, ggplot. , ( ). , "". ( , , Y), . , "PAHs". , , unit(1, "null"). (. all, .)
: ggplot2 2.2.1
library(ggplot2)
library(gtable)
library(grid)
all$hydrocarbons <- factor(all$hydrocarbons, levels = all$hydrocarbons)
levels(all$type)[levels(all$type)=="alkanes"] <- "n-alkanes"
pAll <- ggplot(all, aes(x = hydrocarbons, y = average)) +
geom_bar(position = position_dodge(), stat="identity", fill = "gray32") +
geom_errorbar(aes(ymin = average-SD, ymax = average+SD), color = "gray8") +
facet_wrap( ~ type, scales = "free", ncol = 1) +
ylab("Half-life [d]") + xlab("Hydrocarbons") +
theme(axis.text.x = element_text(size = 12, color = "black", angle = 45, hjust = 1),
axis.title.x = element_text(size = 14, face = "bold", vjust = -0.7),
axis.title.y = element_text(size = 14, face = "bold", vjust = 2),
axis.text.y = element_text(size = 12, colour = "black"))
pMid <- ggplot(subset(all, type == "PAHs"), aes(x = hydrocarbons, y = average)) +
geom_bar(position = position_dodge(), stat = "identity", fill = "gray32") +
geom_errorbar(aes(ymin = average - SD, ymax = average + SD), color = "gray8") +
facet_grid(. ~ group, scales = "free", space = "free") +
ylab("Half-life [d]") +
theme(axis.text.x = element_text(size = 12, color = "black", angle = 45, hjust = 1),
axis.title.x = element_text(size = 14, face = "bold", vjust = -0.7),
axis.title.y = element_text(size = 14, face = "bold", vjust = 2),
axis.text.y = element_text(size = 12, colour = "black"))
gAll <- ggplotGrob(pAll)
gMid <- ggplotGrob(pMid)
pos1 <- c(subset(gMid$layout, grepl("panel", gMid$layout$name), select = t:r))
panels <- gMid[(unique(pos1$t) - 1) : (unique(pos1$t) + 1), min(pos1$l) : max(pos1$l)]
axisL <- gMid[unique(pos1$t), min(pos1$l) - 1]
pos2 <- c(subset(gAll$layout, grepl("panel", gAll$layout$name), select = t:r))
pos2 <- lapply(pos2, "[", 2)
drop <- gAll$layout$name %in% c("panel-1-2", "strip-t-1-2", "axis-b-1-2", "axis-l-2-1")
gAll$grobs[drop] <- NULL
gAll$layout <- gAll$layout[!drop,]
gAll <- gtable_add_grob(gAll, panels, t = pos2$t-1, l = pos2$l, b = pos2$t+1, name = "panels")
gAll <- gtable_add_grob(gAll, axisL, t = pos2$t, l = pos2$l-1, name = "strips")
gAll <- gtable_add_rows(gAll, gAll$heights[pos2$t-1], pos2$t-2)
gAll <- gtable_add_grob(gAll,
list(rectGrob(gp = gpar(col = NA, fill = "gray85")),
textGrob("PAHs", gp = gpar(fontsize = 9.6))),
t = pos2$t-1, l = pos2$l, name = c("background", "text"))
gAll <- gtable_add_rows(gAll, unit(1/10, "line"), pos2$t-1)
gAll$heights[pos2$t + 3] <- gMid$heights[unique(pos1$t) + 1]
grid.newpage()
grid.draw(gAll)

all = structure(list(hydrocarbons = structure(c(21L, 28L, 29L, 30L,
31L, 12L, 13L, 14L, 15L, 60L, 62L, 63L, 64L, 65L, 6L, 7L, 8L,
9L, 10L, 16L, 67L, 17L, 18L, 19L, 2L, 3L, 4L, 5L, 32L, 33L, 34L,
35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L,
48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 23L, 24L,
25L, 26L, 1L, 68L, 11L, 20L, 61L, 59L, 66L, 22L, 27L), .Label = c("Benzene",
"C", "C1", "C2", "C3", "D", "D1", "D2", "D3", "D4", "Ethylbenzene",
"F", "F1", "F2", "F3", "FL", "FL1", "FL2", "FL3", "m-Xylene",
"N", "n-Butylbenzene", "n-C5 (Pentane)", "n-C6 (Hexane)", "n-C7 (Heptane)",
"n-C9 (Nonane)", "n-Pentylbenzene", "N1", "N2", "N3", "N4", "nC-10",
"nC-11", "nC-12", "nC-13", "nC-14", "nC-15", "nC-16", "nC-17",
"nC-18", "nC-19", "nC-20", "nC-21", "nC-22", "nC-23", "nC-24",
"nC-25", "nC-26", "nC-27", "nC-28", "nC-29", "nC-30", "nC-31",
"nC-32", "nC-33", "nC-34", "nC-35", "nC-36", "o-Xylene", "P",
"p-Xylene", "P1", "P2", "P3", "P4", "Propylbenzene", "PY", "Toluene"
), class = "factor"), average = c(6.21, 4.71, 7.6, 16.18, 18.8,
16.87, 16.64, 18.67, 22.79, 7.97, 26.66, 21.72, 18.99, 66.28,
8.33, 8.63, 9.57, 20.69, 32.5, 10.37, 10.53, 24.42, 42.52, 51.99,
74.28, 46.56, 82.85, 114.42, 2.24, 2.24, 4.85, 5.54, 6.81, 5.56,
5.95, 5.82, 5.7, 6.41, 7.36, 6.24, 6.07, 6.35, 7.32, 6.6, 5.97,
6.51, 7.57, 8.37, 9.05, 10.27, 11.5, 14.31, 16.96, 20.52, 21.88,
10.63, 1.74, 9.62, 2.34, 23.51, 18.48, 7.55, 12.53, 15.21, 21.96,
12.8, 9.33, 6.77), SD = c(4.632774217, 2.43670665, 3.266286228,
11.00643289, 4.59631824, 7.022165062, 5.721267073, 8.467132345,
0.988021105, 0.211647391, 16.64819987, 4.416811664, 4.635405486,
7.706085861, 0.89862145, NA, NA, 3.453922632, 8.191613185, NA,
NA, 8.886055918, 9.466539232, 15.77786373, 9.560499532, 15.86163409,
4.854714782, 41.70884318, NA, NA, 1.414267191, 0.089306765, 0.241222891,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 2.215395794, 1.839829721,
1.972060107, 1.797509743, 3.004883333, 3.503601406, 4.242811665,
5.087821955, 8.085948386, 10.10105484, 14.1878649, 13.40071226,
1.715015757, 0.859880844, 4.316473516, 0.044641, 0.631882255,
2.369137637, 7.171631537, 7.250491275, 1.800247445, 2.184177383,
15.31136895, 5.486543125, 0.420247353), type = structure(c(2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L), .Label = c("alkanes", "PAHs", "VOCs"), class = "factor"),
group = structure(c(6L, 6L, 6L, 6L, 6L, 5L, 5L, 5L, 5L, 7L,
7L, 7L, 7L, 7L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 2L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("",
"Chrysenes", "Dibenzothiophenes", "Fluoranthenes", "Fluorenes",
"Naphtalenes", "Phenanthrenes"), class = "factor")), .Names = c("hydrocarbons",
"average", "SD", "type", "group"), class = "data.frame", row.names = c(NA,
-68L))