简体   繁体   English

R-geom_smooth,仅将SE添加一行

[英]R - geom_smooth, add se for only one line

Is there a way, in geom_smooth() (from libray ggplot2 ), to have the confidence interval (parameters se = T ) for a line but not for the other ? 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)

In the graph below, I would like to keep the confidence interval for the blue line, but to remove the one of the red line. 在下图中,我想保留蓝线的置信区间,但要删除红线之一。 As se parameter is not in the aes() function, I don't manage to pass different values in it. 由于se参数不在aes()函数中,因此我无法在其中传递不同的值。 Moreover, there is no function like scale_fill_manual() , to specify different values. 而且,没有像scale_fill_manual()这样的函数来指定不同的值。

在此处输入图片说明

This should work: 这应该工作:

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM