R - geom_smooth, 只为一行添加 se

R - geom_smooth, add se for only one line

有没有办法,在geom_smooth()(来自libray ggplot2)中,有一条线的置信区间(参数se = T)但不是另一个 ?

mpg %>% 
   filter(class %in% c('compact', 'midsize')) %>% 
   ggplot(aes(x = displ, y = as.numeric(hwy), color = class)) + 
      geom_smooth(se = T)

在下图中,我想保留蓝线的置信区间,但删除红线之一。由于 se 参数不在 aes() 函数中,我无法在其中传递不同的值。 而且,没有像scale_fill_manual()这样的函数来指定不同的值。

这应该有效:

mpg %>% 
  filter(class %in% c('compact', 'midsize')) %>% 
  ggplot(aes(x = displ, y = as.numeric(hwy), color = class)) + 
  geom_smooth(data = . %>% filter(class == "compact"), method = "loess", se = F) +
  geom_smooth(data = . %>% filter(class == "midsize"), method = "loess", se = T)