从图例中的geom_smooth SE 中删除灰色框

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

我有 geom_point() 和 geom_smooth() 的组合,并通过有 3 组的 'cj' var 手动控制颜色。

下面的代码通常运行良好:

ggplot(d, aes(x = month, y = prop_er, color = cj, fill = cj)) +
  geom_point() +
  geom_smooth(se = TRUE, method = "lm",
              aes(fill = cj),
              alpha = 0.3) +
  facet_grid(cols = vars(age),
             rows = vars(pers)) +
  scale_color_manual(values = colors,
                     labels = group) +
  scale_fill_manual(values = colors,
                    guide = "none") +
  theme_minimal() +
  theme(legend.position = "bottom")

当我这样做时,对于我的图例,我得到了您在下面的屏幕截图中看到的内容,每个点/线组合周围都有一个灰色框。我认为这来自geom_smooth的SE。如何删除这个灰色框,以便图例中仅显示彩色线和点?

enter image description here

r ggplot2
1个回答
0
投票

你看到的就是平滑走廊的传说。您可以像这样在 geom_smooth 中将其关闭:

library(tidyverse)
ggplot(mtcars, aes(x = cyl, y = disp, color = factor(gear), fill = carb)) +
  geom_point() +
  geom_smooth(show.legend = FALSE) + # suppress geom_smooth legend
  theme_minimal() +
  theme(legend.position = "bottom")

创建于 2024-09-28,使用 reprex v2.1.0

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