2

我为 ggplot2 刻面的每个条带创建了一个颜色条,如下所示:

ggplot(mpg, aes(displ, cty)) +
  geom_point() +
  facet_grid(. ~ drv) + 
  theme(strip.background = element_blank()) + 
  # Add a line on top (Inf) of the plot (Suggested by PoGibas)
  geom_hline(aes(yintercept = Inf, color = drv), size = 4) 

在此处输入图像描述

但是我需要在颜色条和刻面之间添加一个间隙。我怎么能那样做?

4

1 回答 1

2

您可以遵循相同的原则并添加另一个geom_hline()但 set color="white",如下所示:

ggplot(mpg, aes(displ, cty)) +
  geom_point() +
  facet_grid(. ~ drv) + 
  theme(strip.background = element_blank()) + 
  geom_hline(aes(yintercept = Inf), color = "white", size=4) + # white space
  geom_hline(aes(yintercept = Inf, color = drv), size = 2)

玩起来size增加“间距”。

在此处输入图像描述

于 2019-04-15T13:54:40.110 回答