这些问题跟进了以前的帖子:
我刚开始学习gtable
。我合并了上面两个帖子中的代码,以获得构面网格的每个面板上的x轴。
library(ggplot2)
diamondSub <-subset(diamonds, (cut=="Ideal" | cut=="Premium" | cut == "Very Good") &
(color=="E" | color=="I"))
p <- ggplot(diamondSub, aes(x=clarity, y=price)) +
geom_blank() +
geom_boxplot() +
facet_grid(cut~color, scales="free_x") +
theme(plot.background=element_blank(),
panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
axis.line.x = element_line(color = 'black',size=1),
axis.line.y = element_line(color = 'black',size=1))
p
library(gtable)
g <- ggplotGrob(p)
# locate the panels
panels <- grep("panel", g$layout$name)
top <- unique(g$layout$t[panels])
# Construct each row separately
top.row <- rbind_gtable(g[seq.int(min(top)), ],
g[max(top)+1,], "first")
middle.row <- rbind_gtable(g[c(top[2]-1,top[2]), ],
g[max(top)+1,], "first")
bottom.row <- g[(max(top)-1):nrow(g), ]
all <- rbind_gtable(rbind_gtable(top.row, middle.row, "first"), bottom.row, "first")
# Draw it
grid.newpage()
grid.draw(all)
我有两个问题: