I use the language R for all of my statistical analyses and also for making figures. This is a little example of what goes into making a nice looking presentation of data in R. Making figures in R is a mostly fun, sometime frustrating, but ultimately rewarding. It is neat to code out a bonkers mass of characters and then out comes a beautiful figure. I just started using a fancy package, ggplot2. With ggplots you can create “themes” which change the look of the figures. So here is the code for a figure using the default themes and the resulting figure:
plot = ggplot(nn, aes(x=year, y=MPD, colour=fencing)) + geom_errorbar(aes(ymin= MPD-se, ymax=MPD+se), width=.1) + geom_line() + geom_point()
I didn’t much like the colors, the background with grid lines and the small axes labels. But everything can be changed, it just takes a lot of time to figure out the right code to make the changes you want. So here is the code for my improved figure:
plot= ggplot(nn90, aes(x=year, y=MPD)) + geom_errorbar(aes(ymin=MPD-se, ymax=MPD+se), width=.05) + geom_line(size=1,aes(linetype= fencing,color=fencing)) + geom_point(size=3,aes(shape=fencing))
ng1 = theme(panel.background = element_rect(fill = “white”,colour = “white”), panel.grid.major = element_line(colour = NA), axis.line = element_line(size = 1.2, colour=”black”), axis.ticks=element_line(color=”black”), axis.text=element_text(color=”black”,size=15), axis.title=element_text(color=”black”,size=20), panel.grid.minor = element_line(colour = NA), legend.position = “top”, legend.direction=”horizontal”, legend.text = element_text(size=20), legend.key = element_rect(fill = “white”), legend.title = element_blank(),legend.key.size = unit(1.5, “cm”))
plot + scale_x_continuous(breaks =(seq(min(nn90$year),max(nn90$year),by=2))) + scale_colour_manual(values= c(“black”,”black”))+ xlab(“Year”) +ylab(“Mean Parwise Distance ± SE”) + ng1
I think it looks a lot nicer. I won’t go into trying to explain what all the different bits of the code do, but the part that is “ng1=theme(…” is the theme. That is the main part that is responsible for the change in appearance. For any ggplot users feel free to use the theme.
So that is what a day of fiddling around in R will get you. Now I am one step closer to presenting these results at a conference next week. (I will explain what these results actually mean later :)