同样的 x 变量和 y 变量,描述的同样的数据,可以用散点图和平滑曲线图,从中都可以看出数据的趋势,ggplot中可以很容易的将这两个图结合在一张图上。
# 散点图
ggplot(data = iris) +
geom_point(mapping = aes(x = Sepal.Length, y = Sepal.Width))
image.png
# 拟合曲线
ggplot(data = iris) +
geom_smooth(mapping = aes(x = Sepal.Length, y = Sepal.Width))
image.png
两者结合起来
ggplot(data = iris) +
geom_point(mapping = aes(x = Sepal.Length, y = Sepal.Width)) +
geom_smooth(mapping = aes(x = Sepal.Length, y = Sepal.Width))