old.par <- par(no.readonly=TRUE)
par(mfrow=c(2,2),xpd=NA)
# generate some sample data
tmp.x <- rnorm(25, 10, 2)
tmp.y <- rnorm(25, 50, 10)
tmp.z <- rnorm(25, 0, 1)
plot( tmp.x, tmp.y)
# draw a diagonal line across the plot area
tmp1 <- cnvrt.coords( c(0,1), c(0,1), input='plt' )
lines(tmp1$usr, col='blue')
# draw a diagonal line accross figure region
tmp2 <- cnvrt.coords( c(0,1), c(1,0), input='fig')
lines(tmp2$usr, col='red')
# save coordinate of point 1 and y value near top of plot for future plots
tmp.point1 <- cnvrt.coords(tmp.x[1], tmp.y[1])
tmp.range1 <- cnvrt.coords(NA, 0.98, input='plt')
# make a second plot and draw a line linking point 1 in each plot
plot(tmp.y, tmp.z)
tmp.point2 <- cnvrt.coords( tmp.point1$dev, input='dev' )
arrows( tmp.y[1], tmp.z[1], tmp.point2$usr$x, tmp.point2$usr$y,
col='green')
# draw another plot and add rectangle showing same range in 2 plots
plot(tmp.x, tmp.z)
tmp.range2 <- cnvrt.coords(NA, 0.02, input='plt')
tmp.range3 <- cnvrt.coords(NA, tmp.range1$dev$y, input='dev')
rect( 9, tmp.range2$usr$y, 11, tmp.range3$usr$y, border='yellow')
# put a label just to the right of the plot and
# near the top of the figure region.
text( cnvrt.coords(1.05, NA, input='plt')$usr$x,
cnvrt.coords(NA, 0.75, input='fig')$usr$y,
"Label", adj=0)
par(mfrow=c(1,1))
## create a subplot within another plot (see also subplot)
plot(1:10, 1:10)
tmp <- cnvrt.coords( c( 1, 4, 6, 9), c(6, 9, 1, 4) )
par(plt = c(tmp$dev$x[1:2], tmp$dev$y[1:2]), new=TRUE)
hist(rnorm(100))
par(fig = c(tmp$dev$x[3:4], tmp$dev$y[3:4]), new=TRUE)
hist(rnorm(100))
par(old.par)
Run the code above in your browser using DataLab