#' Density plot of all samples
#'
#' Density plot of all samples
#'
#' @param counts matrix of counts
#' @param group vector of the condition from which each sample belongs
#' @param out \code{TRUE} to export the figure
#' @param col colors of the bars
#' @param versionName versionName of the project
#' @return A plot with the density estimations
#' @author Marie-Agnes Dillies and Hugo Varet
# created Feb 7th, 2012
# modified April 30th, 2012
# modified Oct 30th, 2012 (png)
# modified Jan 16th, 2013 (pdf)
# modified Sept 20th, 2013 (lwd and legend)
# modified Sept 24th, 2013 (colors)
# modified Oct 25th, 2013 (modification for multiple factors)
# modified Nov 4th, 2013 (remove null counts)
# modified Mar 21st, 2014 (removed outputfile argument)
# modified Aug 5th, 2014 (removed graphDir argument)
# modified August 26th, 2019 (ggplot2)
densityPlot <- function(counts, group, out=TRUE, col=c("lightblue","orange","MediumVioletRed","SpringGreen"), versionName="."){
if (out) pdf(file=paste0("figures/", versionName, "-densplot.pdf"), width=9)
counts <- removeNul(counts)
group <- data.frame(group=apply(group, 1, paste, collapse="-"))
group$group <- factor(group$group, levels=unique(group$group))
d <- stack(data.frame(counts))
d$group <- rep(group$group, each=nrow(counts))
print(ggplot(d, aes(x=.data$values + 1)) +
stat_density(aes(group=.data$ind, color=.data$group), position="identity", geom="line", show.legend=TRUE) +
scale_x_continuous(trans = log10_trans(),
breaks = trans_breaks("log10", function(x) 10^x),
labels = trans_format("log10", math_format(~10^.x))) +
labs(color="") +
scale_colour_manual(values=col) +
xlab("Raw counts") +
ylab("Density") +
ggtitle(paste(versionName, "Density of counts distribution", sep=" - ")))
if (out) dev.off()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.