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

lineLabel

Line label placement with spplot and lattice.


Description

The lineLabel function produces and draws text grobs following the paths defined by a list of Line objects. The sp.lineLabel methods use this function to work easily with spplot.

Usage

lineLabel(line, label,
          spar=.6, position = c('above', 'below'),
          textloc = 'constantSlope',
          col = add.text$col,
          alpha = add.text$alpha,
          cex = add.text$cex,
          lineheight = add.text$lineheight,
          font = add.text$font,
          fontfamily = add.text$fontfamily,
          fontface = add.text$fontface,
          lty = add.line$lty,
          lwd = add.line$lwd, 
          col.line = add.line$col,
          identifier = 'lineLabel',
          ...)

sp.lineLabel(object, labels, byid=TRUE,...)

label(object, text, ...)

Arguments

line

a list of Lines.

object

A Lines or SpatialLines object.

label, labels, text

a string or expression to be printed following the path of line. The names of labels should match the values of the ID slot of the lines to label. If labels is missing, the ID slot is used instead. The label method is a wrapper function to extract the ID slots and create a suitable character object with the correct names values.

byid

If TRUE (default) only the longest line of each unique ID value will be labelled.

textloc

a character or a numeric. It may be 'constantSlope', 'minSlope' or 'maxDepth', or the numeric index of the location. If it is a numeric, its length must coincide with the number of Lines.

spar

smoothing parameter. With values near zero, the label will closely follow the line. Default value is .6. See smooth.spline for details.

position

character string ('above' or 'below') to define where the text must be placed.

col, alpha, cex, lineheight, font, fontfamily, fontface

graphical arguments for the text. See gpar for details.

lty, lwd, col.line

graphical parameters for the line. See gpar for details.

identifier

A character string to identify the grob to be created.

...

other arguments

Details

Part of the label location code is adapted from panel.levelplot. smooth.spline is used to resample the segment of the line where the label is placed.

Author(s)

Oscar Perpiñán Lamigueiro.

See Also

Examples

data(meuse.grid)
coordinates(meuse.grid) = ~x+y
proj4string(meuse.grid) <- CRS("+init=epsg:28992")
gridded(meuse.grid) = TRUE

data(meuse)
coordinates(meuse) = ~x+y
data(meuse.riv)
meuse.sl <- SpatialLines(list(Lines(list(Line(meuse.riv)), "1")))

library(RColorBrewer)
myCols <- adjustcolor(colorRampPalette(brewer.pal(n=9, 'Reds'))(100), .85)

labs <- label(meuse.sl, 'Meuse River')

## Maximum depth
sl1 <- list('sp.lineLabel', meuse.sl, label=labs,
            position='below', textloc='maxDepth',
            spar=.2,
            col='darkblue', cex=1,
            fontfamily='Palatino',
            fontface=2)

spplot(meuse.grid["dist"],
       col.regions=myCols, 
       sp.layout = sl1)

## Constant slope
sl2 <- modifyList(sl1, list(textloc = 'constantSlope')) ## Default

spplot(meuse.grid["dist"],
       col.regions=myCols, 
       sp.layout = sl2)

## Location defined by its numeric index
sl3 <- modifyList(sl1, list(textloc = 140, position='above'))

spplot(meuse.grid["dist"],
       col.regions=myCols, 
       sp.layout = sl3)

maptools

Tools for Handling Spatial Objects

v1.1-1
GPL (>= 2)
Authors
Roger Bivand [cre, aut] (<https://orcid.org/0000-0003-2392-6140>), Nicholas Lewin-Koh [aut], Edzer Pebesma [ctb], Eric Archer [ctb], Adrian Baddeley [ctb], Nick Bearman [ctb], Hans-Jörg Bibiko [ctb], Steven Brey [ctb], Jonathan Callahan [ctb], German Carrillo [ctb], Stéphane Dray [ctb], David Forrest [ctb], Michael Friendly [ctb], Patrick Giraudoux [ctb], Duncan Golicher [ctb], Virgilio Gómez Rubio [ctb], Patrick Hausmann [ctb], Karl Ove Hufthammer [ctb], Thomas Jagger [ctb], Kent Johnson [ctb], Matthew Lewis [ctb] (<https://orcid.org/0000-0003-2244-4078>), Sebastian Luque [ctb], Don MacQueen [ctb], Andrew Niccolai [ctb], Edzer Pebesma [ctb], Oscar Perpiñán Lamigueiro [ctb], Ethan Plunkett [ctb], Ege Rubak [ctb] (<https://orcid.org/0000-0002-6675-533X>), Tom Short [ctb], Greg Snow [ctb], Ben Stabler [ctb], Murray Stokely [ctb], Rolf Turner [ctb]
Initial release
2021-03-14

We don't support your browser anymore

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