31
也许答案只是被警告。我正在研究使用缩放和居中变量来观察观察值与平均值的差异。这种情节是一种常见的做法。但是当我这样做时,我从ggplot2
得到一个警告。ggplot2警告:当ymin!= 0时堆叠没有明确定义
Warning messages:
1: Stacking not well defined when ymin != 0
我喜欢ggplot2和世界其他地方的快乐和没有警告来我的方式。我尝试通过以下方式摆脱警告,并搜索相关问题(请参阅底部的链接以获取更多有希望的问题)。我的朋友ggplot2仍在警告我。
问题(S):
- 我怎样才能使警告消失?
- 我可以忽略警告吗?
- 这种做法有什么问题吗?
代码尝试:
## The data
mtcars$scaled_mpg <- unlist(tapply(mtcars$mpg, mtcars$cyl, scale))
mtcars <- mtcars[order(mtcars$cyl), ]
mtcars$ID <- unlist(tapply(mtcars$cyl, mtcars$cyl, seq_along))
mtcars$ID <- factor(sprintf("%02d", mtcars$ID))
## ================ Attempt 1 ================
ggplot(mtcars, aes(x = ID, y = scaled_mpg, fill = factor(cyl))) +
geom_bar(stat="identity") + facet_grid(cyl~.)
## ================ Attempt 2 ================
ggplot(mtcars, aes(x = ID, fill = factor(cyl))) +
geom_bar(aes(weight = scaled_mpg)) + facet_grid(cyl~.)
## ================ Attempt 3 ================
dat1 <- subset(mtcars, scaled_mpg >= 0)
dat2 <- subset(mtcars, scaled_mpg < 0)
ggplot() +
geom_bar(data = dat1, aes(x = ID, y = scaled_mpg,
fill = factor(cyl)),stat = "identity") +
geom_bar(data = dat2, aes(x = ID, y = scaled_mpg,
fill= factor(cyl)),stat = "identity") +
facet_grid(cyl~.)
情节:
类似的帖子:
- set length of `geom_hline` in `geom_bar` plot
- ggplot2 - stacking not well defined when ymin !=0
- ggplot2 and a Stacked Bar Chart with Negative Values
是的。在这种情况下,警告将被忽略。它只是在那里让人们注意到他们可能正在通过对barcharts使用非零参考来实施撒谎统计策略。哎呀,你添加facet后甚至没有堆叠。 –