[R] [solved!] Re: [lattice] format and rotation of strip text

David Winsemius dwinsemius at comcast.net
Tue Nov 20 20:44:59 CET 2012


On Nov 20, 2012, at 10:24 AM, Tom Roche wrote:

> 
> https://stat.ethz.ch/pipermail/r-help/2012-November/329509.html
>>> -  without the line above commented out, strip values are (correctly)
>                                typo, should be "incorrectly" ^^^^^^^^^
>>>   all 1.123
> 
>>> +  with the line above commented out, strip values are (correctly)
>>>   1.123 .. 5.123
> 
>>> how to round() or signif() the values obtained from array.3d.df$lev
>>> and displayed in the strips?
> 
> https://stat.ethz.ch/pipermail/r-help/2012-November/329512.html
>> [omitted] seems to be a better result:
> 
> Indeed! The complete sequence that Worked For Me is
> 
> # start example
> library(reshape2)
> library(lattice)
> 
> lon=11
> lat=7
> lev=5
> len=lon*lat*lev
> array.3d <- array(data=c(1:len), dim=c(lat, lon, lev))
> 
> # Rewrite the array values "more spatially," i.e., row-wise from
> # bottom left. If there's a more-R-ish way to fill this array as
> # desired, please let me know: I know 'for' loops are deprecated
> # in R.
> 
> i=1
> for (z in 1:lev) {
>  for (x in lat:1) {
>    for (y in 1:lon) {
>      array.3d[x,y,z]=i ; i=i+1
>    }
>  }
> }
> 
> # produces (with rows=latitudes and cols=longitudes)
> array.3d[,,1]
> array.3d[,,lev]
> 
> # convert data=array.3d to dataframe with reshape2::melt
> array.3d.df <- melt(array.3d, varnames=c("lat","lon","lev"), value.name="conc")
> head(array.3d.df)
> tail(array.3d.df)
> 
> # make level values {longer, "more realistic"}
> 
> array.3d.df$lev <- array.3d.df$lev + 0.12345 # truncated below, and ...
> # ... below note output from these
> head(array.3d.df)
> tail(array.3d.df)
> 
> # plot "appropriately" for atmospheric data where lev=pressure: use
> # * lattice::levelplot
> # * one column, since atmospheric levels stack vertically
> # * rev(lev), since layers closer to ground level have higher pressure
> 
> levelplot(
>  conc ~ lon * lat | rev(lev), data=array.3d.df, layout=c(1,lev),
>  levs=as.character(round(array.3d.df[['lev']], 1)),
>  strip=FALSE,
>  strip.left=strip.custom(
>    factor.levels=as.character(signif(unique(array.3d.df[['lev']]), 3)),
>    strip.levels=TRUE,
>    horizontal=TRUE,
>    strip.names=FALSE,
>    # gotta shrink strip text size to fit strip width:
>    # more on that separately
>    par.strip.text=list(cex=0.5)
>  )
> )
> # end example

If you wanted to make the side strips wider, rather than making the print tiny enough to fit in horizontally, ISTR there are examples of the code to do that in the latticeExtra package. I believe it's in useOuterStrips.

-- 
David.


> 
> If there's a lattice wiki or other way to user-contribute visualization
> documentation, please lemme know. (For that matter, why is there not
> something like an r-sig-vis?)

There is an R wiki. It has some useful stuff on Excel import/export issues that is frequently cited on rhelp: http://rwiki.sciviews.org/doku.php?id=tips:data-io:ms_windows

 I never succeeded in my efforts a couple of years ago at getting registered with enough authority to make contributions, but maybe your experience could be different. At the moment the lattice section looks to either be a stem or something with broken code, at least when viewed by Firefox on a Mac. There was a SIG-wiki but the last posting in the archives is 2 years ago.

> 
> Your assistance is appreciated! Hoping this will be useful to others,
> Tom Roche <Tom_Roche at pobox.com>

David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list