[R] How to put line linking two plots

Paul Murrell p.murrell at auckland.ac.nz
Thu Mar 31 00:28:53 CEST 2011


Hi

On 30/03/2011 10:54 p.m., Mario Valle wrote:
> Hello!
> Suppose I have three charts like below. The top chart is a general
> overview and the bottom charts are related so some point of this chart.
> To make clear this relationship I want to draw a line between (4,0.9) in
> the top chart and (10,1) in the bottom-left one.
> Currently I add it manually using Inkscape on the resulting pdf file.
> Is it possible to add it inside R? Should I switch to other charting
> packages?

You'll have your work cut out using traditional graphics, but this is 
doable in grid-based graphics.  For example, ...

library(grid)
library(lattice)

set.seed(123)
print(xyplot(runif(10)~1:10, type="b"),
	position=c(0, .5, 1, 1),
	prefix="top",
	more=TRUE)
print(xyplot(runif(20)~1:20, type="l"),
	position=c(0, 0, .5, .5),
	prefix="left",
	more=TRUE)
print(xyplot(runif(20)~1:20, type="l"),
	position=c(.5, 0, 1, .5),
	prefix="right")
trellis.focus("panel", 1, 1, prefix="top")
grid.move.to(unit(4, "native"), unit(.9, "native"))
trellis.unfocus()
trellis.focus("panel", 1, 1, prefix="left", clip.off=TRUE)
grid.line.to(unit(10, "native"), unit(1, "native"))
trellis.unfocus()

Paul

> Thanks for the advice!
>                                                   mario
>
> set.seed(123)
> pdf("test.pdf", width=14, height=7)
> layout(matrix(c(1,1,2,3), 2, 2, byrow = TRUE))
> plot(runif(10), type='b')
> plot(runif(20), type='l')
> plot(runif(20), type='l')
> dev.off()
>
> R 2.12.2 on Windows 7 (32bits)
>

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