#' Bar plot of total number of counts per sample
#'
#' Bar plot of total number of counts per sample
#'
#' @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 barplot
#' @author Marie-Agnes Dillies and Hugo Varet
# created Feb 7th, 2012
# modified April 30th, 2012 (group instead of target$group)
# modified Sept 27th, 2012 (size of cex names)
# modified Oct 30th, 2012 (png)
# modified Janu 16th, 2013 (pdf)
# modified Sept 20th, 2013 (legend)
# modified Sept 24th, 2013 (colors)
# modified Oct 25th, 2013 (modification for multiple factors)
# modified Mar 21st, 2014 (removed outputfile argument)
# modified Aug 5th, 2014 (removed graphDir argument)
# modified June 23rd, 2016 (y-axis in millions)
# modified August 26th, 2019 (ggplot2)
barplotTC <- function(counts, group, out=TRUE, col=c("lightblue","orange","MediumVioletRed","SpringGreen"), versionName="."){
if (out) pdf(file=paste0("figures/", versionName, "-barplotTC.pdf"), width=min(14,7+3*ncol(counts)/10), height=7)
tc <- colSums(counts)/1e6
group <- data.frame(group=apply(group, 1, paste, collapse="-"))
group$group <- factor(group$group, levels=unique(group$group))
d <- data.frame(tc=tc, sample=factor(names(tc), levels=names(tc)), group)
print(ggplot(d, aes(x=.data$sample, y=.data$tc, fill=.data$group)) +
geom_bar(stat="identity", show.legend=TRUE) +
labs(fill="") +
scale_fill_manual(values=col) +
xlab("Samples") +
ylab("Total read count (millions)") +
scale_y_continuous(expand=expansion(mult=c(0.01, 0.05))) +
ggtitle(paste(versionName, "Total read count per sample", sep=" - ")) +
theme(axis.text.x=element_text(angle=90, hjust=1, vjust=0.5)))
if (out) dev.off()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.