Error with geom_bar

36 views
Skip to first unread message

Manuel Spínola

unread,
Mar 19, 2011, 1:36:48 PM3/19/11
to ggplot2
Dear list members,

I am trying a geom_bar plot and I got the following error:

data:

> farm2
   Finca      x      y sitio          md
1      1 659941 176987     a  0.11129657
2      2 659512 176098     a  0.60502852
3      3 651258 175814     a  0.75926638
4      4 650894 175779     a  0.14892059
5      5 652324 174998     a  2.24844439
6      6 652197 174910     a 14.03333872
7      7 652377 175091     a  1.05588933
8      8 652270 174077     a  0.47425942
9      9 656095 177502     a  0.93139645
10    10 656145 177312     a  0.23083924
11    11 658116 178902     a 53.53971677
12    12 659692 178963     a  0.95872957
13    13 659411 178985     a  4.03377031
14    14 659197 179364     a  0.59675445
15    15 659370 179284     a  0.44506175
16    16 658839 179159     a  1.04862178
17    17 659247 179733     a  0.38878183
18    18 659302 179354     a  0.73116023
19    19 656271 177388     a  0.86042275
20    20 657788 178661     a  4.88343326
21    21 658441 179401     a  0.21682571
22    22 658909 179599     a  2.48780447
23    23 657186 177335     a  0.37182984
24    24 658787 178867     a  0.65307929
25    25 656768 177666     a  0.22946454
26    26 656953 177901     a  2.71364589
27    27 659470 179179     a  1.23080250
28    28 659202 179066     a 12.14833129
29    29 650321 176217     a  0.35453163
30    30 657415 179352     a 18.20586495
31    31 657193 179180     a  0.06914032
32    32 658508 179346     a  0.43673946
33    33 658746 179267     a  0.82066372
34    34 658928 179432     a  1.91392567
35    35 505294 206985     b  0.10001618
36    36 504818 206013     b  0.46351222
37    37 506036 206212     b  0.70019871
38    38 506167 206036     b  0.51436428
39    39 506087 206192     b  0.30037581
40    40 506060 206141     b  0.23654013
41    41 505923 206365     b  0.46672358
42    42 504629 206055     b  0.66650217
43    43 504981 205812     b  0.67285252
44    44 504843 207266     b  0.48121077
45    45 504895 206011     b  0.29055830
46    46 504975 206070     b  3.72820815
47    47 504587 206782     b  1.99401167
48    48 505478 205525     b  0.38590571
49    49 506976 206485     b  0.40458483
50    50 507023 206435     b  0.61908665
51    51 506305 206452     b  0.43070831
52    52 505200 206635     b 21.69426738
53    53 504916 206336     b  0.18556240
54    54 504731 206098     b  0.15225639
55    55 505154 207828     b  0.37842713
56    56 505269 206215     b  0.19634515


> p = ggplot(farm2, aes(Finca, md))
> p + geom_bar()
stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
Error in data.frame(list(count = c(0, 1, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2,  :
  arguments imply differing number of rows: 33, 56

I don't understand the error message.

Is because I need to convert "Finca" to a factor?

Best,

Manuel

--
Manuel Spínola, Ph.D.
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspi...@una.ac.cr
mspin...@gmail.com
Teléfono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de río
Institutional website: ICOMVIS

Kohske Takahashi

unread,
Mar 19, 2011, 7:54:18 PM3/19/11
to Manuel Spínola, ggplot2
Hi,

If you just want to put bars on each Finca, stat="identity" does it:

ggplot(farm2, aes(Finca, md))+geom_bar(stat="identity")


--
Kohske Takahashi <takahash...@gmail.com>

Research Center for Advanced Science and Technology,
The University of  Tokyo, Japan.
http://www.fennel.rcast.u-tokyo.ac.jp/profilee_ktakahashi.html

> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>

Manuel Spínola

unread,
Mar 20, 2011, 8:37:36 AM3/20/11
to Kohske Takahashi, ggplot2
Thank you very much Kohske.

Manuel
Reply all
Reply to author
Forward
0 new messages