Skip to content
Prev 300115 / 398506 Next

Side by side strip charts

On 2012-07-13 11:37, Rui Barradas wrote:
It seemed like a good exercise to try to imitate the plot
posted by the OP (on Nabble) a bit more closely; so here's
my attempt:

   ## x-axis values to print
   myat <- seq(55, 75, 5)

   ## adjust plot margins to accommodate side 4 labels
   par(mar = c(4,2,2,6), oma = rep(1,4))

   ## do the plot without axes or frame
   stripchart(list(sample1=x1,sample2=x2,sample3=x3),
               method = "stack",
               pch = 4,
               offset = 1/2,
               col = "blue",
               lwd = 2,
               xlim = c(53, 77),
               axes = FALSE)

   ## add the axes; tcl=-0.5 is the default; not really needed
   axis(1, at = myat, tcl = -0.5)
   axis(1, at = myat, pos = 1.90, tcl = -0.5)
   axis(1, at = myat, pos = 2.90, tcl = -0.5)

   ## reprint the axes without labels; ticks are upward
   axis(1, at = myat, labels = NA, tcl = 0.5)
   axis(1, at = myat, labels = NA, pos = 1.90, tcl = 0.5)
   axis(1, at = myat, labels = NA, pos = 2.90, tcl = 0.5)

   ## do the right-side axis, labels only
   axis(4, at = (1:3)-0.1,
        labels = paste("Sample",1:3), las = 1, lwd = 0)

   ## extend horizontal axis lines
   abline(h = (1:3)-0.1, lwd = 2)

   ## add the frame; it's in a bit from the outer edges
   ## due to the 'oma=' par setting
   box("figure")

Peter Ehlers