【问题标题】:Is it possible to add few more details like rich factor to the bar graph along with the pvalve?是否可以在条形图中添加更多细节,如富因子和 pvalve?
【发布时间】:2022-12-05 22:03:43
【问题描述】:
Pathway #Proteins Pvalue Richfactor
Peptide chain elongation 90 1.11E-16 0.5
Translation elongation 79 1.11E-16 0.7
P53 pathway 50 1.11E-16 0.2
cGAS sting pathway 20 1.11E-16 0.4

以上给出的是数据。使用此数据,我尝试生成具有 pvalue 和蛋白质的条形图,但我想向图表添加其他详细信息,例如上面数据中给出的 Rich factor。

library(ggplot2)
library(viridis)

top_fun <- read.delim(file="Pathways.txt",header = TRUE)

topfun <- as.data.frame(top_fun)
#Turn your 'Name' column into a character vector
topfun$Pathway <- as.character(topfun$Pathway)
#Then turn it back into a factor with the levels in the correct order
topfun$Pathway<- factor(topfun$Pathway, levels=unique(topfun$Pathway))



ggplot(topfun,aes(x=Group,y=topfun$Proteins,fill=topfun$Pvalue)) + 
  geom_col(position="dodge",width=0.4) +
  coord_flip() + scale_fill_viridis(option="mako")+
  facet_grid(Pathway~.)+
  theme(strip.text.y = element_text(angle = 0))

使用上面的代码我生成了这张图

我想在图表中添加其他详细信息,例如富因子。谢谢您的帮助!。

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    显而易见的事情是将 Richfactor 映射到 fill 变量。您可以直接将 p 值作为文本添加,因为它们似乎对映射到填充比例不是很有帮助,至少在这个例子中是这样

    ggplot(topfun,aes(x = 'WT', y = Proteins, fill = Richfactor)) + 
      geom_col(position = "dodge", width = 0.4, color = 'gray50') +
      geom_text(aes(y = 1, label = paste('p =', Pvalue), color = Pathway), 
                    hjust = 0) +
      coord_flip() + 
      scale_fill_viridis_c(option = "mako") +
      facet_grid(Pathway ~ .) +
      theme(strip.text.y = element_text(angle = 0)) +
      scale_color_manual(values = c('black', 'black', 'white', 'black'),
                         guide = 'none')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-16
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-18
      • 1970-01-01
      相关资源
      最近更新 更多