美文网首页
R语言ggplot2绘图原理(2)深入理解

R语言ggplot2绘图原理(2)深入理解

作者: Bioinfor生信云 | 来源:发表于2022-07-21 20:15 被阅读0次

    点的形状

    R语言自带的点的形状


    library(ggsci)
    ggplot(data = small_diamonds, aes(x=carat, y=price)) +
      geom_point(shape = 21, size = 5, color = "black", aes(fill = cut)) +
      scale_fill_npg () +
      theme_classic()
    

    点的大小

    ggplot(data = small_diamonds, aes(x=carat, y=price)) +
      geom_point(shape = 21, color = "black", aes(fill = cut, size = price)) +
      scale_fill_npg () +
      scale_size(range = c(1,10)) +
      theme_classic()
    

    设置标题

    ggplot(data = small_diamonds, aes(x=carat, y=price)) +
      geom_point(shape = 21, size = 5, color = "black", aes(fill = cut)) +
      scale_fill_npg () +
      scale_y_continuous(breaks = c(5000, 10000, 15000),
                         labels = c('5K', '10K', '15K')) +
      labs(title = 'point plot',
           subtitle = 'my subtitle',
           x = 'weight of the diamond',
           y = 'price in US dollars',
           fill = 'quality of the cut') +
      theme_classic()
    

    主题美化

    ggplot(data = small_diamonds, aes(x=carat, y=price)) +
      geom_point(shape = 21, size = 5, color = "black", aes(fill = cut)) +
      scale_fill_npg () +
      scale_y_continuous(breaks = c(5000, 10000, 15000),
                         labels = c('5K', '10K', '15K')) +
      labs(title = 'point plot',
           x = 'weight of the diamond',
           y = 'price in US dollars',
           fill = 'quality of the cut') +
      theme_classic() +
      theme(plot.title = element_text(hjust = 0.5,
                                      size = 20),
            axis.title = element_text(size = 15),
            legend.position = c(0.15,0.85))
    

    欢迎关注Bioinfor 生信云微信公众号!

    相关文章

      网友评论

          本文标题:R语言ggplot2绘图原理(2)深入理解

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