【问题标题】:Generating a continuous heatmap with uneven sampling in x axis在 x 轴上生成不均匀采样的连续热图
【发布时间】:2020-03-01 01:58:01
【问题描述】:

我正在尝试使用一些不均匀采样的数据创建热图。原来,什么时候,应用代码

ggplot(df,aes(x,y,fill=z))+geom_tile()

我得到一个如下所示的热图:

现在,我有兴趣进一步探索大约 0.1 的 x 值。我对数据进行采样并使用同一行代码生成新的热图,现在我的热图如下所示:

我的猜测是,现在 ggplot 不知道如何生成绘图的其余部分以使其看起来连续。我正在考虑尝试使用 tidyr 填充功能来填补空白,但我并不完全确定如何采用这种方法。还有另一种方法,只使用 ggplot 函数吗?以下是数据的样例:

sample_df<-structure(list(x = c(0.51, 1.61, 1.41, 1.61, 0.91, 0.01, 0.31, 
1.71, 1.11, 0.21, 0.31, 0.31, 0.61, 0.71, 1.71, 1.91, 0.51, 1.41, 
0.08, 0.065), y = c(0.0811, 0.0561, 0.0701, 0.0891, 0.0251, 0.0221, 
0.0011, 0.0641, 0.0271, 0.0551, 0.0501, 0.0971, 0.0171, 0.0171, 
0.0611, 0.0801, 0.0021, 0.0401, 0.0811, 0.0511), z = c(0.778151250383644, 
0.477121254719662, 0.477121254719662, 0.477121254719662, 0.602059991327962, 
Inf, Inf, 0.477121254719662, 0.477121254719662, 1.11394335230684, 
0.903089986991944, 0.954242509439325, 0.602059991327962, 0.602059991327962, 
0.477121254719662, 0.477121254719662, Inf, 0.477121254719662, 
2.05307844348342, 2.34439227368511)), row.names = c(NA, -20L), spec = structure(list(
cols = list(epsilon = structure(list(), class = c("collector_double", 
"collector")), mu = structure(list(), class = c("collector_double", 
"collector")), eta = structure(list(), class = c("collector_double", 
"collector")), N0 = structure(list(), class = c("collector_double", 
"collector"))), default = structure(list(), class = c("collector_guess", 
"collector")), skip = 1), class = "col_spec"), class = c("spec_tbl_df", 
"tbl_df", "tbl", "data.frame"))

【问题讨论】:

    标签: r ggplot2 heatmap


    【解决方案1】:

    终于自己搞定了。由于我的数据间距在 0.1 左右,我可以将每个 tile 的宽度设为 0.1,它会填满整个空间。

    ggplot(df,aes(x,y,fill=z))+geom_tile(width=0.1)
    

    给出想要的情节

    【讨论】:

      猜你喜欢
      • 2021-11-23
      • 2021-06-03
      • 2012-09-18
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 2018-04-10
      • 1970-01-01
      相关资源
      最近更新 更多