[英]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.