Skip to content

Commit

Permalink
fixes #1241
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Aug 26, 2023
1 parent e9a3f37 commit dcb6085
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
18 changes: 10 additions & 8 deletions R/panel.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

setMethod("panel", signature(x="SpatRaster"),
function(x, main, loc.main="topleft", nc, nr, maxnl=16, maxcell=500000,
box=FALSE, pax=list(), plg=list(), ...) {
box=FALSE, pax=list(), plg=list(), range=NULL, ...) {

dots <- list(...)
if (!is.null(dots$type)) {
Expand Down Expand Up @@ -67,13 +67,15 @@ setMethod("panel", signature(x="SpatRaster"),
bottom <- c(0,1)[b]

if (!categorical) {
if (all(hasMinMax(x))) {
rng <- range(minmax(x, FALSE))
} else {
x <- spatSample(x, maxcell, method="regular", as.raster=TRUE, warn=FALSE)
rng <- range(minmax(x, TRUE))
if (is.null(range)) {
if (all(hasMinMax(x))) {
range <- range(minmax(x, FALSE))
} else {
x <- spatSample(x, maxcell, method="regular", as.raster=TRUE, warn=FALSE)
range <- range(minmax(x, TRUE))
}
}
if (diff(rng) > 0) {
if (diff(range) > 0) {
ptype <- "continuous"
} else {
ptype <- "classes"
Expand All @@ -90,7 +92,7 @@ setMethod("panel", signature(x="SpatRaster"),
plot(y, 1, main=main[i], mar=mar, legend=legend[i], pax=pax, box=box,
loc.main=loc.main, plg=plg, type="classes", ...)
} else {
plot(x, i, main=main[i], mar=mar, legend=legend[i], range=rng, pax=pax, box=box,
plot(x, i, main=main[i], mar=mar, legend=legend[i], range=range, pax=pax, box=box,
loc.main=loc.main, plg=plg, type=ptype, ...)
}
}
Expand Down
3 changes: 2 additions & 1 deletion man/panel.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Show multiple maps that share a single legend.

\usage{
\S4method{panel}{SpatRaster}(x, main, loc.main="topleft", nc, nr, maxnl=16,
maxcell=500000, box=FALSE, pax=list(), plg=list(), ...)
maxcell=500000, box=FALSE, pax=list(), plg=list(), range=NULL, ...)
}

\arguments{
Expand All @@ -27,6 +27,7 @@ Show multiple maps that share a single legend.
\item{box}{logical. Should a box be drawn around the map?}
\item{plg}{see \code{\link{plot}}}
\item{pax}{see \code{\link{plot}}}
\item{range}{numeric. minimum and maximum values to be used for the continuous legend }
\item{...}{arguments passed to \code{plot("SpatRaster", "numeric")} and additional graphical arguments}
}

Expand Down

0 comments on commit dcb6085

Please sign in to comment.