R频率直方图网格

时间:2017-04-14 22:14:08

标签: r ggplot2 histogram frequency

我一直在尝试并且未能制作频率直方图。

这是我的数据:

Species            Length
Cod             28.31964661
Cod             12.93739676
Cod             36.03833829
Cod             12.88226325
Cod             28.09911256
Cod             47.28557474
Cod             30.52498709
Cod             26.94130881
Cod             26.94130881
Cod             13.65413242
Cod             41.44142246
Cod             27.54777744
Cod             26.77590827
Cod             18.1750804
Cod             33.72273078
Cod             26.22457315
Cod             24.79110184
Cod              25.34243696
Cod             33.61246376
Cod              27.54777744
Cod             52.90919296
Cod              52.35785784
Cod              18.72641552
Cod              33.94326483
Cod              33.94326483
Cod              30.30445304
Cod              35.81780424
Cod              39.67715008
Cod             45.19050128
Cod             24.23976672
Cod              26.4451072
Cod              35.26646912
Cod              44.08783104
Cod              39.12581496
Cod              41.33115544
Cod             51.2551876
Cod             53.46052808
Whiting         25.60824365
Whiting         27.36286387
Whiting         18.50620941
Whiting         20.26082963
Whiting         20.26082963
Whiting         19.59240288
Whiting         24.60560352
Whiting         14.57920224
Whiting         17.921336
Whiting         20.42793632
Haddock       26.19769059
Haddock         21.89769581
Haddock         17.49997388
Haddock         10.6590731
Haddock         33.42949998
Haddock       15.25224934
Haddock         17.49997388
Haddock       18.47724542
Haddock       29.91132244
Haddock         29.91132244
Haddock       36.45904176
Haddock       32.06131983
Haddock       32.06131983
Haddock       25.61132766
Haddock       26.49087205
Haddock       28.15223367
Haddock       29.03177805
Haddock       30.59541252
Haddock       34.30904437
Haddock       10.6590731
Haddock       10.6590731
Haddock       23.36360312
Haddock       23.36360312
Haddock         26.29541774
Haddock         29.22723236
Haddock       37.04540468
Haddock         42.90903392
Pout Whiting or Bib 8.99337009
Pout Whiting or Bib 13.85980985
Pout Whiting or Bib 10.91252943
Pout Whiting or Bib 11.18669505
Pout Whiting or Bib 14.33959968
Pout Whiting or Bib 25.85455572
Pout Whiting or Bib 15.29917935
Pout Whiting or Bib 18.7262496
Pout Whiting or Bib 22.8387339
Pout Whiting or Bib 22.8387339
Pout Whiting or Bib 23.52414795
Pout Whiting or Bib 24.209562
Pout Whiting or Bib 27.63663225
Poor Cod        10.35396128
Poor Cod        11.42519924
Poor Cod          22.67319782
Poor Cod          15.88869074
Poor Cod          21.18536732
Poor Cod          17.19798158
Poor Cod          7.79489282
Poor Cod          12.7940033
Poor Cod          15.23404532
Poor Cod          12.4964372
Poor Cod          13.27010906
Poor Cod          13.50816194
Poor Cod          13.86524126
Poor Cod          13.27010906
Poor Cod          7.1402474
Poor Cod          7.7353796
Poor Cod          10.1159084
Poor Cod          10.1159084
Poor Cod            10.7110406
Poor Cod            11.901305
Poor Cod            14.2818338

以下是我对每条鱼的追求:

Graph of One Fish

理想情况下,这将在面部网格上编织在一起,这样我就可以将所有鱼展示在一起。

这是我目前的无用尝试:

ggplot(data,aes(x=length))+geom_histogram()+facet_grid(~species)+theme_bw()

我有点困惑。我不确定频率方面是否有效? 任何建议将不胜感激。

1 个答案:

答案 0 :(得分:0)

R,与大多数非古老的编程语言一样,区分大小写。

您的变量名称为"长度"和"物种"。你正在调用小写"长度"和"物种"。

大写并且它将起作用:

ggplot(data, aes(x=Length)) + geom_histogram() + facet_grid(~Species) + theme_bw()