Examples for 'sf::plot'


plot sf object

Aliases: plot plot.sf get_key_pos plot.sfc_POINT plot.sfc_MULTIPOINT plot.sfc_LINESTRING plot.sfc_CIRCULARSTRING plot.sfc_MULTILINESTRING plot.sfc_POLYGON plot.sfc_MULTIPOLYGON plot.sfc_GEOMETRYCOLLECTION plot.sfc_GEOMETRY plot.sfg plot_sf sf.colors text.sf text.sfc points.sf points.sfc

Keywords:

### ** Examples

nc = st_read(system.file("gpkg/nc.gpkg", package="sf"), quiet = TRUE)
# plot single attribute, auto-legend:
plot(nc["SID74"])
plot of chunk example-sf-plot-1
# plot multiple:
plot(nc[c("SID74", "SID79")]) # better use ggplot2::geom_sf to facet and get a single legend!
plot of chunk example-sf-plot-1
# adding to a plot of an sf object only works when using reset=FALSE in the first plot:
plot(nc["SID74"], reset = FALSE)
plot(st_centroid(st_geometry(nc)), add = TRUE)
plot of chunk example-sf-plot-1
# log10 z-scale:
plot(nc["SID74"], logz = TRUE, breaks = c(0,.5,1,1.5,2), at = c(0,.5,1,1.5,2))
plot of chunk example-sf-plot-1
# and we need to reset the plotting device after that, e.g. by
layout(1)
# when plotting only geometries, the reset=FALSE is not needed:
plot(st_geometry(nc))
plot(st_geometry(nc)[1], col = 'red', add = TRUE)
plot of chunk example-sf-plot-1
# add a custom legend to an arbitray plot:
layout(matrix(1:2, ncol = 2), widths = c(1, lcm(2)))
plot(1)
.image_scale(1:10, col = sf.colors(9), key.length = lcm(8), key.pos = 4, at = 1:10)
plot of chunk example-sf-plot-1
# manipulate plotting order, plot largest polygons first:
p = st_polygon(list(rbind(c(0,0), c(1,0), c(1,1), c(0,1), c(0,0))))
x = st_sf(a=1:4, st_sfc(p, p * 2, p * 3, p * 4)) # plot(x, col=2:5) only shows the largest polygon!
plot(x[order(st_area(x), decreasing = TRUE),], col = 2:5) # plot largest polygons first

sf.colors(10)
 [1] "#0000B3FF" "#0400FFFF" "#4500FFFF" "#8500FFFF" "#C527D8FF" "#FF50AFFF"
 [7] "#FF7A85FF" "#FFA35CFF" "#FFCC33FF" "#FFF50AFF"
text(nc, labels = substring(nc$NAME,1,1))
plot of chunk example-sf-plot-1

[Package sf version 1.0-19 Index]