【发布时间】:2016-04-14 18:14:52
【问题描述】:
使用包 ggplot2 和 iris,我想用拟合的回归线绘制散点图。
library(ggplot2)
ggplot(data=iris, aes(x = Petal.Width, y = Petal.Length,color=Species)) +
geom_point(shape=1) +
stat_smooth(method = "lm",formula= 'Petal.Length ~ Petal.Width+I(Petal.Width^2)+SaleType+Petal.Width*Species', data=iris,
aes(x = Petal.Width, y = Petal.Length,color=Species))
**Warning message:
Computation failed in `stat_smooth()`:
variable lengths differ (found for '(weights)')**
我正在考虑收到此警告的原因,即我有两个自变量,但现在 R 无法读取 stat_smooth 中按颜色划分的物种。如何绘制两条与plot(Petal.Width,fitted(fit)) 相同的线。另外,如果我有另一个回归模型由同一组数据拟合,但是log(y),fit<-lm(log(Petal.Length)~Petal.Width+Species+Petal.Width*Species,data=iris).我可以把两个回归模型的绘制放到同一个图中吗?
【问题讨论】:
标签: r plot ggplot2 regression scatter-plot