Created
April 15, 2014 18:14
-
-
Save aaronwolen/10754777 to your computer and use it in GitHub Desktop.
Figures for Alexis' 2014-04-17 seminar.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(plyr) | |
# Load data --------------------------------------------------------------- | |
enrich.file <- "results/alspac/enrichment/enrichment-results-alspac-encode-dnase-h3k4me3.csv" | |
enrich.df <- read.csv(enrich.file, stringsAsFactors = FALSE) | |
# address stem-cell samples missing tissue annotation | |
stem.rows <- which(is.na(enrich.df$tissue) & grepl("stem", enrich.df$description)) | |
enrich.df$tissue[stem.rows] <- "undifferentiated stem cell" | |
# Prep data for plot ------------------------------------------------------ | |
# log(p) threshold used to select enrichment results | |
plot.thresh <- 3.5 | |
plot.df <- subset(enrich.df, count >= 3 & !is.na(tissue)) | |
# summarize enrichment for each tissue | |
enrich.tissue <- ddply(plot.df, .(feature, threshold, tissue), summarize, | |
mean = mean(enrichment), | |
median = median(enrichment)) | |
# order tissue levels by summarized enrichment | |
tissue.levels <- subset(enrich.tissue, | |
threshold == plot.thresh & feature == "DNaseI") | |
tissue.levels <- arrange(tissue.levels, median)$tissue | |
enrich.tissue$tissue <- factor(enrich.tissue$tissue, tissue.levels) | |
plot.df$tissue <- factor(plot.df$tissue, tissue.levels) | |
# Create plot ------------------------------------------------------------- | |
ggplot(subset(plot.df, threshold == plot.thresh)) + | |
aes(tissue, enrichment, color = feature) + | |
stat_summary(fun.y = median, aes(group = feature), geom = "line") + | |
stat_summary(fun.y = median, geom = "point") + | |
geom_point(shape = 3, alpha = 0.6) + | |
scale_color_brewer("Feature", palette = "Set1") + | |
coord_flip() + | |
ylab("Fold enrichment") + | |
theme_bw() + | |
theme(legend.position = "top", axis.title.y = element_blank()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment