Hi @ all, I have a problem concerning the barplot (barchart lattice) of a dataframe. I work with the attached dataframe. When I try to plot this dataframe I only get two rows plottet. When I try to plot the whole dataframe, there is message, that it is 'height' must be a vector or a matrix. On the y-axis, the "amount_cattle" should be displayed and on the x-axis the "year" and the "country" so that I can compare the amount over the years in each country. Each country on the x-axis needs 4 bars (2000-2003). I hope you can help me. Thanks a lot geophagus -- View this message in context: http://r.789695.n4.nabble.com/barchart-with-3-Arguments-tp4641572.html Sent from the R help mailing list archive at Nabble.com.
No data is attached. The R-help list usually strips out attachments to prevent viruses or malware spreading. Use dput to include the data . Just do : dput(mydata) and copy the results into your email. Also it is a good idea to include the code that you are using. John Kane Kingston ON Canada> -----Original Message----- > From: falk.hilliges at twain-systems.com > Sent: Tue, 28 Aug 2012 08:05:47 -0700 (PDT) > To: r-help at r-project.org > Subject: [R] barchart with 3 Arguments > > Hi @ all, > I have a problem concerning the barplot (barchart lattice) of a > dataframe. I > work with the attached dataframe. > When I try to plot this dataframe I only get two rows plottet. When I > try > to plot the whole dataframe, there is message, that it is 'height' must > be a > vector or a matrix. > On the y-axis, the "amount_cattle" should be displayed and on the x-axis > the > "year" and the "country" so that I can compare the amount over the years > in > each country. Each country on the x-axis needs 4 bars (2000-2003). > I hope you can help me. > Thanks a lot > geophagus > > > > > > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/barchart-with-3-Arguments-tp4641572.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.____________________________________________________________ FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more!
Thank you - I'll try it today and give you a reply!! Thanks a lot Geo -- View this message in context: http://r.789695.n4.nabble.com/barchart-with-3-rows-tp4641572p4641697.html Sent from the R help mailing list archive at Nabble.com.
On 08/29/2012 01:05 AM, Geophagus wrote:> Hi @ all, > I have a problem concerning the barplot (barchart lattice) of a dataframe. I > work with the attached dataframe. > When I try to plot this dataframe I only get two rows plottet. When I try > to plot the whole dataframe, there is message, that it is 'height' must be a > vector or a matrix. > On the y-axis, the "amount_cattle" should be displayed and on the x-axis the > "year" and the "country" so that I can compare the amount over the years in > each country. Each country on the x-axis needs 4 bars (2000-2003). > I hope you can help me. > Thanks a lot > geophagus >Hi geophagus, You seem to want to plot the amount_cattle values for years within countries. You can do this with the "barplot" function: amount_cattle<-matrix(sample(10:50,16),nrow=4) colnames(amount_cattle)<- c("Muckravia","Blotinsk","Overthar","Fumingo") rownames(amount_cattle)<-2000:2003 barpos<-barplot(amount_cattle,beside=TRUE) legend(4,45,2000:2003,fill=gray(c(0.2,0.4,0.6,0.8))) You can also nest the values by year within the average values for countries by reshaping the amount_cattle matrix to this form: newcattle ncattle country year 1 21 Muckravia 2000 2 19 Blotinsk 2000 3 40 Overthar 2000 4 27 Fumingo 2000 5 46 Muckravia 2001 6 38 Blotinsk 2001 7 39 Overthar 2001 8 48 Fumingo 2001 9 33 Muckravia 2002 10 34 Blotinsk 2002 11 35 Overthar 2002 12 23 Fumingo 2002 13 16 Muckravia 2003 14 30 Blotinsk 2003 15 14 Overthar 2003 16 32 Fumingo 2003 library(plotrix) barNest(ncattle~country+year,newcattle,FUN="mean", col=list("lightgray",rainbow(4), c("wheat","lightgreen","yellow","thistle"))) Jim
Thanks a lot 2 all of you. Both proposals work very fine!! Thank you and best greetings. Geophagus -- View this message in context: http://r.789695.n4.nabble.com/barchart-with-3-rows-tp4641572p4641809.html Sent from the R help mailing list archive at Nabble.com.