A gPath object specifying a gTree within the current
scene.
x
A gTree object to be modified.
order
A character vector or a numeric vector that specifies
the new drawing order for the children of the gTree. May not refer
to all children of the gTree (see Details).
back
Controls what happens when the order does not
specify all children of the gTree (see Details).
grep
Should the gPath be treated as a regular expression?
redraw
Should the modified scene be redrawn?
Details
In the simplest case, order specifies a new ordering for all of
the children of the gTree. The children may be specified either by
name or by existing numerical order.
If the order does not
specify all children of the gTree then, by default, the children
specified by order are drawn first and then all remaining
children are drawn. If back=FALSE then the children not
specified in order are drawn first, followed by the specified
children. This makes it easy to specify a send-to-back or
bring-to-front reordering. The order argument is always
in back-to-front order.
It is not possible to reorder the grid display list (the top-level
grobs in the current scene) because the display list is a mixture of
grobs and viewports (so it is not clear what reordering even means and
it would be too easy to end up with a scene that would not draw).
If you want to reorder the grid display list, try grid.grab()
to create a gTree and then reorder (and redraw) that gTree.
Value
grid.reorder() is called for its side-effect of modifying the
current scene.
reorderGrob() returns the modified gTree.
Warning
This function may return a gTree that will not draw. For example, a
gTree has two children, A and B (in that order),
and the width of child B depends on the width of child A (e.g., a box
around a piece of text). Switching the order so that B is drawn
before A will not allow B to be drawn. If this happens with
grid.reorder(), the modification will not be performed. If
this happens with reorderGrob() it should be possible simply to
restore the original order.
Author(s)
Paul Murrell
Examples
# gTree with two children, "red-rect" and "blue-rect" (in that order)
gt <- gTree(children=gList(
rectGrob(gp=gpar(col=NA, fill="red"),
width=.8, height=.2, name="red-rect"),
rectGrob(gp=gpar(col=NA, fill="blue"),
width=.2, height=.8, name="blue-rect")),
name="gt")
grid.newpage()
grid.draw(gt)
# Spec entire order as numeric (blue-rect, red-rect)
grid.reorder("gt", 2:1)
# Spec entire order as character
grid.reorder("gt", c("red-rect", "blue-rect"))
# Only spec the one I want behind as character
grid.reorder("gt", "blue-rect")
# Only spec the one I want in front as character
grid.reorder("gt", "blue-rect", back=FALSE)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(grid)
> png(filename="/home/ddbj/snapshot/RGM3/R_rel/result/grid/grid.reorder.Rd_%03d_medium.png", width=480, height=480)
> ### Name: grid.reorder
> ### Title: Reorder the children of a gTree
> ### Aliases: grid.reorder reorderGrob
> ### Keywords: dplot
>
> ### ** Examples
>
> # gTree with two children, "red-rect" and "blue-rect" (in that order)
> gt <- gTree(children=gList(
+ rectGrob(gp=gpar(col=NA, fill="red"),
+ width=.8, height=.2, name="red-rect"),
+ rectGrob(gp=gpar(col=NA, fill="blue"),
+ width=.2, height=.8, name="blue-rect")),
+ name="gt")
> grid.newpage()
> grid.draw(gt)
> # Spec entire order as numeric (blue-rect, red-rect)
> grid.reorder("gt", 2:1)
> # Spec entire order as character
> grid.reorder("gt", c("red-rect", "blue-rect"))
> # Only spec the one I want behind as character
> grid.reorder("gt", "blue-rect")
> # Only spec the one I want in front as character
> grid.reorder("gt", "blue-rect", back=FALSE)
>
>
>
>
>
> dev.off()
null device
1
>