[R] childNames for xaxis grob (grid package)

Paul Murrell p.murrell at auckland.ac.nz
Thu Jul 10 04:39:58 CEST 2008


Hi


Tobias Verbeke wrote:
> Dear list,
> 
> Can someone explain why the childNames below
> gives
> 
> character(0)
> 
> instead of the (canonical) names of the children grobs
> of the xaxis gTree ?
> 
> [1] "major"  "ticks"  "labels"


The problem is that you xaxis has an 'at' component of NULL, which means
that the axis calculates its tick marks on-the-fly when it comes time to
draw (it has to ask the current viewport what the current scale is).

This means that there are no grobs representing the major, ticks, and
labels stored with the xaxis grob on the display list.  These are
generated just to draw then thrown away.

If you want to modify the look of the grobs that are drawn (then thrown
away), you can use the 'edits' component of the xaxis.  This provides an
edit that will be applied whenever the children are created for drawing.

Simple example (assuming your code below has been run) ...

 grid.edit("xa", edits=gEdit("labels", rot=45))


Paul




> Many thanks in advance,
> Tobias
> 
> ### minimal example code ###
> 
> library(grid)
> pushViewport(plotViewport(c(5,4,4,2)))
> pushViewport(dataViewport(1:5, 1:5))
> grid.points(1:5, 1:5)
> grid.xaxis(name = "xa")
> grid.get("xa")
> childNames(grid.get("xa"))
> 
> ### sessionInfo() ###
> 
>  > sessionInfo()
> R version 2.7.1 (2008-06-23)
> i486-pc-linux-gnu
> 
> locale:
> en_US.UTF-8
> 
> attached base packages:
> [1] grid      stats     graphics  grDevices utils     datasets  methods
> [8] base
> 
> ______________________________________________
> 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.

-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/



More information about the R-help mailing list