library(ggplot2)
library(ggpubr)
show_point_shapes() #显示点的形状(ggpubr包内的函数)
p1 <- ggplot(mpg, aes(x = displ, y = hwy, color = drv, shape = drv)) +
geom_point() +
theme_bw() #绘制基本图形,不自定义点的形状
p1
p2 <- ggplot(mpg, aes(x = displ, y = hwy, color = drv, shape = drv)) +
geom_point() +
scale_shape_manual(values = c(15, 19, 17)) + #自定义点的形状,分别为15, 19, 17。
theme_bw()
p2
cowplot::plot_grid(p1, p2, labels = c('p1', 'p2')) #组合修改前后两幅图
show_line_types() #显示线条类型(ggpubr包内的函数)
p3 <- ggplot(mpg, aes(x = displ, y = hwy, color = drv, shape = drv, linetype = drv)) + #设置线条类型根据drv分类
geom_smooth(se = F, method = 'loess') + #绘制拟合曲线
geom_point() +
theme_bw()
p3
p4 <- ggplot(mpg, aes(x = displ, y = hwy, color = drv, shape = drv, linetype = drv)) + #设置线条类型根据drv分类
geom_smooth(se = F, method = 'loess') + #绘制拟合曲线
geom_point() +
scale_linetype_manual(values = c('twodash', 'longdash', 'dashed')) + #自定义线条的类型
theme_bw()
p4
cowplot::plot_grid(p3, p4, labels = c('p3', 'p4'))#组合修改前后两幅图