我和这个用户有同样的问题:我想制作一个facet_grid带有离散x轴的图,我想让x轴标签写在每个面下,而不是只在底面的一行面下面.例如:
# Drop some factor levels to make the plot smaller
diamondSub <- subset(diamonds, (cut=="Ideal" | cut=="Premium") &
(color=="E" | color=="I"))
# Note that scales="free_x" has no practical effect here
ggplot(diamondSub, aes(x=clarity, y=price)) +
geom_blank()+
geom_boxplot() +
facet_grid(cut~color, scales="free_x")
Run Code Online (Sandbox Code Playgroud)

但是,我不想使用该帖子的解决方案,而只是使用facet_wrap而不是facet_grid,因为我更喜欢facet_grid用条形文本标记条形文本,列的顶部有一个变量,而另一个变量标注行.
当所有x轴实际上相同时,有没有办法在每个面下获得x轴标签facet_grid?
bap*_*ste 17
您可以在gtable中插入轴的副本,
library(gtable)
g <- ggplotGrob(p)
# locate the panels
panels <- grep("panel", g$layout$name)
top <- unique(g$layout$t[panels])
# intersperse a copy of the bottom axes
all <- gtable:::rbind_gtable(gtable:::rbind_gtable(g[seq.int(min(top)), ],
g[max(top)+1,], "first"),
g[seq(min(top)+1, nrow(g)),], "first")
grid.newpage()
grid.draw(all)
Run Code Online (Sandbox Code Playgroud)
