02234511王叶新
2025-12-03
# 基础散点图
ggplot(data = iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) +
geom_point() # 颜色随Species变化#添加线性趋势线
# 散点图 + 线性趋势线(不带误差带)
ggplot(data = iris, aes(x = Sepal.Length, y = Petal.Length)) +
geom_point() + # 散点
geom_smooth(method = "lm", se = FALSE) + # 线性回归趋势线(se=FALSE关闭误差带)
ggtitle("鸢尾花萼片长度与花瓣长度的线性趋势")## `geom_smooth()` using formula = 'y ~ x'