Skip to content

Commit

Permalink
reduced size and improved theme of plotBin()
Browse files Browse the repository at this point in the history
  • Loading branch information
jasenfinch committed Nov 11, 2021
1 parent 573bc31 commit 6b89ea3
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,37 @@ plotTheme <- function(){
strip.text = element_text(face = 'bold'))
}

binPlot <- function(dat,bin,m,dp,type){
pl <- ggplot(dat,aes(x = mz)) +
geom_density() +
xlim(m - 5 * 10^-(dp + 1),
m + 5 * 10^-(dp + 1)) +
plotTheme() +
scale_y_continuous(expand = c(0,0)) +
labs(title = bin,
x = 'm/z',
y = 'Density')

if (type == 'cls') {
class <- cls(x)

if (length(class) == 0) {
stop('No "cls" parameter found for this Binalysis class object.',
call. = FALSE)
}

pl <- pl +
facet_wrap(as.formula(paste("~", class)))
}

if (type == 'sample') {
pl <- pl +
facet_wrap(~fileName)
}

return(pl)
}

#' Plot a spectral bin feature
#' @rdname plotBin
#' @description Kernal density plot of a specified spectral bin feature.
Expand Down Expand Up @@ -51,37 +82,7 @@ setMethod('plotBin',signature = 'Binalysis',
dp <- str_extract(bin,'(?<=[.])[\\w+.-]+') %>%
nchar()

pl <- ggplot(dat,aes(x = mz)) +
geom_density() +
theme_bw() +
xlim(m - 5 * 10^-(dp + 1),
m + 5 * 10^-(dp + 1)) +
theme(plot.title = element_text(face = 'bold'),
axis.title.y = element_text(face = 'bold'),
axis.title.x = element_text(face = 'bold.italic'),
axis.text.x = element_text(angle = 90,hjust = 1)) +
labs(title = bin,
x = 'm/z',
y = 'Density')

if (type == 'cls') {
class <- cls(x)

if (length(class) == 0) {
stop('No "cls" parameter found for this Binalysis class object.',
call. = FALSE)
}

pl <- pl +
facet_wrap(as.formula(paste("~", class)))
}

if (type == 'sample') {
pl <- pl +
facet_wrap(~fileName)
}

return(pl)
binPlot(dat,bin,m,dp,type)
}
)

Expand Down

0 comments on commit 6b89ea3

Please sign in to comment.