我希望使用rhandsontable显示除NA值之外的所有颜色。因此,例如,如果您在安装了rhandsontable的R控制台中运行以下代码,第一列将是灰色的,因为我相信rhandsontable无法处理NA和数字值。但是,如果您删除一个NA,使细胞空白,其余的细胞恢复其颜色。
> MAT = matrix(rnorm(50), nrow = 10, dimnames = list(LETTERS[1:10],
+ letters[1:5]))
> MAT[1,1] <- NA
> rhandsontable(MAT) %>% hot_heatmap()在我的实际数据集中,我有很多NA值,我不希望每一列都显示为灰色。如何告诉rhandsontable仅灰显NA值,而不灰显列中的其余值?
发布于 2016-04-01 00:51:06
我有个黑客。
我将NA值替换为非常具体的0.001。
然后我调整了渲染器,使其将单元格着色为0.001的浅灰色:
# Used by hot_heatmap
renderer_heatmap = function(color_scale) {
renderer = gsub("\n", "", "
function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
heatmapScale = chroma.scale(['%s1', '%s2']);
if (instance.heatmap[col]) {
mn = instance.heatmap[col].min;
mx = instance.heatmap[col].max;
pt = (parseInt(value, 10) - mn) / (mx - mn);
if (value == 0.001) {
td.style.backgroundColor = 'lightgrey';
} else {
td.style.backgroundColor = heatmapScale(pt).hex();
}
}
}
")
renderer = gsub("%s1", color_scale[1], renderer)
renderer = gsub("%s2", color_scale[2], renderer)
renderer
}不是我最好的时候,欢迎更好的答案!
发布于 2020-02-05 19:41:13
这个问题很老了,但不管怎样..rhandsontable的现代版本(我有0.3.7)通过将那些单元格显示为灰色而不影响其他单元格的颜色来正确地处理NAs。
https://stackoverflow.com/questions/36323855
复制相似问题