knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
Provides several geom
s which plot labels generated from sf
data.
ggsflabel is not released on CRAN yet. Please install with install_github()
.
# install.packages("devtools") devtools::install_github("yutannihilation/ggsflabel")
geom_label()
for sflibrary(ggsflabel) nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE) ggplot(head(nc, 3)) + geom_sf(aes(fill = AREA)) + geom_sf_label(aes(label = NAME))
geom_label_repel()
for sfif (requireNamespace("gghighlight", quietly = TRUE)) { library(gghighlight) ggplot(nc) + geom_sf(aes(fill = AREA)) + gghighlight(AREA > 0.20) + geom_sf_label_repel(aes(label = NAME), force = 100, nudge_x = -2, seed = 10) + scale_y_continuous(expand = expand_scale(mult = 0.5)) }
lims()
for sfpoints_sfg <- sf::st_multipoint(as.matrix(expand.grid(x = -90:-70, y = 30:40))) points_sfc <- sf::st_sfc(points_sfg, crs = sf::st_crs(nc)) p <- ggplot() + geom_sf(data = nc, aes(fill = AREA)) + geom_sf(data = points_sfc) # too wide p # shrink the limits to the bbox of nc p + lims_bbox(nc)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.