Plotting graphs with R

This morning I spent 3 hours, from 8am to 11am, trying to force R into plotting beautiful graphs. To increase the challenge I do all my R work through rpy, since the R command-line drives me crazy. Problems, solutions and lessons learner were as follows (if you've never used R this will look like gibberish):

  • To get square line ends you have to the the lend parameter using par BEFORE you call plot.

  • Getting greek characters and other math notation into labels is rather complicated, and right out goddamn impossible through rpy. In the end I fell back to constructing long R commands as string, then using r(command) to execute them.

  • It is not possible to have diagonal axis labels.

  • At least in my version of R (=2.1.0, 2.4.0 crashes with rpy), the axis command ignores the xaxp set with par when at is not specified. Use axTicks specifying xaxp instead.

In the end I got what I wanted though:

The axis here were generated with:

axis(1,at=c(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0),
labels=c(expression(paste("Aleph")),
expression(paste("KNN ")),
expression(paste("KNN ", gamma, "1")),
expression(paste("KNN ", gamma, "2")),
expression(paste("SLIPPER")),
expression(paste("SLIPPER ", gamma, "1")),
expression(paste("SLIPPER ", gamma, "2"))),las=3, srt=90)

Sub-scripting the number after gamma should also be possible, but I gave up.

Oh and before you say: "why didn't you just use excel/openoffice" – Because where would the wonderful vector-based PDF antialiases goodness be then?

Post a comment.