Last active
January 21, 2016 20:51
-
-
Save mfcovington/a90af0956b7dd2d5ea17 to your computer and use it in GitHub Desktop.
time course plotting function
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
timecourse <- readRDS('timecourse.rds') | |
plot.timecourse <- function(gene.list, east.color='orange', west.color='forestgreen', double.plot=FALSE, side.by.side=FALSE) { | |
library(ggplot2) | |
timecourse.subset <- timecourse[timecourse$gene %in% gene.list, ] | |
timecourse.subset$gene <- as.character(timecourse.subset$gene) | |
if (double.plot) { | |
timecourse.subset.copy <- timecourse.subset | |
timecourse.subset.copy$hour <- timecourse.subset.copy$hour + 48 | |
timecourse.subset <- rbind(timecourse.subset, timecourse.subset.copy) | |
x.breaks <- seq(0, 96, 12) | |
} else { | |
x.breaks <- seq(0, 48, 12) | |
} | |
p <- ggplot(timecourse.subset, aes(x=hour, y=mean, color=side)) + | |
geom_line(size=1) + | |
geom_errorbar(aes(ymin=mean-stderr, ymax=mean+stderr), alpha=0.35) + | |
labs(x = 'Time (hours)', y = 'Mean Normalized Counts') + | |
scale_x_continuous(breaks=x.breaks) + | |
scale_color_manual(name = 'Orientation',values = c(east.color, west.color)) | |
if (side.by.side) { | |
p <- p + facet_grid(gene ~ side, scales='free_y') | |
} else { | |
p <- p + facet_wrap(~ gene, ncol=1, scales='free_y') | |
} | |
print(p) | |
} | |
# Plot single gene | |
plot.timecourse('Ha412v1r1_07g008930') | |
# Plot gene list | |
gene.list <- c('Ha412v1r1_07g008930', 'Ha412v1r1_01g020690', 'Ha412v1r1_16g004440', 'Ha412v1r1_14g049950') | |
plot.timecourse(gene.list) | |
# Double plot | |
plot.timecourse(gene.list, d=T) | |
# Plot East/West side-by-side | |
plot.timecourse(gene.list, s=T) | |
# Save most recent plot (set width/height using w/h) | |
ggsave('timecourse-demo-plot.png', w=4, h=6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment