【问题标题】:Create a bar graph with pre-summarized data using ggplot2使用 ggplot2 使用预先汇总的数据创建条形图
【发布时间】:2012-04-08 23:38:57
【问题描述】:

我在一个名为 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 轴,条形的高度应与第二列中的相应值成比例。 p>

到目前为止,我已经尝试了以下方法:

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

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    你需要的是stat="identity"

    比如这一行

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

    给我这个情节

    这就是你所追求的吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-22
      相关资源
      最近更新 更多