diff --git a/NAMESPACE b/NAMESPACE index f3c8c6bc8..b7af0d2f4 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -357,6 +357,7 @@ S3method(st_zm,sfg) S3method(str,sfc) S3method(summary,sfc) S3method(t,sgbp) +S3method(text,sf) S3method(transform,sf) S3method(vec_cast.sfc,default) S3method(vec_cast.sfc,sfc) diff --git a/R/plot.R b/R/plot.R index 5ee3bc47d..ec80d5076 100644 --- a/R/plot.R +++ b/R/plot.R @@ -700,6 +700,25 @@ sf.colors = function (n = 10, cutoff.tails = c(0.35, 0.2), alpha = 1, categorica } } +# Add text to an existing graphic +# +#' @param labels character, text to draw (one per row of input) +#' @param of_largest_polygon logical, passed on to \code{st_centroid} +#' @name plot +#' @export +#' @details Adds text to an existing graphic. Text is placed at the centroid of +#' each feature in \code{x}. Provide POINT features for full control of placement. +#' @examples +#' text(nc, labels = substring(nc$NAME,1,1)) +text.sf = function(x, labels = row.names, ..., of_largest_polygon = FALSE){ + x = st_geometry(x) + x = st_centroid(x, of_largest_polygon = FALSE) + xy = st_coordinates(x) + text(xy[,1], xy[,2], labels = labels, ...) +} + + + # get the aspect ratio of a bounding box, for geodetic coords true scale at mid latitude: get_asp = function(bb) { asp = diff(bb[c(2,4)])/diff(bb[c(1,3)]) diff --git a/man/dbWriteTable.Rd b/man/dbWriteTable.Rd index f232618b6..9a5b8e58b 100644 --- a/man/dbWriteTable.Rd +++ b/man/dbWriteTable.Rd @@ -32,17 +32,19 @@ \arguments{ \item{conn}{DBIObject} -\item{name}{ - character vector of names (table names, fields, keywords). -} +\item{name}{The table name, passed on to \code{\link[DBI:dbQuoteIdentifier]{dbQuoteIdentifier()}}. Options are: +\itemize{ +\item a character string with the unquoted DBMS table name, +e.g. \code{"table_name"}, +\item a call to \code{\link[DBI:Id]{Id()}} with components to the fully qualified table name, +e.g. \code{Id(schema = "my_schema", table = "table_name")} +\item a call to \code{\link[DBI:SQL]{SQL()}} with the quoted and fully qualified table name +given verbatim, e.g. \code{SQL('"my_schema"."table_name"')} +}} -\item{value}{ - a data.frame. -} +\item{value}{A \link{data.frame} (or coercible to data.frame).} -\item{...}{ - placeholder for future use. -} +\item{...}{Other parameters passed on to methods.} \item{row.names}{Add a \code{row.name} column, or a vector of length \code{nrow(obj)} containing row.names; default \code{FALSE}.} diff --git a/man/plot.Rd b/man/plot.Rd index 637513a51..071da632f 100644 --- a/man/plot.Rd +++ b/man/plot.Rd @@ -16,6 +16,7 @@ \alias{plot.sfg} \alias{plot_sf} \alias{sf.colors} +\alias{text.sf} \title{plot sf object} \usage{ \method{plot}{sf}( @@ -153,6 +154,8 @@ plot_sf( ) sf.colors(n = 10, cutoff.tails = c(0.35, 0.2), alpha = 1, categorical = FALSE) + +\method{text}{sf}(x, labels = row.names, ..., of_largest_polygon = FALSE) } \arguments{ \item{x}{object of class sf} @@ -242,6 +245,10 @@ or object returned by \link{st_graticule}} \item{alpha}{numeric, in \verb{[0,1]}, transparency} \item{categorical}{logical; do we want colors for a categorical variable? (see details)} + +\item{labels}{character, text to draw (one per row of input)} + +\item{of_largest_polygon}{logical, passed on to \code{st_centroid}} } \description{ plot one or more attributes of an sf object on a map @@ -275,6 +282,9 @@ implies an \href{https://en.wikipedia.org/wiki/Equirectangular_projection}{Equir non-categorical colors from \code{sf.colors} were taken from \link[sp]{bpy.colors}, with modified \code{cutoff.tails} defaults If categorical is \code{TRUE}, default colors are from \url{https://colorbrewer2.org/} (if n < 9, Set2, else Set3). + +Adds text to an existing graphic. Text is placed at the centroid of +each feature in \code{x}. Provide POINT features for full control of placement. } \examples{ nc = st_read(system.file("gpkg/nc.gpkg", package="sf"), quiet = TRUE) @@ -302,4 +312,5 @@ x = st_sf(a=1:4, st_sfc(p, p * 2, p * 3, p * 4)) # plot(x, col=2:5) only shows t plot(x[order(st_area(x), decreasing = TRUE),], col = 2:5) # plot largest polygons first sf.colors(10) +text(nc, labels = substring(nc$NAME,1,1)) }