-
Notifications
You must be signed in to change notification settings - Fork 300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add text method #2399
add text method #2399
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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)]) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
labels = row.names(x)