R 生成x轴采样不均匀的连续热图
我正在尝试使用一些采样不均匀的数据创建热图。最初,在应用代码时R 生成x轴采样不均匀的连续热图,r,ggplot2,heatmap,R,Ggplot2,Heatmap,我正在尝试使用一些采样不均匀的数据创建热图。最初,在应用代码时 ggplot(df,aes(x,y,fill=z))+geom_tile() 我得到的热图如下所示: 现在,我感兴趣的是进一步研究x在0.1左右的值。我对数据进行采样并使用同一行代码生成新的热图,现在我的热图如下所示: 我的猜测是,现在ggplot不知道如何生成剩余的plot以使其看起来是连续的。我想尝试使用tidyr fill函数来填补空白,但我不完全确定如何使用这种方法。有没有其他方法,只使用ggplot函数?以下是数据的
ggplot(df,aes(x,y,fill=z))+geom_tile()
我得到的热图如下所示:
现在,我感兴趣的是进一步研究x在0.1左右的值。我对数据进行采样并使用同一行代码生成新的热图,现在我的热图如下所示:
我的猜测是,现在ggplot不知道如何生成剩余的plot以使其看起来是连续的。我想尝试使用tidyr fill函数来填补空白,但我不完全确定如何使用这种方法。有没有其他方法,只使用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"))
sample_df最终我自己找到了答案。由于我的数据的间距约为0.1,因此我可以将每个磁贴的宽度设置为0.1,它将填充整个空间
ggplot(df,aes(x,y,fill=z))+geom_tile(width=0.1)
给出所需的绘图