Skip to content

Commit 0a9ecd4

Browse files
committed
m
1 parent d94768d commit 0a9ecd4

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

R/plot.R

+6-2
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,12 @@ map.pal <- function(name, n=50, ...) {
318318
return(names(v))
319319
}
320320
if (name %in% names(v)) {
321-
r <- grDevices::colorRampPalette(v[[name]], ...)
322-
r(n)
321+
v <- v[[name]]
322+
if (length(v) != n) {
323+
grDevices::colorRampPalette(v, ...)(n)
324+
} else {
325+
v
326+
}
323327
} else {
324328
error("map.pal", paste(name, "is not a known palette"))
325329
}

R/plot_raster.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.default.pal <- function() {
33
opt.pal <- options("terra.pal")[[1]]
44
if (is.null(opt.pal)) {
5-
map.pal("viridis")
5+
map.pal("viridis", 100)
66
} else {
77
opt.pal
88
}

man/as.raster.Rd

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Implementation of the generic \code{\link[grDevices]{as.raster}} function to cre
1717
\arguments{
1818
\item{x}{ SpatRaster }
1919
\item{maxcell}{positive integer. Maximum number of cells to use for the plot}
20-
\item{col}{vector of colors. Default is col=rev(terrain.colors(255)))}
20+
\item{col}{vector of colors. The default is \code{map.pal("viridis", 100)}}
2121
}
2222

2323

man/plot.Rd

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ There is a separate help file for plotting a \code{\link[=plot,SpatGraticule,mis
4747
\arguments{
4848
\item{x}{SpatRaster or SpatVector}
4949
\item{y}{missing or positive integer or name indicating the layer(s) to be plotted}
50-
\item{col}{character. Colors. The default is \code{rev(grDevices::terrain.colors(50))}. If \code{x} is a \code{SpatRaster}, it can also be a \code{data.frame} with two columns (value, color) to get a "classes" type legend or with three columns (from, to, color) to get an "interval" type legend}
50+
\item{col}{character vector to specify the colors to use. The default is \code{map.pal("viridis", 100)}. The default can be changed with the \code{terra.pal} option. For example: \code{options(terra.pal=terrain.colors(10))}. If \code{x} is a \code{SpatRaster}, it can also be a \code{data.frame} with two columns (value, color) to get a "classes" type legend or with three columns (from, to, color) to get an "interval" type legend}
5151
\item{type}{character. Type of map/legend. One of "continuous", "classes", or "interval". If not specified, the type is chosen based on the data}
5252
\item{mar}{numeric vector of length 4 to set the margins of the plot (to make space for the legend). The default is (3.1, 3.1, 2.1, 7.1) for a single plot with a legend and (3.1, 3.1, 2.1, 2.1) otherwise. The default for a RGB raster is 0. Use \code{mar=NA} to not set the margins}
5353
\item{legend}{logical or character. If not \code{FALSE} a legend is drawn. The character value can be used to indicate where the legend is to be drawn. For example "topright" or "bottomleft". Use \code{plg} for more refined placement. Not supported for continuous legends (the default for raster data)}

0 commit comments

Comments
 (0)