ggplot。按组添加回归线

时间:2016-04-21 12:31:17

标签: r ggplot2 regression

如果我画这个

dodge <- position_dodge(.35)   
ggplot(mediat, aes(x=t, y=Value, colour=factor(act),group=id )) + 
geom_point(position=dodge) + geom_errorbar(aes(ymin=Value-sdt, ymax=Value+sdt), 
width=0, position=dodge) +  theme_bw() + geom_smooth(method="lm",se=FALSE,
fullrange=TRUE)

我明白了 enter image description here

如您所见,未绘制回归线。 + stat_smooth(method = lm,fullrange = TRUE,se = FALSE)结果相同。

我发现删除“group = id”我可以获得回归线但是

然后

ggplot(mediat, aes(x=t, y=Value, colour=factor(act) ))+ geom_point(position=dodge) +
geom_errorbar(aes(ymin=Value-sdt, ymax=Value+sdt), width=0, position=dodge) +
theme_bw() + geom_smooth(method="lm",se=FALSE, fullrange=TRUE)

enter image description here

正如你所看到的,现在它绘制了线条,但是我按组散失了闪避功能。

我怎样才能同时获得这两件事?我的意思是,在第一个整洁的情节上用“id”回归线?

任何其他基础图,格子或任何其他常见包装的解决方案也是受欢迎的。

此致

0 个答案:

没有答案
相关问题