> library(tidyverse)
> head(mpg)
> ggplot(mpg, aes(displ, hwy))+geom_point()
# geom_smooth()默认的method="loess"
> ggplot(mpg, aes(displ, hwy)) + geom_point() +
geom_smooth(aes(color="loess")) + geom_smooth(aes(color="lm"))
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
# 自定义geom_smooth()的method
> ggplot(mpg, aes(displ, hwy)) + geom_point() +
geom_smooth(aes(color="loess"), method="loess") +
geom_smooth(aes(color="lm"), method="lm")
# aes()只是指定映射对象,并不是定义颜色。要定义颜色,需要借助scale_color_manual()
> ggplot(mpg, aes(displ, hwy)) + geom_point() +
geom_smooth(aes(color="loess"), method="loess") +
geom_smooth(aes(color="lm")
ggplot2中的颜色定义与映射
最新推荐文章于 2024-03-08 16:52:14 发布