如何用ggplot2绘制频率? [英] How to barplot frequencies with ggplot2?
本文介绍了如何用ggplot2绘制频率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个熔化的数据集,其中包含一列值",该值表示随数据集的每一行而变化的绝对数.我想按国家/地区在条形图中显示此数字.
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))
我所得到的是:
pmin(y,0)中的错误:找不到对象"y".
Error in pmin(y, 0) : Objekt 'y' not found.
当然,我三遍检查了是否存在值"变量,但我只是找不到问题所在.如果离开y = ...,我得到的每个国家/地区的观察值与我的情况相同.
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.
推荐答案
您可能需要在 geom_bar()
中定义身份统计信息.
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")
这篇关于如何用ggplot2绘制频率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文