gpt4 book ai didi

r - 使用 ggplot 绘制曲线拟合

转载 作者:行者123 更新时间:2023-12-05 05:22:20 28 4
gpt4 key购买 nike

如何使用 ggplot 绘制最佳拟合线的曲线?我最好的猜测是我需要以某种方式更改 stat_smooth 参数,但我不知道如何更改。我的目标类似于下图中的黑线。 enter image description here

vv<-structure(list(X = 16:19, school = structure(c(3L, 3L, 3L, 3L), .Label = c("UCB", "UCD", "UIUC"), class = "factor"), year = 2009:2012, mean = c(15.60965, 16.785, 16.77725, 15.91729), sd = c(6.483547,6.852999, 6.327013, 6.74991)), .Names = c("X", "school", "year", "mean", "sd"), row.names = 16:19, class = "data.frame")

ggplot(vv, aes(x = year, y = mean)) +
ggtitle("scores")+
geom_point() +
stat_smooth(method = "lm", col = "red")

最佳答案

您可以尝试更改公式:

ggplot(vv, aes(x = year, y = mean)) + 
ggtitle("scores")+
geom_point() +
stat_smooth(method = "lm", formula = y ~ splines::bs(x, 3), col = "red")

enter image description here

关于r - 使用 ggplot 绘制曲线拟合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40645776/

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