本文介绍了ggplot2警告:当ymin!= 0时堆叠不能很好地定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 也许答案只是被警告。我正在研究使用缩放和居中变量来观察观察值与平均值的差异。这种情节是一种常见的做法。但是当我这样做时,我从 ggplot2 发出警告。 警告信息: 1:当ymin!= 0时堆叠不能很好定义 我喜欢ggplot2,世界其他地方都很开心,没有任何警告会以我的方式出现。我尝试通过以下方式摆脱警告,并搜索相关问题(请参阅底部的链接以获取更多有希望的问题)。 $ b 问题 我怎样才能让警告消失? 我可以忽略警告吗? 这种做法有什么问题吗? ##数据 mtcars $ scaled_mpg< - unlist(tapply(mtcars $ mpg,mtcars $ ), mtcars mtcars $ ID mtcars $ ID< - factor(sprintf(%02d,mtcars $ ID)) ## ================尝试1 ================ ggplot(mtcars,aes(x = ID,y = scaled_mpg,fill = factor(cyl)))+ geom_bar(stat =identity)+ facet_grid(cyl〜。) ## ================尝试2 ========== ====== ggplot(mtcars,aes(x = ID,fill = factor(cyl)))+ geom_bar(aes(weight = scaled_mpg))+ facet_grid(cyl〜。) ## ================尝试3 ================ dat1< - 子集(mtcars,scaled_mpg> = 0) dat2 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〜。) 情节: $ b $ ul $ b $ 设定`geom_hline`的长度`geom_bar` plot ggplot2 - 当ymin!= 0时堆栈不能很好地定义 解决方案 1)通过添加 position =identity至 geom_bar 或者当然可以使用 suppressWarnings(print(ggplot(...))) 考虑到技术方面 - 是的,你可以忽略它。此警告的原因与解释条形图具有负高而不仅仅是负值。 Perhaps the answer is to just be warned. I am attmepting to use a scaled and centered variable to look at how observations differ from the mean value. This plot is a common practice. But when I do this I get a warning from ggplot2. Warning messages:1: Stacking not well defined when ymin != 0 I like to have ggplot2 and the rest of the world happy and no warnings coming my way. I tried to get rid of the warning in the following ways and searched SO (see links at bottom for some more promising questions) for related questions. Still my friend ggplot2 is warning me.QUESTION(S): How can I make the warning go away? Can I ignore the warning? Is there something wrong with this practice?Code attempts:## The datamtcars$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~.)The plot:Similar posts: set length of `geom_hline` in `geom_bar` plotggplot2 - stacking not well defined when ymin !=0ggplot2 and a Stacked Bar Chart with Negative Values 解决方案 1) Either by adding position = "identity" to geom_bar or, of course, by using suppressWarnings(print(ggplot(...)))2-3) Considering the technical side - yes, you can ignore it. The reason for this warning is related to interpreting that bars have negative height instead of just negative values. 这篇关于ggplot2警告:当ymin!= 0时堆叠不能很好地定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-31 23:20