library(tidyverse)
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy))+
geom_smooth(mapping = aes(x = displ, y = hwy, color = drv), stat = "smooth",
position = "identity",formula = y ~ x,method=loess
,span =175)
给点加颜色colour=factor(cyl)
library(tidyverse)
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy,colour=factor(cyl)))+
geom_smooth(mapping = aes(x = displ, y = hwy, color = drv), stat = "smooth",
position = "identity",formula = y ~ x,method=loess
,span =175)
修改颜色类型为class
library(tidyverse)
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy,colour=factor(cyl)))+
geom_smooth(mapping = aes(x = displ, y = hwy, color = class), stat = "smooth",
position = "identity",formula = y ~ x,method=loess
,span =175)
library(tidyverse)
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy,colour=factor(cyl)))+
geom_smooth(mapping = aes(x = displ, y = hwy, color = factor(cyl)), stat = "smooth",
position = "identity",formula = y ~ x,method=loess
,span =175)
点和线的颜色都为factor(cyl)效果
修改点和线的颜色都为class
library(tidyverse)
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy,colour=class))+
geom_smooth(mapping = aes(x = displ, y = hwy, color = class), stat = "smooth",
position = "identity",formula = y ~ x,method=loess
,span =175)
参考文献:R数据科学—[新西兰]哈德利 威克姆,[美]加勒特 格罗勒芒德—陈光欣[译] 北京:人民邮电出版社
开发环境:RStudio