【发布时间】:2017-12-01 11:15:43
【问题描述】:
我尝试用 ggplot2 绘制加权密度。结果似乎很好,但我收到以下警告:Warning: Ignoring unknown aesthetics: weight。 other ggplot2 applications 中似乎出现了类似的问题,因此我想知道是否可以忽略警告。
可重现的例子:
library(ggplot2)
set.seed(123)
# Some random data & weights
x <- rnorm(1000, 5)
w <- x^5
# Plot unweighted
ggplot() + stat_density(aes(x = x))
# Plot weighted - Warning: Ignoring unknown aesthetics: weight
ggplot() + stat_density(aes(x = x, weight = w / sum(w))) # Weighting seems to work fine
# Comparison of weighted density in base graphics - Same results as with ggplot2
plot(density(x, weights = w / sum(w)))
可以忽略此警告消息吗?
【问题讨论】:
-
你可以试试
options(warn=-1)? (source) -
@h3rm4n 你永远不应该那样做。如果需要,请使用
suppressWarnings。无论如何,这应该提交给 ggplot2 错误跟踪器(如果尚未提交)。 -
@h3rm4n 我不在乎是否显示警告,我只是想确保我的结果是正确的。
-
@Roland 什么是“ggplot2 错误跟踪器”,我在哪里可以找到它?即使我收到警告消息,您是否同意我的结果有效?
-
@Roland 为什么会这样?出于链接源中提到的原因?