我试图用facet清理ggplot
,这样我就可以显示一条简单的线条(相当于底线)而不是facet标签周围的典型框。
以下代码几乎让我一路走来,但与所需的输出不同。
ggplot(mtcars, aes(mpg, hp)) +
geom_point() +
facet_wrap(~cyl) +
theme_classic() +
theme(strip.background = element_blank())
期望的输出(手动编辑)。理想情况下,线的长度将略短于panel.background
(因此它不会接触y
轴)
也许使用annotate + segment
ggplot(mtcars, aes(mpg, hp)) +
geom_point() +
facet_grid(~cyl,) +
theme_classic() +
theme(strip.background = element_rect(color = "white"),
strip.placement = "inside",
strip.text = element_text(vjust = -1)) +
annotate("segment",x = 10,xend = 34,y = 375,yend = 375, size = 0.5,) +
coord_cartesian(ylim = c(0, 360), clip="off")