简体   繁体   English

如何在同一图中以多种颜色在R中回归线周围产生标准误差?

[英]How do I have the standard errors around regression lines in R with multiple colours in the same plot?

I'm using ggplot to plot several pieces of data on the same graph. 我正在使用ggplot在同一张图上绘制几条数据。 Below, each line is a time point and has different color, which I've manually selected using the scale_color_manual function. 在下面,每行是一个时间点,并且具有不同的颜色,这是我使用scale_color_manual函数手动选择的。 I'd like to include standard error but have the standard error colour match the color of the regression line. 我想包含standard error但标准误差颜色与回归线的颜色匹配。

Below I've edited the color of standard error to red by changing the 'fill' in the geom_smooth function. 下面,我通过更改geom_smooth函数中的“填充”将标准错误的颜色编辑为红色。 But don't know how to change it so each line and error match. 但是不知道如何更改它,因此每一行和错误都匹配。

在此处输入图片说明

ggplot(data, aes(x=log10(x), y=y, color=factor(Time)))+ 
  geom_smooth(method="loess", span=2, fill="red") +
  facet_wrap(~Condition)+
  scale_color_manual(name="Time",values=c("red","blue","green"))

Set the fill aesthetic. 设置fill美学。 This can be done in the ggplot() call or in the geom_smooth call. 这可以在ggplot()调用或geom_smooth调用中完成。

data = data.frame(x = runif(60), y = runif(60), 
                  Time = rep(1:3, 20), 
                  Condition = factor(rep(1:2, 30)))

ggplot(data, aes(x=log10(x), y=y, colour=factor(Time), fill =   factor(Time)))+ 
  geom_smooth( method="loess", span=2) +
  facet_wrap(~Condition)+
  scale_color_manual(name="Time", values=c("red","blue","green")) +
  scale_fill_manual(name="Time", values=c("red","blue","green"))

在此处输入图片说明

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

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