Skip to content
Prev 205932 / 398506 Next

Plotting numeric values against non numeric items

Dennis and Sam,

Re Dennis' lattice plot:
Here's how you can superpose lines and points in the key.
simpleKey() is not flexible enough, so we use the key list directly.

dissolve <- data.frame(
           Method = rep(c('No Stir', 'Stir'), each = 2),
           Type = rep(c('Cube', 'Granules'), 2),
           Time = c(686.36, 398.32, 179.17, 60.29))

library(lattice)
xyplot(Time ~ Method, data = dissolve, groups = Type,
        col = c('blue', 'red'), pch = c(16, 17), cex = 1.4, lwd = 2,
        ylim = c(0, 800),
        type = 'b',
        panel = function(x, y, ...) {
                        panel.grid(h = 7, v = 0)
                        panel.xyplot(x, y, ...)  },
        key = list(lines = list(col=c('blue','red'),
                                pch=c(16,17), type='b', lwd=2),
                   text = list(c('Cube', 'Granules')),
                   divide = 1,
                   size = 3,
                   space = 'right'),
        scales = list(tck = c(1, 0),
                      x = list(at = c(1, 2),
                          labels = c('No stir', 'Stir')),
                      y = list(at = seq(0, 800, by = 100))),
        main = 'Dissolving time vs. Stirring / No stirring\n
                for sugar cubes and granules',
        ylab = 'Dissolving time (seconds)')

The 'size' and 'divide' arguments to key set the length of
the line and the number of points overlapping it, for which
the default seems to be 3.

Another comment re Dennis' code: the par.settings() line
won't work as given; you need either

   par.settings = simpleTheme(col = c('Blue', 'Red')),

or

   par.settings = list(superpose.line = list(col = c('Blue', 'Red')),
                       superpose.symbol = list(col = c('Blue', 'Red'))),

but neither is needed.

  -Peter Ehlers
Dennis Murphy wrote: