Skip to content

Commit

Permalink
m
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Jul 19, 2024
1 parent ee9cd94 commit 52f14fb
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 23 deletions.
6 changes: 3 additions & 3 deletions R/plot_raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ prettyNumbs <- function(x, digits) {


setMethod("plot", signature(x="SpatRaster", y="numeric"),
function(x, y=1, col, type=NULL, mar=NULL, legend=TRUE, axes=!add, plg=list(), pax=list(), maxcell=500000, smooth=FALSE, range=NULL, levels=NULL, all_levels=FALSE, breaks=NULL, breakby="eqint", fun=NULL, colNA=NULL, alpha=NULL, sort=FALSE, decreasing=FALSE, grid=FALSE, ext=NULL, reset=FALSE, add=FALSE, buffer=FALSE, background=NULL, box=axes, clip=TRUE, ...) {
function(x, y=1, col, type=NULL, mar=NULL, legend=TRUE, axes=!add, plg=list(), pax=list(), maxcell=500000, smooth=FALSE, range=NULL, fill_range=FALSE, levels=NULL, all_levels=FALSE, breaks=NULL, breakby="eqint", fun=NULL, colNA=NULL, alpha=NULL, sort=FALSE, decreasing=FALSE, grid=FALSE, ext=NULL, reset=FALSE, add=FALSE, buffer=FALSE, background=NULL, box=axes, clip=TRUE, ...) {

old.mar <- graphics::par()$mar
on.exit(graphics::par(mar=old.mar))
Expand Down Expand Up @@ -837,7 +837,7 @@ setMethod("plot", signature(x="SpatRaster", y="numeric"),
alpha <- alpha[[y]]
}
}
plot(x, col=col, type=type, mar=mar, legend=legend, axes=axes, plg=plg, pax=pax, maxcell=2*maxcell/length(y), smooth=smooth, range=range, levels=levels, all_levels=all_levels, breaks=breaks, breakby=breakby, fun=fun, colNA=colNA, alpha=alpha, grid=grid, sort=sort, decreasing=decreasing, ext=ext, reset=reset, add=add, buffer=buffer, background=background, box=box, clip=clip, ...)
plot(x, col=col, type=type, mar=mar, legend=legend, axes=axes, plg=plg, pax=pax, maxcell=2*maxcell/length(y), smooth=smooth, range=range, fill_range=fill_range, levels=levels, all_levels=all_levels, breaks=breaks, breakby=breakby, fun=fun, colNA=colNA, alpha=alpha, grid=grid, sort=sort, decreasing=decreasing, ext=ext, reset=reset, add=add, buffer=buffer, background=background, box=box, clip=clip, ...)
return(invisible())
} else {
x <- x[[y]]
Expand Down Expand Up @@ -913,7 +913,7 @@ setMethod("plot", signature(x="SpatRaster", y="numeric"),
}
}

x <- .prep.plot.data(x, type=type, cols=col, mar=mar, draw=TRUE, plg=plg, pax=pax, legend=isTRUE(legend), axes=isTRUE(axes), coltab=coltab, cats=cats, interpolate=smooth, levels=levels, range=range, colNA=colNA, alpha=alpha, reset=reset, grid=grid, sort=sort, decreasing=decreasing, ext=ext, all_levels=all_levels, breaks=breaks, breakby=breakby, add=add, buffer=buffer, background=background, box=box, maxcell=maxcell, clip=clip, ...)
x <- .prep.plot.data(x, type=type, cols=col, mar=mar, draw=TRUE, plg=plg, pax=pax, legend=isTRUE(legend), axes=isTRUE(axes), coltab=coltab, cats=cats, interpolate=smooth, levels=levels, range=range, fill_range=fill_range, colNA=colNA, alpha=alpha, reset=reset, grid=grid, sort=sort, decreasing=decreasing, ext=ext, all_levels=all_levels, breaks=breaks, breakby=breakby, add=add, buffer=buffer, background=background, box=box, maxcell=maxcell, clip=clip, ...)

if (!is.null(fun)) {
if (!is.null(formals(fun))) {
Expand Down
14 changes: 1 addition & 13 deletions man/flowAccumulation.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ for (r in 1:nrow(elev1)) {
}


## Elevation Raster Maps
## Elevation raster
elev1 <- rast(elev1)
elev2 <- rast(elev2)

Expand All @@ -82,19 +82,9 @@ plot(flowdir2)
##
flow_acc1 <- flowAccumulation((flowdir1))
flow_acc2 <- flowAccumulation((flowdir2))
## Alternative option
## here the argument of "terrain" functions is flow directions instead of elevation.

flow_acc2a <- terrain(flowdir2,"flowacc")
t(array(flow_acc1[],rev(dim(flow_acc1)[1:2])))
t(array(flow_acc2[],rev(dim(flow_acc2)[1:2])))

plot(flow_acc1)
plot(flow_acc2)

weight <- elev1*0+10


flow_acc1w <- flowAccumulation(flowdir1,weight)
flow_acc2w <- flowAccumulation(flowdir2,weight)

Expand All @@ -113,8 +103,6 @@ flowdir <- terrain(elev,"flowdir")
weight <- cellSize(elev,unit="km")
flowacc_weight <- flowAccumulation(flowdir,weight)
flowacc <- flowAccumulation(flowdir)


}

\keyword{spatial}
2 changes: 1 addition & 1 deletion man/map_extent.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Helper function for creating custom map elements that are aligned with the axes

Unlike the standard base plot, terra keeps the axis aligned with the data. For that reason you cannot use \code{par()$usr} to get these coordinates.

The coordinates returned by this function are used in, for example, code{\link{add_legend}} such that a legend can be automatically placed in the a particular corner.
The coordinates returned by this function are used in, for example, \code{\link{add_legend}} such that a legend can be automatically placed in the a particular corner.

This function only returns meaningful results of the active plot (canvas) was create with a call to \code{plot} with a SpatRaster or SpatVector as first argument.
}
Expand Down
9 changes: 5 additions & 4 deletions man/plot.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ There is a separate help file for plotting a \code{\link[=plot,SpatGraticule,mis

\usage{
\S4method{plot}{SpatRaster,numeric}(x, y=1, col, type=NULL, mar=NULL, legend=TRUE, axes=!add, plg=list(), pax=list(),
maxcell=500000, smooth=FALSE, range=NULL, levels=NULL, all_levels=FALSE,
breaks=NULL, breakby="eqint", fun=NULL, colNA=NULL, alpha=NULL, sort=FALSE,
decreasing=FALSE, grid=FALSE, ext=NULL, reset=FALSE, add=FALSE, buffer=FALSE,
background=NULL, box=axes, clip=TRUE, ...)
maxcell=500000, smooth=FALSE, range=NULL, fill_range=FALSE,
levels=NULL, all_levels=FALSE, breaks=NULL, breakby="eqint", fun=NULL,
colNA=NULL, alpha=NULL, sort=FALSE, decreasing=FALSE, grid=FALSE, ext=NULL,
reset=FALSE, add=FALSE, buffer=FALSE, background=NULL, box=axes, clip=TRUE, ...)

\S4method{plot}{SpatRaster,missing}(x, y, main, mar=NULL, nc, nr, maxnl=16, maxcell=500000, add=FALSE, ...)

Expand Down Expand Up @@ -75,6 +75,7 @@ There is a separate help file for plotting a \code{\link[=plot,SpatGraticule,mis
\item{maxcell}{positive integer. Maximum number of cells to use for the plot}
\item{smooth}{logical. If \code{TRUE} the cell values are smoothed (only if a continuous legend is used)}
\item{range}{numeric. minimum and maximum values to be used for the continuous legend }
\item{fill_range}{logical. If \code{TRUE}, values outside of \code{range} get the colors of the extreme values; otherwise they get colored as \code{NA}}
\item{levels}{character. labels for the legend when \code{type="classes"} }
\item{all_levels}{logical. If \code{TRUE}, the legend shows all levels of a categorical raster, even if they are not present in the data}
\item{breaks}{numeric. Either a single number to indicate the number of breaks desired, or the actual breaks. When providing this argument, the default legend becomes "interval"}
Expand Down
4 changes: 2 additions & 2 deletions src/math_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ double modal_value(std::vector<double> values, unsigned ties, bool narm, std::de
tieCount = 1;
} else if (counts[i] == counts[maxCount]) {
tieCount++;
double rand = dist(rgen);
if (rand < (1 / tieCount)) {
double randnr = dist(rgen);
if (randnr < (1 / tieCount)) {
maxCount = i;
}
}
Expand Down

0 comments on commit 52f14fb

Please sign in to comment.