gpt4 book ai didi

r - 使用ggplot2为每组添加回归线

转载 作者:行者123 更新时间:2023-12-04 00:44:56 26 4
gpt4 key购买 nike

我做下图:

> ddd
UV.NF TRIS volvol
2 145.1923 31 500 µl / 625 µl
3 116.3462 50 500 µl / 625 µl
4 127.1635 60 500 µl / 625 µl
5 125.9615 69 500 µl / 625 µl
6 162.0192 30 1 ml / 625 µl
7 166.8269 50 1 ml / 625 µl
8 176.4423 60 1 ml / 625 µl
9 171.6346 70 1 ml / 625 µl
19 292.3077 31 500 µl / 2500 µl
20 321.1538 50 500 µl / 2500 µl
21 225.0000 60 500 µl / 2500 µl
22 263.4615 69 500 µl / 2500 µl
23 301.9231 30 1 ml / 2500 µl
24 350.0000 50 1 ml / 2500 µl
25 282.6923 60 1 ml / 2500 µl
26 282.6923 70 1 ml / 2500 µl
35 133.6207 31 500 µl / 625 µl

ggplot() +
geom_point(aes(y = log(UV.NF), x = TRIS, colour=ddd[,"volvol"], shape=ddd[,"volvol"]),
data=ddd) +
labs(colour = "volvol", shape="volvol") + xlab("TRIS (mM)") +
guides(colour = guide_legend(title="Vol. lyo. / Vol. reconst."),
shape=guide_legend(title="Vol. lyo. / Vol. reconst.")) +
scale_shape_manual(values = c(19,19,3,3)) + scale_colour_manual(values = c(2,4,2,4))

graph

我想添加回归线 lm(y~x)对于出现在图例中的四个组中的每一个。我用 geom_smooth() 做了很多尝试但没有成功。

最佳答案

我不太确定这是否是您想要的,但是您是否尝试过以下操作?

ggplot(ddd,aes(y = log(UV.NF), x = TRIS, colour = volvol, shape = volvol)) +
geom_point() + geom_smooth(method = "lm", fill = NA)

这为我提供了以下带有您数据的图: enter image description here

还有一些关于 geom_smooth 的文档这几乎可以满足您的需求,尽管以更复杂(但更灵活)的方式。

关于r - 使用ggplot2为每组添加回归线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12281335/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com