[R] barplot - easy for experienced, difficult for me

John Kane jrkrideau at inbox.com
Tue Oct 1 13:53:09 CEST 2013


There is a slight problem with that second link. It is the same as the first. 

It is easier to sent the data (or a decent sample of it) in the email by using dput.  Type ?dput for more information.  Essentially you just do dput(myfile) copy it and paste it into the email. This allow the reader tp see exactly the data set that you are using.  I think Jim (Lobachevski?) Lemon has given you an answer. 

While this link is not directly linked to your request for other ideas of how to plot the data it may give you some ideas.  I tend to like the point + error bar graph but I am no expert and obviously it depends on your data.

And another off-topic matter, you might want to have a look at the ggplot2 package for graphing. Very different from base graphics but powerful.

Here is a different approach with bar plots using ggplot2 and Jim's data that I have shamelessly appropriated.  It is a more complicated approach as I had to reshape the data into a from that ggplot2 would accept. The data is supplied in dput format.

dat1 <-  structure(list(park1 = c(6, 9, 4, 7, 3, 7, 10, 3, 6), park2 = c(3, 
5, 6, 1, 8, 6, 4, 7, 11), bugs = structure(c(1L, 6L, 8L, 7L, 
5L, 9L, 3L, 4L, 2L), .Label = c("Bug", "Fly", "Gnat", "Midge", 
"Nit", "Slug", "Tick", "Wasp", "Worm"), class = "factor")), .Names = c("park1", 
"park2", "bugs"), row.names = c(NA, -9L), class = "data.frame")


mdat  <-  melt(dat1, id.var = "bugs")  # reshape data using the rehape2 command melt
names(mdat) <-  c("Invertibrate", "park", "Count")

ggplot(mdat, aes(Invertibrate, Count, fill  = park)) + 
  geom_bar(stat="identity") + facet_grid(park ~ .) +
  theme(legend.position="none")


John Kane
Kingston ON Canada


> -----Original Message-----
> From: tobi_gebetsberger at gmx.at
> Sent: Mon, 30 Sep 2013 06:05:09 -0700 (PDT)
> To: r-help at r-project.org
> Subject: [R] barplot - easy for experienced, difficult for me
> 
> hey guys,
> 
> I wanna make a simple barplot, looking like this excel graph:
> <http://r.789695.n4.nabble.com/file/n4677251/barplot_invertebrates.jpg>
> 
> my data set includes 9 groups of invertebrates (x-axes) and total number
> (y-axes) from two different parks (1 and 2).
> 
> my data-set looks like that:
> 
> <http://r.789695.n4.nabble.com/file/n4677251/barplot_invertebrates.jpg>
> 
> I'm a bloody beginner and happy for your help.
> 
> ps: if you know what other graph could be interesting to make out of this
> very simple data, go ahead and let me know!
>

____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!



More information about the R-help mailing list