我在名为 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")
给我这个情节
那是你追求的吗?
关于r - 使用 ggplot2 创建带有预先汇总数据的条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10067452/