I am using following codes to plot map
library(sp)
library(rgdal)
library(maps)
library(gplots)
library(clim.pact)
library(fields)
source("/R/PlotGridded2DMap.R")
source("/R/image.plot.fix.R")
source("/R/image.plot.plt.fix.r")
seasonal_plot<-function(input,lonll=-180,latll=-90,lonres=5.,latres=3.75,write_file=TRUE,The_title=NULL){
if(is.null(The_title)){
for (ki in 1:length(input)){
The_title[[ki]]<-sprintf("XCH4 CH4 (ppb)",ki)
}
}
if(!is.list(input)){input=list(input)}
lon.ll <- lonll #lower left corner of grid
lat.ll <- latll #lower left corner of grid
lon.res <- lonres #resolution in degrees longitude
lat.res <- latres #resolution in degrees latitude
for (ki in 1:length(input)){
# plot for whole world
sh<-dim(input[[ki]]$avg)
numpix.x <- sh[1] #number of pixels in x directions in
grid
numpix.y <- sh[2] #number of pixels in y directions in
grid
#print(ki)
#print(input[[ki]]$avg)
mat <- t(input[[ki]]$avg)# length
xs <- seq(lon.ll,by=lon.res,length=dim(mat)[2])+0.5*lon.res
#centers of cells
ys <- seq(lat.ll,by=lat.res,length=dim(mat)[1])+0.5*lat.res
#centers of cells
col=rich.colors(32)
xlims <-c(-180,180)
ylims <-c(-90,90)
old.par <- par(no.readonly = TRUE)
par(mar=c(par()$mar[1:3],4))
cex.set <- 1.2
par(cex=cex.set)
par(mgp=c(2.0,0.3,0))
par(tcl=-0.1)
opath <- ("/Result/scitm3/") # path to save image
if(write_file){png(file=paste(opath,The_title[[ki]],".png",sep="
"),width=1000,height=800,pointsize=23)}
if(!write_file){x11()}
image.plot.fix(x=xs,y=ys,z=input[[ki]]$avg,zlim=c(1600,2000),nlevel=64,col=col,xlab="Longitude",ylab="Latitude",legend.width=0.03,
offset=0.05,legend.only=F,lg=F)
map(database = "world", add=TRUE,col="black")
title(paste(The_title[[ki]]))
if(write_file){dev.off()}
}
}
when I try to use map(database = "world",
add=TRUE,col="black")
I get error
Error in map(database = "world", add = TRUE, col = "black")
:
unused argument(s) (database = "world")
if I comment this line then I get plot but it does not have world border.
I really got stuck at this point and I do not know how to fix it.
--
View this message in context:
http://r.789695.n4.nabble.com/plotting-border-over-map-tp4479163p4479163.html
Sent from the R help mailing list archive at Nabble.com.
On Sat, 17 Mar 2012, uday wrote:> I am using following codes to plot map > > library(sp) > library(rgdal) > library(maps) > library(gplots) > library(clim.pact) > library(fields) > source("/R/PlotGridded2DMap.R") > source("/R/image.plot.fix.R") > source("/R/image.plot.plt.fix.r") > > seasonal_plot<-function(input,lonll=-180,latll=-90,lonres=5.,latres=3.75,wr > ite_file=TRUE,The_title=NULL){ if(is.null(The_title)){ > for (ki in 1:length(input)){ > The_title[[ki]]<-sprintf("XCH4 CH4 (ppb)",ki) > } > } > if(!is.list(input)){input=list(input)} > lon.ll <- lonll #lower left corner of grid > lat.ll <- latll #lower left corner of grid > lon.res <- lonres #resolution in degrees longitude > lat.res <- latres #resolution in degrees latitude > > for (ki in 1:length(input)){ > # plot for whole world > sh<-dim(input[[ki]]$avg) > numpix.x <- sh[1] #number of pixels in x directions in > grid > numpix.y <- sh[2] #number of pixels in y directions in > grid > #print(ki) > #print(input[[ki]]$avg) > mat <- t(input[[ki]]$avg)# length > xs <- seq(lon.ll,by=lon.res,length=dim(mat)[2])+0.5*lon.res > #centers of cells > ys <- seq(lat.ll,by=lat.res,length=dim(mat)[1])+0.5*lat.res > #centers of cells > col=rich.colors(32) > > xlims <-c(-180,180) > ylims <-c(-90,90) > > old.par <- par(no.readonly = TRUE) > par(mar=c(par()$mar[1:3],4)) > cex.set <- 1.2 > par(cex=cex.set) > par(mgp=c(2.0,0.3,0)) > par(tcl=-0.1) > opath <- ("/Result/scitm3/") # path to save image > if(write_file){png(file=paste(opath,The_title[[ki]],".png",sep=" > "),width=1000,height=800,pointsize=23)} > > if(!write_file){x11()} > > image.plot.fix(x=xs,y=ys,z=input[[ki]]$avg,zlim=c(1600,2000),nlevel=64,col> col,xlab="Longitude",ylab="Latitude",legend.width=0.03, > offset=0.05,legend.only=F,lg=F) > > map(database = "world", add=TRUE,col="black") > > title(paste(The_title[[ki]])) > if(write_file){dev.off()} > > } > } > > when I try to use map(database = "world", add=TRUE,col="black") > I get error > Error in map(database = "world", add = TRUE, col = "black") : > unused argument(s) (database = "world") > > if I comment this line then I get plot but it does not have world border. > > I really got stuck at this point and I do not know how to fix it. >Well, you haven't provided a minimal reproducible example, so we can only guess what is in /R/PlotGridded2DMap.R /R/image.plot.fix.R /R/image.plot.plt.fix.r but my guess is you are redefining the map() function in there. HTH, Ray
Hi Ray, Thanks for reply /R/PlotGridded2DMap.R /R/image.plot.fix.R /R/image.plot.plt.fix.r are the functions those I wrote for plotting and they work with another data, but only I have some issue with only the codes those I provided before. and what do you mean by " I am redefining the map() function in there"? -- View this message in context: http://r.789695.n4.nabble.com/plotting-border-over-map-tp4479163p4484009.html Sent from the R help mailing list archive at Nabble.com.