为ggplot2构面添加颜色条

Feng Tian

我为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) 

在此处输入图片说明

但是我需要在颜色栏和构面之间添加一个间隙。我该怎么办?

拉韦

您可以遵循相同的原则,然后添加另一个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以增加“间距”。

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章