如何将x标签移动到R中ggplot中的facet标签上

时间:2017-12-06 15:43:39

标签: r ggplot2 graph bar-chart facet

我想将小平面标签(3,4,5)移动到x值(4,6,8)下面。 我目前的代码:

library(ggplot2)
ggplot(mtcars) + aes(factor(cyl), wt) + 
geom_bar(stat = "summary", fun.y = "mean") + 
facet_grid(~gear, switch = "x")

目前,它看起来像这样:

currently

我正在寻找看起来像这样的东西:

goal

1 个答案:

答案 0 :(得分:3)

library(ggplot2)
ggplot(mtcars) + aes(factor(cyl), wt) + 
geom_bar(stat = "summary", fun.y = "mean") + 
facet_grid(~gear, switch = "x") +
theme(strip.placement = "outside")

enter image description here