r - 缺失数据的网格图

标签 r plot missing-data

我的数据如下所示:

Col1 Var1 Var2
A     1    NA
B     NA    1
C     1    NA
D     1    1

我想创建缺失数据的网格图,就像使用 Amelia 包 ( https://www.r-bloggers.com/ggplot-your-missing-data-2/ ) 一样

但是,我发现结果很难看。基本上,我希望第 1 列中的变量位于 x 轴上,而 Var1 和 Va2 位于 Y 轴上。存在时像灰色,不存在时像黑色。这有道理吗?

有什么建议吗?我把阿米莉亚图放在下面 enter image description here

最佳答案

基础 R 解决方案

Dat = t(matrix(as.numeric(is.na(df[,2:3])), nrow=nrow(df)))
rownames(Dat) = names(df)[2:3]
colnames(Dat) = df$Col1

heatmap(Dat, NA, NA, scale="none", col=c("gray", "black"))

Heatmap

数据

df = read.table(text="Col1 Var1 Var2
A     1    NA
B     NA    1
C     1    NA
D     1    1", 
header=TRUE)

关于r - 缺失数据的网格图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53875171/

相关文章:

r - ggplot.data.frame : Mapping should be created with aes or aes_string 中的错误

r - `Error in file(con, "r ") : cannot open the connection` 来自运行 BRugsFit()

python - 在 python 中集成直方图?

ruby-on-rails - 为什么 Rails 4 说缺少帮助文件,尽管它在那里?

r - 重复后的数据表截止行

r - ggplot 图例中缺少彩条,Windows 远程桌面

python - 将 x 和 y 抖动添加到 seaborn 线性图中是否会改变拟合值?

python - 如何获得没有填充的标记,来自seaborn 0.11+

python - 如何在python中替换NaN值

R gbm处理缺失值