[R] Adjusting axis labels on lattice xyplot

David Winsemius dwinsemius at comcast.net
Sat Oct 15 00:28:41 CEST 2016


> On Oct 14, 2016, at 12:03 PM, Rich Shepard <rshepard at appl-ecosys.com> wrote:
> 
>  I've read chapters 7 and 8 in the Lattice book and do not see how to thin
> labels on the x and y axes of an xyplot(), and how to rotate the dates on
> the x axis for easier reading (rot did not do the job for me.)
> 
>  The data (as raindata.dat) and the existing plot (as precip.pdf) are
> attached.

The structure( .. ) call would need to be sourced:

> rain <- source("~/raindata.dat")
> str(rain)
List of 2
 $ value  :'data.frame':	341 obs. of  3 variables:
  ..$ station: Factor w/ 6 levels "0.3E","0.6W",..: 1 1 1 1 1 1 1 1 1 1 ...
  ..$ date   : Factor w/ 62 levels "2013-12-01","2013-12-02",..: 32 33 34 35 36 37 38 39 40 41 ...
  ..$ amount : Factor w/ 48 levels "","0.00","0.01",..: 1 1 3 2 2 2 12 18 34 14 ...
 $ visible: logi TRUE

When you do that you can see the only the first item in the length2 list is likely to be useful:

> str(rain[[1]])
'data.frame':	341 obs. of  3 variables:
 $ station: Factor w/ 6 levels "0.3E","0.6W",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ date   : Factor w/ 62 levels "2013-12-01","2013-12-02",..: 32 33 34 35 36 37 38 39 40 41 ...
 $ amount : Factor w/ 48 levels "","0.00","0.01",..: 1 1 3 2 2 2 12 18 34 14 ...

#So re-assign#

rain <- rain[[1]]

And the date column is a factor. Fortunately the as.Date.factor function doesn't need as.chaacter anymore:

rain$date=as.Date(rain$date)


> 
>  The ploting command used is:
> 
> xyplot(rain$amount ~ rain$date | rain$station, main="Weather Stations",
> xlab="Date", ylab="Amount (inches)", pch=16, col=132)
> 
>  Please point me to the appropriate place in the book where the prepanel
> function to change the axis lable spacing and rotation is discussed.

The place on the ?xyplot help page to look is in the section on `scales`. There's no difficulty using 'rot' as long as it is in the correct place which in this instance is `x` sublist of the `scales` list

xyplot(amount ~ date | station, data=rain, main="Weather Stations",
    xlab="Date", ylab="Amount (inches)", pch=16, col=132, 
    scales=list(y=list(at=0:4), 
                x=list(at=seq(min(rain$date), max(rain$date), by='week'), rot=90) )
      )




> I
> expected it to be in chapter 8. Or, if there's another reference I should
> read, please point me to that.


> 
>  For some reason I've not yet tracked down, there is no longer help
> available within the R session (running in emacs with ESS) when I type, for
> example, ?xyplot. R returns the message that there's no documentation in the
> specified packages and libraries. Obviously something changed since I last
> used R.
> 
> Rich<raindata.dat><precip.pdf>______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list