Skip to content

Instantly share code, notes, and snippets.

@yutannihilation
Last active February 11, 2019 21:05
Show Gist options
  • Save yutannihilation/7a5a72ba2e1dcd1665ea34fb511b1eaa to your computer and use it in GitHub Desktop.
Save yutannihilation/7a5a72ba2e1dcd1665ea34fb511b1eaa to your computer and use it in GitHub Desktop.
library(ggplot2)


nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)

ggplot(nc[1:2,]) +
  geom_sf(aes(fill = AREA)) +
  geom_sf_label(aes(label = NAME),
                nudge_x = c(-0.2, 0.2),
                nudge_y = c(-0.2, 0.2))
#> Warning in st_point_on_surface.sfc(sf::st_zm(x)): st_point_on_surface may
#> not give correct results for longitude/latitude data

Created on 2019-02-11 by the reprex package (v0.2.1)

library(ggplot2)

nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
ggplot(nc[1:3,]) +
  coord_fixed() +
  geom_sf() +
  # for comparison
  geom_sf_label(aes(label = NAME), colour = "grey") +
  # add nudges
  geom_sf_label(aes(label = NAME), colour = "red",
                nudge_x = c(-0.4, 0.5, 0.7),
                nudge_y = c(0.2, 0.2, 0.5))
#> Coordinate system already present. Adding new coordinate system, which will replace the existing one.
#> Warning in st_point_on_surface.sfc(sf::st_zm(x)): st_point_on_surface may
#> not give correct results for longitude/latitude data

#> Warning in st_point_on_surface.sfc(sf::st_zm(x)): st_point_on_surface may
#> not give correct results for longitude/latitude data

Created on 2019-02-12 by the reprex package (v0.2.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment