R中使用ggplot的条形图错误

发布于 2024-11-27 19:55:48 字数 449 浏览 1 评论 0原文

我尝试使用 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

能否归途做我良人 2024-12-04 19:55:48

您没有提供可重现的示例,所以我只是猜测,但您的语法对我来说看起来不正确。检查此处:http://docs.ggplot2.org/current/geom_bar.html

图表默认生成计数表格:

p <- ggplot( dataset, aes( factor(date) ) ) + geom_bar()

如果您希望它做不同的事情,您需要告诉它使用什么统计数据。有关使用平均值的示例,请参阅上面的链接(朝向底部)。或者,请参阅此处的混合点/散点图(页面最底部):
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:

p <- ggplot( dataset, aes( factor(date) ) ) + geom_bar()

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文