Here is a way to do it using just base graphics: layout(matrix(c(1,1,2,3), 2, 2, byrow = TRUE)) plot(runif(10), type='b', ylim=c(0,1)) x.tmp <- grconvertX(4, to='ndc') y.tmp <- grconvertY(0.9, to='ndc') plot(runif(20), type='l', ylim=c(0,1)) par(xpd=NA) segments( 10, 1, grconvertX(x.tmp, from='ndc'), grconvertY(y.tmp, from='ndc'), col='red' ) plot(runif(20), type='l')
-- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Paul Murrell > Sent: Wednesday, March 30, 2011 4:29 PM > To: Mario Valle > Cc: R-help@r-project.org > Subject: Re: [R] How to put line linking two plots > > 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 > p...@stat.auckland.ac.nz > http://www.stat.auckland.ac.nz/~paul/ > > ______________________________________________ > 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. ______________________________________________ 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.