【问题标题】:Plotting bubble plot : All the pathway term on a single axis绘制气泡图:单个轴上的所有路径项
【发布时间】:2021-04-17 07:12:49
【问题描述】:

这是我的示例数据

a <- dput(head(df))
structure(list(Term = c("Reactome Gene Sets", "GO Biological Processes", 
"GO Biological Processes", "GO Biological Processes", "GO Biological Processes", 
"GO Biological Processes"), Pathway = c("R-MMU-191273", "GO:0034341", 
"GO:0050900", "GO:0046942", "GO:0001817", "GO:0048871"), VVV = c("Cholesterol biosynthesis", 
"response to interferon-gamma", "leukocyte migration", "carboxylic acid transport", 
"regulation of cytokine production", "multicellular organismal homeostasis"
), p_value = c(-11.6414922875, -9.3148301923, -6.2150336681, 
-5.9190690396, -5.8467499202, -5.767770517)), row.names = c(NA, 
-6L), class = c("tbl_df", "tbl", "data.frame"))

我在这里尝试显示路径及其各自的 pvalue

我的代码

ggplot(df, aes(x=Term,y=p_value)) +
  geom_point(aes(size=abs(p_value))) +
  #geom_text(data=df,label=df$Pathway) + 
  geom_label_repel(aes(label=Pathway), size=3)+
  
  #scale_color_gradientn(colours = rainbow(5)) +
  labs(
    x='-log10(pvalue)', y=NULL,
    color='p_value',size='pvalue'
  ) +
  theme(
    axis.title = element_text(face='bold'),
    axis.text = element_text(face='bold')
  )

我得到的输出是这个

有没有办法让我也可以将 Reactome 基因设置在与 GO 生物过程相同的轴或线上。我的想法是在一行中显示所有这些,显着的 pvalue 显示更大的气泡。

任何建议或帮助将不胜感激。

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    您可以根据Pathway 值应用nudge_x

    library(ggplot2)
    library(ggrepel)
    library(dplyr)
    
    ggplot(df, aes(x=Term,y=p_value)) +
      geom_point(aes(size=abs(p_value))) +
      geom_label_repel(aes(label=Pathway), size=3, 
                       nudge_x = ifelse(grepl('R-MMU', df$Pathway), 1, 3),
                       direction = "y") +
      
      #scale_color_gradientn(colours = rainbow(5)) +
      labs(
        x='-log10(pvalue)', y=NULL,
        color='p_value',size='pvalue'
      ) +
      theme(
        axis.title = element_text(face='bold'),
        axis.text = element_text(face='bold')
      )
    


    让所有东西都在同一个 X 轴上:

    df %>%
      mutate(X_value = '-log10(pvalue)') %>%
      ggplot(aes(x=X_value,y=p_value)) +
      geom_point(aes(size=abs(p_value))) +
      geom_label_repel(aes(label=Pathway), size=3) +
      labs(y=NULL, x = NULL,color='p_value',size='pvalue')
    

    【讨论】:

    • 好吧,这是个好建议,但是否有可能将所有术语放在一行中,换句话说,GO Biological Processes 和 Reactome Gene Sets all in single axis 是可能的......现在 Reactome 是像另一个因素..所以它是单独打印的..现在如果我理解它们就像两个因素一样,所以它们是分开打印的......
    • 黄金级答案
    • 另一种自定义如何为这些数据点着色,例如高于 -8 的一种颜色和低于 -8 的另一种颜色以区分?
    • 您应该将其作为一个新问题提出,以便 1 篇文章仅关注一个特定问题,从而减少未来读者的困惑。
    • 提出了新问题,我只能在 90 分钟内发布一次 ..
    猜你喜欢
    • 1970-01-01
    • 2022-07-12
    • 2019-03-23
    • 2010-12-06
    • 2017-05-03
    • 2017-04-23
    • 1970-01-01
    • 2020-10-31
    • 1970-01-01
    相关资源
    最近更新 更多