Skip to content

Instantly share code, notes, and snippets.

@yutannihilation
Last active November 11, 2018 11:30
Show Gist options
  • Save yutannihilation/a008f5310cb28031758756c2d47d12eb to your computer and use it in GitHub Desktop.
Save yutannihilation/a008f5310cb28031758756c2d47d12eb to your computer and use it in GitHub Desktop.

c.f. tidyverse/ggplot2#2881

library(ggplot2)
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3

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

ggplot() + 
  geom_sf(aes(fill = AREA), data=nc) + 
  scale_y_continuous(
    labels = function(x) {
      labels <- parse(text = paste0(format(x, nsmall = 1L), "*degree*N"))
      print(labels)
      labels
  }) +
  coord_sf()

#> expression(34.0*degree*N, 34.5*degree*N, 35.0*degree*N, 35.5*degree*N, 
#>     36.0*degree*N, 36.5*degree*N)

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


library(ggplot2)
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3

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

ggplot() + 
  geom_sf(aes(fill = AREA), data=nc) + 
  scale_y_continuous(
    labels = function(x) {
      paste0(format(x, nsmall = 1L), "\u00b0", "N")
  }) +
  coord_sf()

Created on 2018-11-11 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