# build data
new.data <- data.frame(Overall.TiTv = c(2.4726628184904, 1.25117630909399,
1.28546471295163, 2.16564305201698, 2.28582642769748, 1.44779168046433),
Novel.TiTv = c(1.50619920965182, 0.977593757441331, 1.17049372310868, 0.948855050841696,
1.29272835599841, 1.02193511483115), Non.synonymous.TiTv = c(1.93106040952599,
1.05242200935915, 1.29515091548419, 1.83382194044418, 1.99342268780203,
1.25316056772065), Novel.Non.synonymous.TiTv = c(1.47481045668845, 0.813714848047626,
1.20468696828205, 1.05049274180824, 1.89479397061867, 0.927376054708901))
names <- c("<=SB quantile 10%", ">=SB quantile 90%", "<=GATK-SB quantile 10%",
">= GATK-SB quantile 90%", "<=Fisher score quantile 10%", ">=Fisher score quantile 90%")
rownames(new.data) <- names
# load packages
suppressPackageStartupMessages(library(ggplot2))
suppressPackageStartupMessages(library(reshape))
suppressPackageStartupMessages(library(reshape2))
new.data.m <- melt(as.matrix(new.data))
new.data.m <- rename(new.data.m, c(X1 = "SB", X2 = "TiTv"))
a <- ggplot(new.data.m, aes(x = SB, y = value, fill = TiTv)) + opts(title = "") +
labs(x = NULL, y = "TiTv", fill = NULL)
b.color <- a + geom_bar(stat = "identity", position = "dodge")
c.color <- b.color + facet_grid(TiTv ~ .) + opts(legend.position = "topright")
immigration_theme <- theme_update(axis.text.x = theme_text(angle = 90,
hjust = 1), panel.grid.major = theme_line(colour = "grey90"), panel.grid.minor = theme_blank(),
panel.background = theme_blank(), axis.ticks = theme_blank(), legend.position = "none")
c.color
The goal is to group down-quantile and up-quantile as a group in the plot, so I re-organize the plot my multiple plots.
my.barplot <- function(b, ylim = c(0, 2.5), text) {
bb <- c(b[1:2], NA, b[3:4], NA, b[5:6])
my.color = c("red", "red", "blue", "blue", "blue", "blue", "green", "green")
barplot(bb, ylim = ylim, col = my.color, panel.first = grid(6, 5, lwd = 2),
space = 0)
mtext(text, side = 4, cex = 0.9)
}
par(mfcol = c(5, 1))
par(mar = c(1, 4, 1, 1))
my.barplot(new.data[, 4], text = colnames(new.data)[4])
my.barplot(new.data[, 3], text = colnames(new.data)[3])
my.barplot(new.data[, 1], text = colnames(new.data)[2])
my.barplot(new.data[, 2], text = colnames(new.data)[1])
# add lables
barplot(rep(NA, times = 8), ylim = c(0, 2.5), space = 0, axes = FALSE)
names <- rownames(new.data)
n <- c(names[1:2], NA, names[3:4], NA, names[5:6])
text(1:8 - 0.5, 2.6, srt = 90, adj = 1, labels = n, xpd = T, cex = 1.4)