我想使用R中的ggplot生成分解与时间的关系图,如下所示:
ggplot(data=deco, aes(x = week, y = mass, group=interaction(treatment,habitat),
colour=habitat, linetype=treatment)) +
geom_point() +
theme_classic() +
geom_smooth(method='lm',formula=y~x)
因为最初的垃圾重量是5克,所以我希望所有的线在0周内从5克开始。但是,我意识到所有的线都有不同的起点。我试图找到任何解决方案来迅速解决所有问题,但所有方法对我而言都不奏效。如果你们中的任何一个都能解决这个问题,那就太好了。
答案 0 :(得分:2)
正如Gregor所指出的,这并不重要,因为组的大小未知且geom_smooth
受到限制。有两个选项,可以在ggplot
之外适合您的模型。或抑制截距,移动y,然后重新标记轴。
ggplot(mtcars, aes(wt, drat, col = factor(am))) +
geom_point() +
geom_smooth(method = 'lm') +
xlim(0, 6)
Intercept <- 5
ggplot(mtcars, aes(wt, drat - Intercept, col = factor(am))) +
geom_point() +
geom_smooth(method = 'lm', formula = y ~ x + 0) +
scale_y_continuous(labels = function(x) x + Intercept) +
xlim(0, 6)