library(ggplot2)
library(ggpubr)
一、绘制原始图
ggplot(mpg, aes(x = displ, y = hwy, color = drv, shape = drv)) +
geom_point() +
geom_smooth(se = F, method = 'loess') +
theme_bw()
二、自定义颜色
scale_color_manual(values = c("#0073C2FF", "#EFC000FF", "#868686FF")) #自定义颜色
ggplot(mpg, aes(x = displ, y = hwy, color = drv, shape = drv, linetype = drv)) +
geom_smooth(se = F, method = 'loess') +
geom_point() +
scale_linetype_manual(values = c('twodash', 'longdash', 'dashed')) +
theme_bw() +
scale_color_manual(values = c("#0073C2FF", "#EFC000FF", "#868686FF")) #自定义颜色
三、自定义点的形状
show_point_shapes() +
theme_classic()#显示点的形状(ggpubr包内的函数)
ggplot(mpg, aes(x = displ, y = hwy, color = drv, shape = drv)) +
geom_point() +
geom_smooth(se = F, method = 'loess') +
theme_bw() +
scale_color_manual(values = c("#0073C2FF", "#EFC000FF", "#868686FF")) +
scale_shape_manual(values = c(15, 19, 17)) #自定义点的形状,分别为15, 19, 17。
四、自定义线条的类型
show_line_types() #显示线条类型(ggpubr包内的函数)
ggplot(mpg, aes(x = displ, y = hwy, color = drv, shape = drv, linetype = drv)) +
geom_point() +
geom_smooth(se = F, method = 'loess') +
theme_bw() +
scale_color_manual(values = c("#0073C2FF", "#EFC000FF", "#868686FF")) +
scale_shape_manual(values = c(15, 19, 17)) +
scale_linetype_manual(values = c('twodash', 'longdash', 'dashed')) #自定义线条的类型