[R] allowing line wrap for long strip text in xyplot (lattice)

Deepayan Sarkar deepayan.sarkar at gmail.com
Tue Aug 25 23:07:23 CEST 2009

On Mon, Aug 24, 2009 at 8:04 PM, Donald Boyd<boydd at hughes.net> wrote:
> Hi. Am brand new to R and to mailing lists - have never posted anywhere
> before, so hope I do this right.
> Am using R 2.9.1 with lattice graphics (just installed, fully up to date).
> Am doing trellis xyplot with y (emp=employment), x (yearmo=a time measure)
> and conditioning variable (indf - factor describing industry) -- i.e., (emp
> ~ yearmo | indf), where all three variables are in a dataframe. The
> conditioning variable is a factor with a long text description (e.g.,
> "Offices of bank holding companies and of other holding companies
> (60551112)" constructed from a much-less-descriptive industry code - in this
> case, 60551112). That long text goes into the strip text above each panel.
> With default settings the text for many of the factor levels is too long for
> the strip area and I simply see some of it but not all of it. I would like
> to be able to see the full text description, which means I would like to
> allow it to wrap over several lines in the strip area - say 2 or 3 lines.
> Note that the text itself does NOT have any embedded line-wrap characters
> (\n) and I would like to avoid writing something to guess where to insert
> them into each of more than 1,000 levels of the factor. I suspect that
> xyplot, perhaps through par.strip.text, has some simple way of allowing it
> to do intelligent line wrap. I have searched high and low, but have not
> figured this out:
> - I have read the lattice documentation but haven't quite figured out from
> that what I should do
> - I have tried using lines=2 in par.strip.text and lineheight=2 but the
> former appears to change the height of the strip area without forcing line
> wrap, and the latter as I understand it controls spacing between lines
> - I have tried workarounds like using cex=0.2 in par.strip.text to make the
> text really small, but it gets hard to read; and I have tried
> abbreviate=TRUE in par.strip.text but I would rather have full titles
> I am sure there is a really simple solution to this but I can't figure it
> out. If anyone could tell me how I can get long strip titles in xyplot to
> wrap lines (without inserting "\n"s in them) I would appreciate it greatly.

Lattice has no facilities for automatic wrapping. However,

1. see ?strwrap to get your strings broken, and ?paste to join them with "\n"-s.

2. You will need to manually find a suitable 'width' for the strwrap
call, depending on your device size and layout

3. You will also need to use lines= in par.strip.text, but you should
be able to figure out the appropriate value from the results of


More information about the R-help mailing list