使用ggplot2创建包含预先汇总数据的条形图

Ank*_*kit 4 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
Run Code Online (Sandbox Code Playgroud)

如何从此数据创建简单的条形图,其中第一列沿x轴,并且条的高度应与第二列中的对应值成比例.

直到现在,我尝试了以下方法:

binData <- read.table("binFile")
costBars = ggplot(binData,aes(x=V1,y=V2))
finalPlot2 = costBars + geom_bar()
finalPlot2
Run Code Online (Sandbox Code Playgroud)

但是这些命令会产生以下错误?

stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
Error in pmin(y, 0) : object 'y' not found
Run Code Online (Sandbox Code Playgroud)

Ben*_*Ben 7

你需要的是什么 stat="identity"

例如,这一行

ggplot(data=binfile, aes(x=V1, y=V2)) + geom_bar(stat="identity")
Run Code Online (Sandbox Code Playgroud)

给了我这个情节

在此输入图像描述

这就是你要追求的吗?