Skip to content

Commit

Permalink
improved theme and reduced object size of plotPurity() and plotCentra…
Browse files Browse the repository at this point in the history
…lity()
  • Loading branch information
jasenfinch committed Nov 11, 2021
1 parent 0cc8891 commit 6a698e5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ importFrom(dplyr,vars)
importFrom(furrr,future_map)
importFrom(future,plan)
importFrom(ggplot2,aes)
importFrom(ggplot2,aes_string)
importFrom(ggplot2,element_blank)
importFrom(ggplot2,element_line)
importFrom(ggplot2,element_text)
Expand All @@ -71,6 +72,7 @@ importFrom(ggplot2,ggtitle)
importFrom(ggplot2,guide_legend)
importFrom(ggplot2,guides)
importFrom(ggplot2,labs)
importFrom(ggplot2,scale_y_continuous)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_bw)
importFrom(ggplot2,xlab)
Expand Down
49 changes: 27 additions & 22 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

plotTheme <- function(){
theme_bw() +
theme(plot.title = element_text(face = 'bold'),
theme(plot.title = element_text(face = 'bold',hjust = 0.5),
plot.caption = element_text(hjust = 0),
panel.border = element_blank(),
panel.grid = element_blank(),
axis.title = element_text(face = 'bold'),
Expand Down Expand Up @@ -242,14 +243,26 @@ setMethod('plotFingerprint',signature = 'Binalysis',
axis.title = element_text(face = 'bold'))
})

#' @importFrom ggplot2 aes_string geom_histogram scale_y_continuous

plotHist <- function(d,x,histBins,title,xlab,ylab){
ggplot(d,aes_string(x = x)) +
geom_histogram(fill = ggthemes::ptol_pal()(1),colour = 'black',bins = histBins) +
plotTheme() +
facet_wrap(~polarity) +
scale_y_continuous(expand = c(0,0)) +
labs(title = title,
x = xlab,
y = ylab)
}

#' Plot bin purity histogram
#' @rdname plotPurity
#' @description Plot the bin purity distribution for a Binalysis object.
#' @param x S4 object of class Binalysis
#' @param histBins number of bins to use for histogram plotting
#' @seealso \code{\link{accurateData}}, \code{\link{binneRlyse}},
#' \code{\link{plotCentrality}}
#' @importFrom ggplot2 geom_histogram
#' @export

setMethod('plotPurity',signature = 'Binalysis',function(x,histBins = 30){
Expand All @@ -264,15 +277,11 @@ setMethod('plotPurity',signature = 'Binalysis',function(x,histBins = 30){
pur$polarity[pur$polarity == 'p'] <- 'Positive mode'

pur %>%
ggplot(aes(x = purity)) +
geom_histogram(fill = "#88CCEE",colour = 'black',bins = histBins) +
theme_bw() +
facet_wrap(~polarity) +
ggtitle('Bin Purity Distribution') +
theme(plot.title = element_text(face = 'bold'),
axis.title = element_text(face = 'bold')) +
xlab('Purity Measure') +
ylab('Frequency')
plotHist('purity',
histBins = histBins,
title = 'Bin Purity Distribution',
xlab = 'Purity',
ylab = 'Frequency')

})

Expand All @@ -297,15 +306,11 @@ setMethod('plotCentrality',signature = 'Binalysis',function(x,histBins = 30){
pur$polarity[pur$polarity == 'p'] <- 'Positive mode'

pur %>%
ggplot(aes(x = centrality)) +
geom_histogram(fill = "#88CCEE",colour = 'black',bins = histBins) +
theme_bw() +
facet_wrap(~polarity) +
ggtitle('Bin Centrality Distribution') +
theme(plot.title = element_text(face = 'bold'),
axis.title = element_text(face = 'bold')) +
xlab('Centrality measure') +
ylab('Frequency')
plotHist('centrality',
histBins = histBins,
title = 'Bin Centrality Distribution',
xlab = 'Centrality',
ylab = 'Frequency')

})

Expand Down Expand Up @@ -365,8 +370,8 @@ setMethod('plotTIC',signature = 'Binalysis',
Index = rawInfo[,by] %>% unlist()) %>%
gather('Mode','TIC',-Sample,-Colour,-Index)

TICdat$Mode[TICdat$Mode == 'n'] <- 'Negative'
TICdat$Mode[TICdat$Mode == 'p'] <- 'Positive'
TICdat$Mode[TICdat$Mode == 'n'] <- 'Negative mode'
TICdat$Mode[TICdat$Mode == 'p'] <- 'Positive mode'

TICmedian <- TICdat %>%
group_by(Mode) %>%
Expand Down

0 comments on commit 6a698e5

Please sign in to comment.