美文网首页
富集分析图左侧名称拥挤解决办法

富集分析图左侧名称拥挤解决办法

作者: 医只蜗牛 | 来源:发表于2021-07-16 10:33 被阅读0次

    富集分析图左侧名称拥挤解决办法

    耐药患者组织与敏感的患者组织内的成纤维细胞比较

    -主要修改地方【对比旧代码】

    1.theme_bw(base_size = 7)
    2.axis.text.y = element_text(size = 7))

    
    library( "ggplot2" )
    {
      kegg_down_dt <- as.data.frame( kk.down )
      kegg_up_dt <- as.data.frame( kk.up )
      down_kegg <- kegg_down_dt[ kegg_down_dt$pvalue < 0.05, ]
      down_kegg$group = -1
      up_kegg <- kegg_up_dt[ kegg_up_dt$pvalue < 0.05, ]
      up_kegg$group = 1
    
      dat = rbind( up_kegg, down_kegg )
      dat$pvalue = -log10( dat$pvalue )
      dat$pvalue = dat$pvalue * dat$group
      
      dat = dat[ order( dat$pvalue, decreasing = F ), ]
      
      g_kegg<- ggplot(dat, aes(x=reorder(Description,order(pvalue, decreasing = F)), y=pvalue, fill=group)) + 
        geom_bar(stat="identity") + 
        scale_fill_gradient(low="blue",high="red",guide = FALSE) + 
        scale_x_discrete(name ="Pathway names") +
        scale_y_continuous(name ="log10P-value") +
        coord_flip() + theme_bw(base_size = 7)+
        theme(plot.title = element_text(hjust = 0.5),  axis.text.y = element_text(size = 7))+
        ggtitle("Pathway Enrichment") 
      
      ###修改了数值,【7,可修改】,下面为旧代码。
      
      # g_kegg <- ggplot( dat, 
      #                   aes(x = reorder( Description, order( pvalue, decreasing=F ) ), y = pvalue, fill = group)) + 
      #   geom_bar( stat = "identity" ) + 
      #   scale_fill_gradient( low = "blue", high = "red", guide = F ) + 
      #   scale_x_discrete( name = "Pathway names" ) +
      #   scale_y_continuous( name = "log10P-value" ) +
      #   coord_flip() + theme_bw() + theme( plot.title = element_text( hjust = 0.5 ) ) +
      #   ggtitle( "Pathway Enrichment" ) 
      print( g_kegg )
      ggsave( g_kegg, filename = 'kegg_up_down.png' )
    }
    

    相关文章

      网友评论

          本文标题:富集分析图左侧名称拥挤解决办法

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