【发布时间】:2020-06-03 12:56:21
【问题描述】:
我有一个数据框(下面的快照 - 它实际上有超过 12,000 个观察值),我可以在其中使用 ggplot 并构建一个直方图来单独描述每个变量的分布。我现在有兴趣将我构建的 3 个直方图叠加起来创建一个“单一”直方图。
我已尝试根据a similar question that was asked previously 改编以下建议,
d = data.frame(x = c(data1, data2),
type=rep(c("A", "B"), c(length(data1), length(data2))))
ggplot(d) +
geom_density(aes(x=x, colour=type))
但我不断收到以下错误:
#combinedImputedDataVis is a data frame
distr <- combinedImputedDataVis[,37:39]
ggplot(distr) + geom_density(aes(x=c(rt,controlt,cleart),
type=rep(c("rt","controlt","cleart"),c(length(rt),length(controlt),length(cleart)))))
Error: Aesthetics must be either length 1 or the same as the data (12687): x and type
Run `rlang::last_error()` to see where the error occurred.
In addition: Warning message:
Ignoring unknown aesthetics: type
不知道我哪里错了,希望有第二双眼睛
【问题讨论】:
-
data1和data2是原子数值类型吗?因为我从链接的答案中获取了data1和data2,并且 ggplot2 v3.3.0 没有错误 -
我更新了我的问题以包含我根据之前提供的解决方案创建的代码