Skip to content

Instantly share code, notes, and snippets.

@meren
Last active May 25, 2017 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meren/7e2f00b32500a237afffe30b76d7b991 to your computer and use it in GitHub Desktop.
Save meren/7e2f00b32500a237afffe30b76d7b991 to your computer and use it in GitHub Desktop.
#!/usr/bin/env Rscript
library(reshape)
library(ggplot2)
# set the work directory
setwd('~/Downloads')
# matrix-boxplots.txt should be a three-column, TAB-delimited matrix with a header for 'region', 'haplotype', and 'ratio'.
m <- data.frame(read.table('matrix-boxplots.txt', header = TRUE, sep="\t"))
m$region = factor(m$region, levels=c("MED", "ASW", "PSE", "PSW", "PON", "RED", "ION", "IOS"))
g <- ggplot(m, aes(x=haplotype, y=ratio, fill=haplotype, group=haplotype))
g <- g + geom_boxplot(outlier.alpha = 0.0)
g <- g + geom_jitter(width=0.05, alpha=0.5)
g <- g + facet_grid(. ~ region)
g <- g + theme_bw() + theme(axis.text.x = element_text(angle = 90, hjust = 1))
pdf('boxes.pdf', width=12, height=4)
print(g)
dev.off()
region haplotype ratio
ASW HP_02 0.373024136
ASW HP_02 0.471918075
ASW HP_02 0.271837848
ASW HP_03 0.248834262
ASW HP_03 0.082462621
ASW HP_03 0.1187625
ASW HP_04 0.209962772
ASW HP_04 9.41E-06
ASW HP_04 0.143162351
(...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment