Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

text

Add labels to a map


Description

Plots labels, that is a textual (rather than color) representation of values, on top an existing plot (map).

Usage

## S4 method for signature 'RasterLayer'
text(x, labels, digits=0, fun=NULL, halo=FALSE, ...)

## S4 method for signature 'RasterStackBrick'
text(x, labels, digits=0, fun=NULL, halo=FALSE, ...)

## S4 method for signature 'SpatialPolygons'
text(x, labels, halo=FALSE, ...)

## S4 method for signature 'SpatialPoints'
text(x, labels, halo=FALSE, ...)

Arguments

x

Raster*, SpatialPoints* or SpatialPolygons* object

labels

character. Optional. Vector of labels with length(x) or a variable name from names(x)

digits

integer. how many digits should be used?

fun

function to subset the values plotted (as in rasterToPoints)

halo

logical. If TRUE a 'halo' is printed around the text. If TRUE, additional arguments hc='white' and hw=0.1 can be modified to set the colour and width of the halo

...

additional arguments to pass to graphics function text

See Also

Examples

r <- raster(nrows=4, ncols=4)
r <- setValues(r, 1:ncell(r))
plot(r)
text(r)

plot(r)
text(r, halo=TRUE, hc='blue', col='white', hw=0.2)

plot(r, col=bpy.colors(5))
text(r, fun=function(x){x<5 | x>12}, col=c('red', 'white'), vfont=c("sans serif", "bold"), cex=2)

raster

Geographic Data Analysis and Modeling

v3.4-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Jacob van Etten [ctb], Michael Sumner [ctb], Joe Cheng [ctb], Dan Baston [ctb], Andrew Bevan [ctb], Roger Bivand [ctb], Lorenzo Busetto [ctb], Mort Canty [ctb], Ben Fasoli [ctb], David Forrest [ctb], Aniruddha Ghosh [ctb], Duncan Golicher [ctb], Josh Gray [ctb], Jonathan A. Greenberg [ctb], Paul Hiemstra [ctb], Kassel Hingee [ctb], Institute for Mathematics Applied Geosciences [cph], Charles Karney [ctb], Matteo Mattiuzzi [ctb], Steven Mosher [ctb], Babak Naimi [ctb], Jakub Nowosad [ctb], Edzer Pebesma [ctb], Oscar Perpinan Lamigueiro [ctb], Etienne B. Racine [ctb], Barry Rowlingson [ctb], Ashton Shortridge [ctb], Bill Venables [ctb], Rafael Wueest [ctb]
Initial release
2021-05-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.