R中使用ggplot的条形图错误
我尝试使用 ggplot2 制作时间序列数据集的条形图,但收到以下错误消息(我已在类似的数据集上执行此操作并且它有效):
Error in if (!is.null(data$ymin) && !all(data$ymin == 0)) warning("Stacking not well defined when ymin != 0", : missing value where TRUE/FALSE needed
为此,我使用了以下代码:
p <- ggplot(dataset, aes(x=date, y=value)) + geom_bar(stat="identity")
如果我使用 geom_point()
而不是 geom_bar()
它工作得很好。
I try to make a barplot of a time-series dataset with ggplot2
but I get following error message (I have performed this on a similar dataset and it works):
Error in if (!is.null(data$ymin) && !all(data$ymin == 0)) warning("Stacking not well defined when ymin != 0", : missing value where TRUE/FALSE needed
For this I have used following code:
p <- ggplot(dataset, aes(x=date, y=value)) + geom_bar(stat="identity")
If I use geom_point()
instead of geom_bar()
it works fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有提供可重现的示例,所以我只是猜测,但您的语法对我来说看起来不正确。检查此处:http://docs.ggplot2.org/current/geom_bar.html
图表默认生成计数表格:
如果您希望它做不同的事情,您需要告诉它使用什么统计数据。有关使用平均值的示例,请参阅上面的链接(朝向底部)。或者,请参阅此处的混合点/散点图(页面最底部):
http://docs.ggplot2.org/current/position_jitter.html
但从根本上来说你有两个连续变量,我不清楚为什么你想要除了散点图之外的任何东西。
You haven't provided a reproducible example, so I'm just guessing, but your syntax doesn't look right to me. Check here: http://docs.ggplot2.org/current/geom_bar.html
Bar charts by default produce tabulations of counts:
If you want it to do something different, you'll need to tell it what statistic to use. See the link above (towards the bottom) for an example using the mean. Alternatively, see here for a hybrid point/scatterplot (very bottom of the page):
http://docs.ggplot2.org/current/position_jitter.html
But fundamentally you have two continuous variables and it's not clear to me why you'd want anything but a scatterplot.