facet_wrap()中的行而不是框

问题描述 投票:0回答:2

我试图用facet清理ggplot,这样我就可以显示一条简单的线条(相当于底线)而不是facet标签周围的典型框。

以下代码几乎让我一路走来,但与所需的输出不同。

ggplot(mtcars, aes(mpg, hp)) +
 geom_point() +
 facet_wrap(~cyl) +
 theme_classic() +
 theme(strip.background = element_blank())

期望的输出(手动编辑)。理想情况下,线的长度将略短于panel.background(因此它不会接触y轴)

enter image description here

r ggplot2 facet-wrap
2个回答
2
投票

也许使用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")

enter image description here


1
投票

不完全是你想要的,但关闭......

ggplot(mtcars, aes(mpg, hp)) +
theme_bw() +
theme(
  panel.grid.major = element_blank(),
  panel.grid.minor = element_blank(),
  strip.background = element_blank(),
  panel.border = element_rect(colour = "black")
)+
geom_point() +
facet_wrap(~cyl) 

© www.soinside.com 2019 - 2024. All rights reserved.