Hi Paul,

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))

Thank you very much for the detailed explanation. I was trying
to find the grid equivalent of the following base graphics code

atPositions <- axis(2, labels = FALSE)
axis(2, at = atPositions, labels = 10^atPositions)

i.e. use the 'at' to make appropriate labels. I guess there is
no way to do this without passing a (self-made) 'at' to grid.xaxis
in the first place as in

library(grid)
pushViewport(plotViewport(c(5,4,4,2)))
set.seed(120)
xData <- rpois(5, 12)
yData <- rpois(5, 12)
pushViewport(dataViewport(xData, yData))
grid.points(xData, yData)
atPositions <- grid.pretty(current.viewport()$xscale)
grid.xaxis(name = "xa", at = atPositions, label = 10^atPositions)

Thanks again,
Tobias

P.S. Maybe the above could be used to populate the
\examples{} section of grid.pretty ?

### 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"))

______________________________________________
R-help@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.

Reply via email to