r - 显示复杂热图中的数字
问题描述
嗨,我正在尝试在 HEATMAP 上显示 df 的数字
我有这个 df
> matrinrmatr
ce n1 n2 n3 ca
sn 6.47 1.89 0.52 NA NA
inn 6.47 3.94 NA NA NA
pn 6.93 NA NA NA NA
bn 6.40 6.63 5.08 5.56 2.73
cn 7.67 2.13 2.03 5.70 NA
vn 7.29 3.37 2.76 3.74 2.18
cin 5.57 3.61 2.51 3.72 2.18
我尝试使用以下脚本制作热图
hmmatrinr <- Heatmap(matrinrmatr,
row_title="Grupos",
column_title="camadas",
col=colheatp,
cluster_rows=FALSE,
cluster_columns=FALSE,
show_column_dend=FALSE,
width=unit(6, "cm"),
height=unit(9, "cm"),
heatmap_legend_param=list(
title="Score",
at=c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12),
legend_height=unit(8, "cm"),
grid_width=unit(0.5, "cm")
),
layer_fun <- function(j, i, x, y, width, height, fill) {
grid.text
(sprintf("%s",
pindex(matrinrmatr, i, j),
x=x, y=y,
gp=gpar(fontsize=10, col="grey")))
}
)
我有这个没有 layer_fun 部分的热图,没有单元格上的数字 https://i.stack.imgur.com/0AMoV.png
问题出在 layer_fun 部分
它给了我
Error in sprintf("%s", pindex(matrinrmatr, i, j), x = x, y = y, gp = gpar(fontsize = 10, :
arguments cannot be recycled to the same length
我试着用
layer_fun <- function(j, i, x, y, width, height, fill) {
grid.text
(sprintf(
"%f",
pindex(matrinrmatr, i, j), x=x, y=y))
}
结果是
Warning message:
In sprintf("%f", pindex(matrinrmatr, i, j), x = x, y = y) :
2 arguments not used by format '%f
也试过
layer_fun <- function(j, i, x, y, width, height, fill) {
grid.text
(sprintf("%s",
pindex(matrinrmatr, i, j), x=x, y=y))
}
并给了我
Warning message:
In sprintf("%s", pindex(matrinrmatr, i, j), x = x, y = y) :
2 arguments not used by format '%s'
没有数字
如果有人可以帮助我,我将不胜感激。谢谢
解决方案
推荐阅读
- r - 在 R 中使用 bnstruct 为动态贝叶斯网络设置层
- python - 如何使用列列表进行分组
- asp.net-core - asp-标签未在 Blazor 服务器端应用程序中突出显示
- python - 无法在终端执行使用 tkinter 和 py2app 创建的 Mac 应用程序
- c - open() 的“模式”参数不会为文件设置正确的权限
- javascript - 使用 django-Javascript 将导航栏图标更改为活动状态
- sql - 查询工资超过4000的公司名称
- python - python marshmallow:验证嵌套请求 JSON 的任何解决方法?
- javascript - 使用 JavaScript 在 Chrome 中单击按钮
- python - np.multiply "where" 条件有问题?