diff --git a/R/PlotEquiMap.R b/R/PlotEquiMap.R index 37847dcc40166713a346b3859c38a75f85699fcc..cf0442fcd2374a4b565a0676965cfeb3629aac5f 100644 --- a/R/PlotEquiMap.R +++ b/R/PlotEquiMap.R @@ -695,8 +695,23 @@ PlotEquiMap <- function(var, lon, lat, varu = NULL, varv = NULL, par(userArgs) par(mar = margins, cex.main = cex_title, cex.axis = cex_axes_labels, mgp = c(0, spaceticklab, 0), las = 0) - plot.window(xlim = range(lonb$x, finite = TRUE), ylim = range(latb$x, finite = TRUE), - xaxs = 'i', yaxs = 'i') + + #NOTE: Here creates the window for later plot. If 'usr' for par() is not specified, + # use the lat/lon as the borders. If 'usr' is specified, use the assigned values. + if (is.null(userArgs$usr)) { + #NOTE: The grids are assumed to be equally spaced + xlim_cal <- c(lonb$x[1] - (lonb$x[2] - lonb$x[1]) / 2, + lonb$x[length(lonb$x)] + (lonb$x[2] - lonb$x[1]) / 2) + ylim_cal <- c(latb$x[1] - (latb$x[2] - latb$x[1]) / 2, + latb$x[length(latb$x)] + (latb$x[2] - latb$x[1]) / 2) + plot.window(xlim = xlim_cal, ylim = ylim_cal, xaxs = 'i', yaxs = 'i') +# Below is Old code. The border grids are only half plotted. +# plot.window(xlim = range(lonb$x, finite = TRUE), ylim = range(latb$x, finite = TRUE), +# xaxs = 'i', yaxs = 'i') + } else { + plot.window(xlim = par("usr")[1:2], ylim = par("usr")[3:4], xaxs = 'i', yaxs = 'i') + } + if (axelab) { axis(2, at = ypos, labels = ylabs, cex.axis = cex_axes_labels, tcl = cex_axes_ticks, mgp = c(0, spaceticklab + 0.2, 0)) @@ -740,8 +755,18 @@ PlotEquiMap <- function(var, lon, lat, varu = NULL, varv = NULL, # # Plotting continents # ~~~~~~~~~~~~~~~~~~~~~ - # - coast <- map(continents, interior = FALSE, wrap = TRUE, + # + # maps::map has the global map range [0, 360] or [-180, 180]. + # Set xlim so lon = 0 won't show a straight line when lon = [0, 359]. + # NOTE: It works except Antartic area. Don't know why. ylim is also set + # but it doesn't work. + if (continents == 'world') { # [-180, 180] + xlim_conti <- c(-179.99, 179.99) + } else { # [0, 360] + xlim_conti <- c(0.01, 359.99) + } + coast <- map(continents, interior = FALSE, wrap = TRUE, + xlim = xlim_conti, ylim = c(-89.99, 89.99), fill = filled.continents, add = TRUE, plot = FALSE) if (filled.continents) { old_lwd <- par('lwd')