r - 使用 ggplot2 创建带有预先汇总数据的条形图

标签 r ggplot2

我在名为 binFile 的文件中有以下数据

78 1
79 4
80 33
81 150
82 714
83 2663
84 8834
85 25679
86 63654
87 139731
88 265909
89 441686
90 639773
91 803736
92 879616
93 832181
94 682584
95 480228
96 290093
97 149299
98 65443
99 24487
100 7487
101 1835
102 402
103 59
104 10

我如何创建一个简单的 条形图从这个数据中,第一列沿着 x 轴,条形的高度应该与第二列中的相应值成比例。

到目前为止,我已经尝试了以下方法:
binData <- read.table("binFile")
costBars = ggplot(binData,aes(x=V1,y=V2))
finalPlot2 = costBars + geom_bar()
finalPlot2

但是这些命令会产生以下错误?
stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
Error in pmin(y, 0) : object 'y' not found

最佳答案

您需要的是stat="identity"
例如,这一行

ggplot(data=binfile, aes(x=V1, y=V2)) + geom_bar(stat="identity")

给我这个情节

enter image description here

那是你追求的吗?

关于r - 使用 ggplot2 创建带有预先汇总数据的条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10067452/

相关文章:

r - 在文本编辑器中集成 R linter 的选项有哪些? svTools、codetools 等中的 lint

r - 如何在ggplot中突出显示沿曲线的点

r - ggplot2 中的日期刻度显示错误的标签

r - ggplot2:在不影响限制的情况下添加几何图形

r - 使用 data.table 按组显示重复项

r - 如何转换时间和日期

r - 对 Gamma 分布使用 anova() 给出看似随机的 p 值

r - 在 R 中以交互方式获取库的内容

r - 平滑曲线上的最大曲线变化率

r - geom_abline 多个斜率和截距