From b1772973a4b9c9b1058d580329915735f7521f11 Mon Sep 17 00:00:00 2001 From: Pariksheet Nanda Date: Thu, 26 Jan 2017 18:58:06 -0500 Subject: [PATCH] ENH: Optimize plots for publication Also refactor ggsave() export to multiple formats. --- .gitignore | 1 + plots.R | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index be049ac..b326ec5 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ z_stack/ *.csv *.pdf *.png +*.svg # Log files from CellProfiler Analyst *.log diff --git a/plots.R b/plots.R index 536a1c0..2635491 100644 --- a/plots.R +++ b/plots.R @@ -11,14 +11,21 @@ binwidth <- 0.025 ## Bring RNAi to the front of the level list. wells_all$type <- relevel(wells_all$type, "RNAi") +theme_set(theme_bw()) + +plot_save <- function(prefix, extensions = c("png", "pdf", "svg")) { + invisible(sapply(paste(prefix, extensions, sep = "."), + ggplot2::ggsave, width = 8, height = 5, + units = "in")) +} + ggplot(filter(wells_all, type == "RNAi"), aes(coloc, fill = significant)) + geom_histogram(binwidth = binwidth) + - scale_fill_manual(values = c("grey70", "blue")) + - ggtitle("Histogram of RNAi wells with significant overlap (p-value < 5%)") + + scale_fill_manual(values = c("grey", "blue")) + + ggtitle("Histogram of wells with significant overlap (p-value < 5%)") + xlab("% colocalization") -ggsave("rnai-hist-signif.png") -ggsave("rnai-hist-signif.pdf") +plot_save("rnai-hist-signif") ggplot(wells_all, aes(coloc, color = type)) + geom_freqpoly(binwidth = binwidth) + @@ -26,13 +33,11 @@ ggplot(wells_all, aes(coloc, color = type)) + facet_wrap(~ type) + ggtitle("Histogram of all well types") + xlab("% colocalization") -ggsave("all-hist.png") -ggsave("all-hist.pdf") +plot_save("all-hist") ggplot(wells_all, aes(coloc, color = type)) + geom_density() + facet_wrap(~ type) + ggtitle("Density plot of wells to show distribution") + xlab("% colocalization") -ggsave("all-density.png") -ggsave("all-density.pdf") +plot_save("all-density")