【发布时间】:2019-02-24 13:26:34
【问题描述】:
想要创建一堆 1D 热图:
- 显示中心性(例如均值,由高亮表示)
- 显示离散度(例如标准偏差,由分级表示)
注意:中心性或分散性不取决于样本量。每个变量的条形长度应该是恒定的,样本大小不是(必要的)。
例如它看起来如何
这里是类似变量的最小示例:
library(plyr)
v1 <- c("yes", "rather no", "yes", "yes", "yes", "rather yes", "rather yes", "rather no", "rather no", "no", "no", "no")
(v1 <- factor(v1, levels=c("no", "rather no", "rather yes", "yes"), ordered = TRUE)) # order factor values & show
# now, one variant how to re-code/transform the _ordered_ factors as/to values
# (you may have a better proposal/oppinion)
(v1n <- sapply(v1, function(x) as.numeric(as.character(mapvalues(x, from=c("no", "rather no", "rather yes", "yes"), to=c("0", "0.333", "0.666", "1")))))) # re-code to numeric & show
(v1n.mean <- mean(v1n)) # calculate mean & show
(v1n.sd <- sd(v1n)) # calculate standard deviation & show
v2 <- c("rather yes", "rather yes", "rather no", "rather no", "rather no", "rather no", "rather no", "rather no", "rather no")
v2 <- factor(v2, levels=c("no", "rather no", "rather yes", "yes"), ordered = TRUE)
v2
v2n <- sapply(v2, function(x) as.numeric(as.character(mapvalues(x, from=c("no", "rather no", "rather yes", "yes"), to=c("0", "0.333", "0.666", "1")))))
v2n
(v2n.mean <- mean(v2n))
(v2n.sd <- sd(v2n))
v3 <- c("yes", "yes", "yes", "rather yes", "rather yes", "rather yes", "rather no", "no")
v3 <- factor(v3, levels=c("no", "rather no", "rather yes", "yes"), ordered = TRUE)
v3
v3n <- sapply(v3, function(x) as.numeric(as.character(mapvalues(x, from=c("no", "rather no", "rather yes", "yes"), to=c("0", "0.333", "0.666", "1")))))
v3n
(v3n.mean <- mean(v3n))
(v3n.sd <- sd(v3n))
【问题讨论】:
-
示例图片中的连续阴影具有分级,这意味着连续变量。但是您的数据是离散的。您想为每个变量显示四个矩形,还是要将数据视为连续数据并显示密度?
-
@G5W:谢谢!是的,实际上我已经将变量重新编码为:-2 表示“否”,-1 表示“相当不”,1 表示“相当是”,2 表示“是”。在这里,我选择让支持者来决定如何正确地重新编码数据——也许其他人有更好的建议。 (-:
-
如果您将代码缩进保存在@alex 列表中,则代码缩进需要四个额外的空格 - 这意味着第一级总共需要 8 个空格。或者,使用带反引号的 GH 样式格式。
-
@Zoe:如前所述,我知道如何缩进代码——它根本无法在我的机器上运行(已停用一些 javascript)。如果可能,请自行调整。谢谢(-:
-
您的意思是对 v3 有不同数量的响应吗?