r - 错误 : StatBin requires a continuous x variable the x variable is discrete. 也许你想要 stat ="count"?

标签 r algorithm

我昨天运行这段代码并且它有效但是在今天运行之后,我得到了这个错误。 错误:StatBin 需要一个连续的 x 变量,而 x 变量是离散的。也许你想要 stat="count"?

library(rattle)
dsname <- "weatherAUS"
ds <- get(dsname)
p <- ggplot(ds, aes(Location, fill=Location))
p <- p + geom_bar(width=1, colour="white")
p <- p + theme(legend.position="none")
p <- p + coord_flip()
p <- p + geom_text(stat="bin",
color="white",
hjust=1.0,
size=3,
aes(y=..count.., label=..count..))

我想知道如何解决这个问题。

最佳答案

根据我的评论,在不检查可能会破坏的内容的情况下,update.packages 甚至 install.package 都不是一个好主意。 ggplot2 2.0 有一些核心差异,Hadley 非常善于沟通。

这是代码的工作版本:

library(rattle)
library(ggplot2)

data(weatherAUS)

p <- ggplot(weatherAUS, aes(Location, fill=Location))

# using geom_bar will automatically make a new "count" column
# available in an internal, transformed data frame. the help
# for geom_bar says as much

p <- p + geom_bar(width=1, colour="white")

# geom_text can then access this computed variable with
# ..count.. (I still thin that's horrible syntax, hadley :-)
p <- p + geom_text(aes(y=..count.., label=..count..),
                   stat="count", color="white",
                   hjust=1.0, size=3)

p <- p + theme(legend.position="none")
p <- p + coord_flip()
p

# to be more explicit to other readers of your code, you
# could also do this instead of the `geom_bar` call
p <- p + stat_count(width=1, colour="white", geom="bar")

enter image description here

除非这只是为了练习 ggplot2,否则为每个条形图单独着色对于“生产”可视化来说可能不是一个好主意。

关于r - 错误 : StatBin requires a continuous x variable the x variable is discrete. 也许你想要 stat ="count"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34838496/

相关文章:

r - 如何使用另一个变量对 geom_segment 中创建的箭头进行加权和标签

r - R : cannot coerce class '"mids"' into a data. 帧中的鼠标问题

r - 在具有相同 x 轴的两个结果的多面图中添加显着性水平

通过不影响其中包含该词的其他名称从字符串中删除词

python - 如何在不强制和/或花费大量计算时间的情况下解决这个问题?

algorithm - 解决这种逻辑问题的方法是什么?

c++ - 如何找到二分查找算法的迭代次数?

r - 了解 plyr 的 ddply 函数

algorithm - 应该对算法/代码进行哪些更改才能获得预期的车辆形状?

algorithm - 动态规划与 Dijkstra 算法的区别