首页 > 解决方案 > ggplot:有没有更简洁的方式使用主题背景?

问题描述

我想包括一些充满背景的圆圈,以便它们覆盖下面的任何东西,但仍然融入背景。

在下面的示例中,我以编程方式使用hrbrthemes::theme_ft_rc()$plot.background$fill. 但是,我想知道是否有更清洁、更短的方法。黑色背景的圆圈只是为了显示我不想要的东西:)

library(ggplot)
x = c(0,1)
y = c(0,3)
xend = c(4,2)
yend = c(4,2)
data = data.frame(x, xend, y, yend)
p2 <- ggplot(data) +
  geom_link(aes(x = x, xend = xend, y = y,  yend = yend)) +
  # Starting circle
  geom_point(aes(x = x, y = y), size=5, shape = 21, alpha=1,
             fill = "black"
  ) +
  # Ending circle
  geom_point(aes(x = xend, y = yend), size=5, shape = 21, alpha=1,
             fill = hrbrthemes::theme_ft_rc()$plot.background$fill
  ) +
  hrbrthemes::theme_ft_rc()
p2

在此处输入图像描述

标签: rggplot2

解决方案


推荐阅读