[英]Split facet_wrap panel when x is a factor in ggplot2
I want to add a vertical line to split facet_wrap
panel in ggplot2. 我想添加一条垂直线以分割
facet_wrap
面板。
ggplot(mpg, aes(drv, hwy))+
geom_boxplot(aes(colour = drv))+
facet_wrap(~year)+
theme_bw()+
theme(panel.grid=element_blank())
my question is how could we add vertical lines when x is a factor ? 我的问题是,当x是一个因子时,如何添加垂直线?
From ?scale_x_discrete
: 从
?scale_x_discrete
:
You can use continuous positions even with a discrete position scale - this allows you (eg) to place labels between bars in a bar chart.
您甚至可以使用连续的头寸,甚至使用离散的头寸比例尺-这(例如)允许您在条形图中的条形图之间放置标签。
You can add vertical lines with geom_vline()
& set the position at 1.5, 2.5, etc: 您可以使用
geom_vline()
添加垂直线, geom_vline()
位置设置为geom_vline()
等:
ggplot(mpg, aes(drv, hwy)) +
geom_boxplot(aes(colour = drv))+
geom_vline(xintercept = c(1.5, 2.5), linetype = "dashed") +
facet_wrap(~ year) +
theme_bw() +
theme(panel.grid=element_blank())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.