Mark Coletti
2008-Apr-20 20:11 UTC
[R] Attempting to sync x-axis labels with grid lines in lattice bwplot
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
Deepayan Sarkar
2008-Apr-21 22:31 UTC
[R] Attempting to sync x-axis labels with grid lines in lattice bwplot
On 4/20/08, Mark Coletti <mcoletti at gmail.com> wrote:> 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.A factor such as Gen here would get converted to numeric values using as.numeric() before plotting, so you can infer the 'at' values from that. In other words, the level "0" gets plotted as 1, "10" as 2, and so on. -Deepayan