如何使用 ggplot2 绘制频率条形图?

发布于 2024-09-15 14:12:47 字数 402 浏览 3 评论 0原文

我有一个融化的数据集,其中包含一列“值”,它代表一个绝对数字,该数字随数据集的每一行而变化。我想按国家/地区在条形图中显示这个数字。

p <- ggplot(melted,aes(factor(country),y=as.numeric(value))) + geom_bar() +opts(axis.text.x = theme_text(angle = 90,hjust = 1)) 

我得到的只是:

pmin(y, 0) 中出现错误:未找到对象“y”。

当然,我三次检查了是否存在“值”变量,我只是找不到问题所在。如果将 y=... 排除在外,我会得到每个国家的观察结果,在我的例子中,每个国家的观察结果都是相同的。

I have a melted dataset containing a column "value" which represent an absolute number which varies with every row of the dataset. I want to display this number in a barchart by country.

p <- ggplot(melted,aes(factor(country),y=as.numeric(value))) + geom_bar() +opts(axis.text.x = theme_text(angle = 90,hjust = 1)) 

all I get is:

Error in pmin(y, 0) : Objekt 'y' not found.

Of course I triple-checked if there was a "value" variable I just can't find what's wrong. If a leave the y=... out I get the observations per country which are the same for every country in my case.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

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

评论(1

铁憨憨 2024-09-22 14:12:47

您可能需要在geom_bar()中定义身份统计信息。

 ggplot(melted,aes(factor(country),y=as.numeric(value))) + 
        geom_bar(stat = "identity", position = "stack")

You might need to define the identity statistic in geom_bar().

 ggplot(melted,aes(factor(country),y=as.numeric(value))) + 
        geom_bar(stat = "identity", position = "stack")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文