[R] Attempting to sync x-axis labels with grid lines in lattice bwplot

Mark Coletti mcoletti at gmail.com
Sun Apr 20 22:11:09 CEST 2008


I have created a lattice bwplot that suffers from axis label
overplotting.  The box plot contains grid lines, and I thought that
only plotting the labels for corresponding vertical grid lines would
not only cure the overplotting but also be more aesthetically
pleasing.  Unfortunately hours of poring over manuals, documentations,
mailing list archives, and other R-related text hasn't helped.

This following is the plot:

http://www.lychnobite.org/images/bsf.png

As you can see, the x axis labels are a mess.  :(

This is the code I used to generate the plot:

bsf.plot = bwplot( fitness ~ Gen | Crossover * Rules,
  data = bsf.df,
  panel = function(...) {
    panel.grid(v = -10, h = -1)
    panel.bwplot(...)

    # cribbed some lines from lattice grid function
    limits <- current.panel.limits()
    print( limits$xlim )

    # maybe add x axis plotting here? ... and suppress it elsewhere?

  },
  subset = Gen %in% filtered.gen,    # mask for plotting only some generations
  par.settings = list(plot.symbol = list(pch = 20)), # dots for outliers
  pch="|",                              # want median lines not dot
  fill="lightgray",                     # gray stands out more
  xlab="Generations",
  main = "Best so far" )

I suspect that I'll have to use "at" within "scale" -- but where to
get the grid line coordinates?  As seen above, I cut-n-pasted some of
the source from "panel.grid", but then realized that there seemed to
be no way to get that information to the "scale/at" parameter.

Does anyone have any tips for correcting this?  I suppose I could cut
down the label font size, but that's a bit of an eye straining kludge.

Cheers!

Mark Coletti



More information about the R-help mailing list