ggplot2警告:未固定在轴上时,堆栈定义不正确

时间:2019-04-16 14:57:07

标签: r ggplot2

由于本书中的代码不再起作用(我使用的是ggplot2 3.1.0),因此我正在尝试以不同的方式再现Wickham的用于数据分析的优雅图形图4.10中的图形。我有一些东西似乎起作用,但它会发出警告消息,我想知道这是怎么回事。

我看过一些相关的帖子,但它们没有回答我的特定问题(ggplot2 Error : Mapping a variable to y and also using stat="bin". example from 'Elegant Graphics for Data Analysis')。我制作的图形似乎正常工作,我只需要有关警告内容的信息。

##this is whats in the book, it doesn't work because of the y variable in the 
##aes()
d <- ggplot(diamonds, aes(carat)) + xlim(0, 3)
d + stat_bin(aes(y = 1, fill = ..count..), binwidth = 0.1, geom = "tile", position="identity")


##My reaction was to just cut out the variable and instead change position to 
##"fill"
d + stat_bin(
    aes(fill = ..count..), binwidth = 0.1,
    geom = "tile", position="fill")

该图形看起来正确,但是给出了以下警告: 未固定在轴上时,堆栈定义不明确

这是什么意思?在我的情况下,这是一个问题吗?什么时候会担心?

---编辑--- 我想澄清一下,我专门使用此特定方法询问该错误。我可以使用其他不会发出警告的方法来制作相同的图形。

-编辑- 这是一些生成我想要的图形的代码。我看起来和上面的代码完全一样,但是并没有警告我:如果堆栈未固定在轴上,则堆栈定义不正确

d <- ggplot(diamonds, aes(carat)) + xlim(0, 3)
d + geom_histogram(
    aes(fill = ..count..), binwidth = 0.1,
    position="fill")

0 个答案:

没有答案