Skip to content

Instantly share code, notes, and snippets.

@skurscheid
Last active November 7, 2016 02:58
Show Gist options
  • Save skurscheid/dd0f4e50e1c6c0cd2db4a823e7ca0a9b to your computer and use it in GitHub Desktop.
Save skurscheid/dd0f4e50e1c6c0cd2db4a823e7ca0a9b to your computer and use it in GitHub Desktop.
boxplot_example.R
# preparing example data for clusters
MCF10_promoter_clusters <- as.data.frame(matrix(nrow = nrow(tab4), ncol = ncol(tab4)))
colnames(MCF10_promoter_clusters) <- colnames(MCF10_expression_data)
rownames(MCF10_promoter_clusters) <- rownames(MCF10_expression_data)
for (x in colnames(MCF10_promoter_clusters)){
MCF10_promoter_clusters[,x] <- paste("cluster", sample(c(1:7), size = nrow(MCF10_promoter_clusters), replace = T), sep = "")
}
# example of plotting expession data by cluster group
MCF10_expression_data <- read.csv("MCF10_expression_data.csv", row.names = 1)
# best to log2 transform the expression data in order to have quasi-normal distribution of cpm data
# also add offset of + 1 in order to avoid -/+Inf
MCF10_expression_data <- log2(MCF10_expression_data + 1)
# to make sure that the rows of the two tables are organized in the same order we create a vector with rownames used for indexing
i1 <- intersect(rownames(MCF10_expression_data), rownames(MCF10_promoter_clusters))
# actual plotting, all five plots on a single page.
par(mfrow = c(3,2))
sapply(colnames(MCF10_expression_data), function(x){
boxplot(MCF10_expression_data[i1, x] ~ MCF10_promoter_clusters[i1, x], main = paste(x))
})
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment