Try using the subplot function from the TeachingDemos package. Hope this helps,
-- 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-boun...@r- > project.org] On Behalf Of dxc13 > Sent: Wednesday, May 13, 2009 12:06 PM > To: r-help@r-project.org > Subject: [R] Overlaying two plots > > > Hi useR's, > > I want to overlay an image plot over a world map and I can do it, but > just > not the way I need to do it. Here is the code I am using (with data > file > attached) to create my baseline map: > library(sp) > load("TM_WORLD_BORDERS_SIMPL-0.2.RData") > par(bty="l") > plot(wrld_simpl, axes = TRUE, ylim = c(-90, 90), xlim=c(-180, 180), > asp=1.5) > lim <- par("usr") > abline(v=-180, h=90, col="red") #Image plot needs to be inside this > square# > abline(v=180, h=-90, col="red") > > The last two statements create a square on the map between the latitude > and > longitude limits of the world. I want to place the following image > plot > (data matrix attached) inside that square region and then overlay the > world > map again. When I use the following code, the image plot takes up the > whole > plot screen and is not within the square region and thus when I overlay > the > world map, the coordinates will be off. > > df <- as.matrix(read.table("kz_time1.txt", header=F)) > dff <- apply(df, 2, rev) > image(t(dff), xlab="", ylab="", axes=FALSE) > > par(new=TRUE) > plot(wrld_simpl, axes = TRUE, ylim = c(-90, 90), xlim=c(-180, 180), asp > = > 1.5, xlab="Longitude", ylab="Latitude") > abline(v=-180, h=90, col="red") > abline(v=180, h=-90, col="red") > > Can anyone help? > Thanks in advance. > dxc13 > > http://www.nabble.com/file/p23526662/TM_WORLD_BORDERS_SIMPL-0.2.RData > TM_WORLD_BORDERS_SIMPL-0.2.RData > http://www.nabble.com/file/p23526662/kz_time1.txt kz_time1.txt > -- > View this message in context: http://www.nabble.com/Overlaying-two- > plots-tp23526662p23526662.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.