【问题标题】:Is there an R function to plot a single variable as a heatmap? [closed]是否有 R 函数将单个变量绘制为热图? [关闭]
【发布时间】:2020-09-16 06:54:30
【问题描述】:

我已经生成了一些 RNA-seq 数据,并拥有两组之间的 DE 基因列表和倍数变化 (log2FC)。

我希望能够在与该图中类似的单个条形图中为该组比较绘制 log2FC 的摘要热图

.

有没有人知道如何为此编写一个 ggplot 脚本?

谢谢。

【问题讨论】:

    标签: r ggplot2 heatmap pheatmap rna-seq


    【解决方案1】:

    您可以在 ggplot 中使用 geom_tile() 实现非常相似的效果。

    library(ggplot2)
    library(tidyr)
    library(dplyr)
    
    # generate random fold changes
    df <- data.frame(
      group1 = rnorm(100),
      group2 = rnorm(100)
    )
    # get order by first group
    df$pos <- rank(df$group1, ties.method="first")
    
    # convert from wide to long for ggplot
    df.long <- pivot_longer(
      df, c("group1","group2"),
      names_to="group", values_to="logFC"
    )
    
    ggplot(df.long, aes(x=pos, y=reorder(group, desc(group)), fill=logFC)) +
      geom_tile() +
      scale_fill_gradient2(low="blue", mid="black", high="yellow", midpoint=0) +
      theme_void() +
      theme(
        legend.position="top",
        axis.text.y=element_text()
      )
    

    制作剧情:

    【讨论】:

    • 好主意。更新了答案并添加了色阶。
    • 太棒了!非常感谢!
    猜你喜欢
    • 2022-11-02
    • 2016-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-14
    • 2021-12-03
    • 1970-01-01
    • 2020-10-10
    相关资源
    最近更新 更多