[R] Alternate tick labels in xyplot

David Winsemius dwinsemius at comcast.net
Thu Feb 14 22:31:05 CET 2013


On Feb 14, 2013, at 10:52 AM, Lisa Daniel wrote:

> Dear Rhelp,
> I was able to solve the tick labels part.  If somebody can help me in creating title for each row of figures above the individual headings, it will be great.

I think you need to be looking at grid.text() in package grid.

> library(grid)
> library(lattice)
> xy <-xyplot(decrease ~ treatment, OrchardSprays,
>     main= "Some plot",
>         groups = rowpos, type = "a",
>     scales=list(x=list(at=seq(1,8,1),labels=c('A','','C','','E','','G',''))),
>                 page     = function(n){
>                          grid.text(LETTERS[j],
>                          y = 0.95,
>                          x = 0.15,
>                          default.units = "npc",
>                          just = c("left"),
>                          gp = gpar(fontsize = 12,fontface="bold") )
>                        },
>     par.settings = c(simpleTheme(lty=1:8, col="black",lwd=2),list(axis.components=list(bottom=list(tck=c(0,1))),layout.heights = list(main = 1.2,
>                        sub  = 0,
>                        axis.top = 0.2,
>                        top.padding  = 0.1,
>                        bottom.padding = 0)) ),
>         auto.key = list(x = 0.2, y = 0.9,
>         cex = 0.75, points = FALSE, lines = TRUE)) 
> j=1
> print(xy, pos = c(0.0, 0.5, 0.33, 1.0), more = TRUE)
> j=j+1
> print(xy, pos = c(0.33, 0.5, 0.66, 1.0), more = TRUE)
> j=j+1
> print(xy, pos = c(0.66, 0.5, 0.99, 1.0), more = TRUE)
> j=j+1
> print(xy, pos = c(0.0, 0.0, 0.33, 0.5), more = TRUE)
> j=j+1
> print(xy, pos = c(0.33, 0.0, 0.66, 0.5), more = TRUE)
> j=j+1
> print(xy, pos = c(0.66, 0.0, 0.99, 0.5), more = FALSE)
> 
> Many thanks,
> Lisa
> 
> 
> 
> 
> ----- Original Message -----
> From: Lisa Daniel <lisadaniel2013 at yahoo.com>
> To: "r-help at r-project.org" <r-help at r-project.org>
> Cc: 
> Sent: Thursday, February 14, 2013 12:14 PM
> Subject: Alternate tick labels in xyplot
> 
> Dear Rhelp,
> 
> I would like to get alternate tick labels for the xyplot:
> library(lattice)
> library(grid)
> 
> xy <-xyplot(decrease ~ treatment, OrchardSprays,
>     main= "Some plot",
>         groups = rowpos, type = "a",
>                 page     = function(n){
>                          grid.text(LETTERS[j],
>                          y = 0.95,
>                          x = 0.15,
>                          default.units = "npc",
>                          just = c("left"),
>                          gp = gpar(fontsize = 12,fontface="bold") )
>                        },
>     par.settings = c(simpleTheme(lty=1:8, col="black",lwd=2),list(layout.heights = list(main = 1.2,
>                        sub  = 0,
>                        axis.top = 0.2,
>                        top.padding  = 0.1,
>                        bottom.padding = 0)) ),
>         auto.key = list(x = 0.2, y = 0.9,
>         cex = 0.75, points = FALSE, lines = TRUE)) 
> j=1
> print(xy, pos = c(0.0, 0.5, 0.33, 1.0), more = TRUE)
> j=j+1
> print(xy, pos = c(0.33, 0.5, 0.66, 1.0), more = TRUE)
> j=j+1
> print(xy, pos = c(0.66, 0.5, 0.99, 1.0), more = TRUE)
> j=j+1
> print(xy, pos = c(0.0, 0.0, 0.33, 0.5), more = TRUE)
> j=j+1
> print(xy, pos = c(0.33, 0.0, 0.66, 0.5), more = TRUE)
> j=j+1
> print(xy, pos = c(0.66, 0.0, 0.99, 0.5), more = FALSE)
> 
> 
> similar to the x-axis in the code below, but somehow it is not working when I pasted 'list(axis.components=...) in the above code:
> xyplot(rnorm(12) ~ 1:12 , type="l",
> scales=list(x=list(at=seq(2,12,2),labels=c(1, ' ', 3 , ' ' , 5 , ' ' ))),
> par.settings=list(axis.components=list(bottom=list(tck=c(0,1))))) 
> 
> scales=list(x=list(at=seq(1,8,1),labels=c('A', ' ', 'C', ' ' ,'E' , ' ','G',' '))),
> 
> If possible, I would like a heading for each rows (justified to center) above the individual heading.
> 
> Please help.
> Many thanks,
> Lisa.
> 
> 
> ______________________________________________
> R-help at r-project.org mailing list
> 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