要在R的ggplot2中绘制不添加负值的geom_smooth曲线,可以使用以下方法:
df <- data.frame(x = c(1, 2, 3, 4, 5),
y = c(2, 3, 4, 3, 5))
library(ggplot2)
p <- ggplot(data = df, aes(x = x, y = y))
p <- p + geom_point()
p <- p + geom_smooth(method = "lm")
p <- p + ylim(0, Inf)
print(p)
这样就可以绘制出不添加负值的geom_smooth曲线图。