0% found this document useful (0 votes)
21 views

An Example of "Linking" Graphical Objects in Grid: Paul Murrell December 10, 2015

This document discusses linking graphical objects in R to aid in comparison. It shows how to split a page into two viewports for two graphs, name the axis objects the same in each graph, and then edit the axes simultaneously rather than individually. By naming the axis objects like "xaxis" and "yaxis" in both graphs, any changes to those objects will be reflected in both graphs, allowing easy comparison of the two subjects' data.

Uploaded by

rojasleop
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

An Example of "Linking" Graphical Objects in Grid: Paul Murrell December 10, 2015

This document discusses linking graphical objects in R to aid in comparison. It shows how to split a page into two viewports for two graphs, name the axis objects the same in each graph, and then edit the axes simultaneously rather than individually. By naming the axis objects like "xaxis" and "yaxis" in both graphs, any changes to those objects will be reflected in both graphs, allowing easy comparison of the two subjects' data.

Uploaded by

rojasleop
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

An Example of Linking Graphical Objects in

grid

Paul Murrell

December 10, 2015

Suppose that I am drawing two graphs on a page, which are the results from
two subjects in an experiment. I want the graphs to have the same axes to aid
in comparison of the subjects.
First of all, I will split the page up into two bits for the two graphs.

> pushViewport(viewport(layout = grid.layout(1, 2, respect = TRUE)))

Now I generate some data and draw the first plot.

> x <- 1:10


> y1 <- rnorm(10)
> vp1a <- viewport(layout.pos.col = 1)
> vp1b <- viewport(width = 0.6, height = 0.6,
+ xscale = c(0, 11), yscale = c(-4, 4))
> pushViewport(vp1a, vp1b)
> grid.xaxis(name = "xaxis")
> grid.yaxis(name = "yaxis")
> grid.points(x, y1)
> popViewport(2)

Notice that I have named the graphical objects for the axes. When I draw the
second plot I will use the same names for the axis objects.

> y2 <- rnorm(10)


> vp2a <- viewport(layout.pos.col = 2)
> vp2b <- viewport(width = 0.6, height = 0.6,
+ xscale = c(0, 11), yscale = c(-4, 4))
> pushViewport(vp2a, vp2b)
> grid.xaxis
> grid.xaxis(name = "xaxis")
> grid.yaxis(name = "yaxis")
> grid.points(x, y2)
> popViewport(2)

1
The output looks like the figure below.

4 4
2 2


0 0
2 2

4 4
0 2 4 6 8 10 0 2 4 6 8 10

Because I have used the same name for the axis objects in both plots, I can edit
the axes for both plots simultaneously rather than having to edit each one in
turn. For example ...

> grid.edit("xaxis", at = c(1, 5, 9), global = TRUE)


>

The output now looks like the figure below.

4 4
2 2

0


0

2 2
4 4
1 5 9 1 5 9

This might seem a very small gain in this example, but it is potentially of great
use in, for example, the implementation of a scatterplot matrix.

You might also like