美文网首页基因组数据绘图
柱状图 | 分面柱状图,箱线图

柱状图 | 分面柱状图,箱线图

作者: 一只小脑斧 | 来源:发表于2022-07-05 19:47 被阅读0次

    (125条消息) 【ggplot】复杂柱状图:自定义颜色、标签、位置、坐标轴和主题Ryan_Yang的博客-CSDN博客_复杂柱状图

    data


    LB(KSFY_%~M(_`P@CHNT0WE.png

    data.melt


    GTM$%2VHVSKW6{RKA}EC8J1.png B3M7FJ[C1`E)1MAU]5T$)SG.png
    
    data.melt <- 
      data %>%
      mutate(group = paste0("Cluster", group)) %>%
      # data.frame(row.names = 1) %>%
      # as.matrix() %>%
      melt()
    
    library(ggplot2)
    
    ggplot(data.melt, aes(x=variable,y=value, fill = variable)) +
      geom_boxplot(col="#6a737b")+
      facet_grid(.~factor(group, paste0("Cluster",c(0:8))))+ #分面
      geom_jitter(col="#caccd1", pch=19,cex=0.1, position = position_jitter(0.2))+
      theme_bw()+RotatedAxis()+
      theme(panel.grid = element_blank(),
            axis.text.x=element_text(angle=10,hjust = 1,vjust=0.5))+
      labs(x=NULL,y=NULL,title = "")+
      geom_boxplot(position=position_dodge(0),aes(color = factor(group)))+
      NoLegend()+theme(plot.title = element_text(hjust = 0.5))  #也就加上这一行,标题居中
    
    TO29H$%XHW%)}16BI3PK530.png
    ggplot(data.melt, aes(x=variable,y=value, fill = variable)) +
      geom_bar(col="#6a737b",stat="identity")+#stat=”“identity”:指定了柱状图的高度(y)
      facet_grid(.~factor(group, paste0("cluster.",c(0:8))))+#修改柱形图的顺序
      scale_fill_manual(values=c('#1aafd0','#6a67ce','#ffb900','#fc636b'))+ #颜色
      theme_bw() +#去除背景色
      theme(panel.grid=element_blank()) #去除网格线
    

    相关文章

      网友评论

        本文标题:柱状图 | 分面柱状图,箱线图

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