Monday: openfisheries & ggplot

Andrew has put together the pre­lim­i­nary API for the openfisheries.org project. I’ve begun an R pack­age, rfish­eries, to inter­face to the open­fish­eries project. It would be great to incor­po­rate data from the RAM Legacy data­base and the seaaroundus.org project, which may be done at the level of the R pack­age or (per­haps more flex­i­bly) directly through the devel­op­ing open­fish­eries API.

Here’s a quick proof-of-principle exam­ple for Andrew’s API:

(Code linked from image as usual).

ggplot2

Look­ing into switch­ing my graph­ics into ggplot.

For instance, above graph is made by:

dat <- data.frame(year = global$year, global = as.numeric(global$data),
usa=as.numeric(usa$data))
dat2 <- melt(dat, id="year")
ggplot(dat2, aes(year, value, fill=variable)) + geom_area()

Note that data has to be in “long” form, accom­plished by “melt” function.

Pri­mary dis­ad­van­tages are (a) me hav­ing to learn a new syn­tax (b) users of my pack­age hav­ing to learn a new syn­tax. (a) is some­thing I can get over, (b) is some­thing I can largely avoid by keep­ing plot­ting rou­tines and data rou­tines sep­a­rate enough, though it’s more a prob­lem in build­ing on other’s plot­ting rou­tines or hav­ing other devel­op­ers extend mine. (I’m sure Hadley would argue that it would in fact be eas­ier, not harder, thanks to the gram­mar, so there’s that side too).  Any­way, non-trivial step when you real­ize you ‘re start­ing off unable to even cre­ate a plot.

Col­lat­ing ref­er­ences as a start­ing point.  Prob­a­bly noth­ing bet­ter than the deep end: read­ing throught ggplot2 book, since get­ting a han­dle on the phi­los­o­phy of the gram­mar of graph­ics seems ulti­mately more use­ful than get­ting exam­ples that run.

 

Con­tin­ued notes

still writ­ing today’s notes… check back

No related posts.