如何繪製使用ggplot的最佳擬合線的曲線?我最好的猜測是我需要改變stat_smooth參數,但我不知道如何。我的目標就像下圖中的黑線。 使用ggplot繪製曲線擬合
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")
也許'geom_smooth(method =「lm」,col =「red」,formula = y〜poly(x,2))',但難以做更有趣的四點 – user20650