有一个问题,在ggplot中添加图例到不同的光滑.
library(splines)
library(ggplot2)
temp <- data.frame(x = rnorm(200, 20, 15), y = rnorm(200, 30, 8))
ggplot(data = temp, aes(x, y)) + geom_point() +
geom_smooth(method = 'lm', formula = y ~ bs(x, df=5, intercept = T), col='blue') +
geom_smooth(method = 'lm', formula = y ~ ns(x, df=2, intercept = T), col='red')
Run Code Online (Sandbox Code Playgroud)
我有两个样条:红色和蓝色.我如何为他们添加传奇?