美文网首页生信图可视化大全
R语言-ggplot自定义点的形状、线条的类型

R语言-ggplot自定义点的形状、线条的类型

作者: Whuer_deng | 来源:发表于2019-07-12 10:42 被阅读253次
    library(ggplot2)
    library(ggpubr)
    
    show_point_shapes() #显示点的形状(ggpubr包内的函数)
    
    image.png
    p1 <- ggplot(mpg, aes(x = displ, y = hwy, color = drv, shape = drv)) + 
      geom_point() + 
      theme_bw() #绘制基本图形,不自定义点的形状
    p1
    
    image.png
    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
    
    image.png
    cowplot::plot_grid(p1, p2, labels = c('p1', 'p2')) #组合修改前后两幅图
    
    image.png
    show_line_types() #显示线条类型(ggpubr包内的函数)
    
    image.png
    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
    
    image.png
    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
    
    image.png
    cowplot::plot_grid(p3, p4, labels = c('p3', 'p4'))#组合修改前后两幅图
    
    image.png

    相关文章

      网友评论

        本文标题:R语言-ggplot自定义点的形状、线条的类型

        本文链接:https://www.haomeiwen.com/subject/rotekctx.html