0% found this document useful (0 votes)
51 views2 pages

Drawing Lines Between Viewports: Grid - Move.to and Grid - Line.to

This document describes how to draw lines between viewports in the grid graphics system in R. It demonstrates using grid.move.to() and grid.line.to() to draw points and lines across different viewports. This allows drawing across coordinate systems within a single graphic. The code example pushes two viewports, draws points and a line between them to connect the same data point across the different scales.

Uploaded by

Imtiaz N
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)
51 views2 pages

Drawing Lines Between Viewports: Grid - Move.to and Grid - Line.to

This document describes how to draw lines between viewports in the grid graphics system in R. It demonstrates using grid.move.to() and grid.line.to() to draw points and lines across different viewports. This allows drawing across coordinate systems within a single graphic. The code example pushes two viewports, draws points and a line between them to connect the same data point across the different scales.

Uploaded by

Imtiaz N
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

Drawing Lines Between Viewports:

grid.move.to and grid.line.to

Paul Murrell

September 28, 2017

Many graphics systems have the notion of a current drawing location. This has been added
to Grid, with the additional benefit that the drawing location can be specified relative to an
arbitrary viewport. This allows drawing across coordinate systems1 .
The following code demonstrates a simple example (the output is given after the code).

> pushViewport(
+ viewport(w = 0.8, h = 0.8,
+ layout = grid.layout(1, 3,
+ widths = unit(rep(1, 3),
+ c("null", "inches", "null")))))
> pushViewport(viewport(layout.pos.col = 1, yscale = c(0, 4)))
> grid.grill(); grid.yaxis(); grid.xaxis()
> grid.points(0.5, unit(2, "native"))
> grid.move.to(0.5, unit(2,"native"))
> popViewport()
> pushViewport(viewport(layout.pos.col = 3, yscale = c(0, 2)))
> grid.grill(); grid.yaxis(); grid.xaxis()
> grid.points(0.5, unit(2, "native"))
> grid.line.to(0.5, unit(2,"native"))
1 There was a request on R-help for exactly this sort of thing - I will try to find the exact reference - and

there has since been another (From: Ross Darnell; Subject: Problems with segments and multiple graphs).

1
4 2 ●

3 1.5

2 ● 1

1 0.5

0 0
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1

You might also like