【问题标题】:Heatmap with binary outcome variables on a continous x-axis - is it possible?在连续 x 轴上具有二进制结果变量的热图 - 有可能吗?
【发布时间】:2019-06-21 09:23:34
【问题描述】:

编造数据

Years (row): 0.5, 0.5, 1.1, 2.0

A: (column 1): 1, 0, 1, 1

B: (column 2): 0, 0, 1, 1

C: (column 3): 0 ,1 ,0, 0

我尝试在 R 中为我的数据制作热图,我希望在 Y 轴和 x 轴上获得不同标记(A、B、C)的结果,我会喜欢有年份(> 200个数据)。

我尝试了许多不同的方法和组合,但不知何故我无法让它发挥作用。

我正在使用 R,我尝试使用 ggplot

library(ggplot2)
ggplot(Data,aes(x=Years,y=markers,fill=factor(Positive/Negative)))+geom_tile()

我知道这是不正确的,但我就是不知道如何让它发挥作用。

【问题讨论】:

    标签: r ggplot2 binary heatmap


    【解决方案1】:

    类似的东西? 您需要融合您的数据,以便您可以将年份和类用作标签,并将您的值用作填充值:

    
    library(data.table)
    df <- fread(
    'Years      A    B   C
    0.19       1    0   0   
    0.21       0    1   1   
    1.00       0    0   1
    2.25       1    0   1'
    )
    
    library(tidyverse)
    
    df %>% melt(id.vars = 'Years') %>% 
      ggplot(aes(x = as.factor(Years), y = as.factor(variable), 
                 fill = as.factor(value))) +
      geom_tile() +
      scale_fill_manual(values = c('black', 'white')) +
      labs(x = 'year', y = 'marker',fill = 'result')
    

    【讨论】:

    • 是的,这正是我一直试图做的。非常感谢,我会试试看能不能成功。
    猜你喜欢
    • 1970-01-01
    • 2021-05-18
    • 1970-01-01
    • 2019-12-16
    • 1970-01-01
    • 2020-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多