From 81974a40115f4b25e8c893c6e8506c867b7607bf Mon Sep 17 00:00:00 2001 From: aho Date: Mon, 26 Apr 2021 17:22:42 +0200 Subject: [PATCH 1/2] Use 'usr' in par() as the borders. --- R/PlotEquiMap.R | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/R/PlotEquiMap.R b/R/PlotEquiMap.R index 37847dc..5b60c30 100644 --- a/R/PlotEquiMap.R +++ b/R/PlotEquiMap.R @@ -695,8 +695,16 @@ 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)) { + 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)) -- GitLab From 39f3e5b231fb461c37d84f04df8ad2e1db7ae179 Mon Sep 17 00:00:00 2001 From: aho Date: Fri, 30 Apr 2021 17:23:27 +0200 Subject: [PATCH 2/2] Caclulate the correct border; add 'xlim' in map() to avoid border line of map --- R/PlotEquiMap.R | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/R/PlotEquiMap.R b/R/PlotEquiMap.R index 5b60c30..cf0442f 100644 --- a/R/PlotEquiMap.R +++ b/R/PlotEquiMap.R @@ -698,9 +698,16 @@ PlotEquiMap <- function(var, lon, lat, varu = NULL, varv = NULL, #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)) { - plot.window(xlim = range(lonb$x, finite = TRUE), ylim = range(latb$x, finite = TRUE), - xaxs = 'i', yaxs = 'i') + 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') } @@ -748,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') -- GitLab