Skip to content

geom_hline() / geom_vline() don't work with geom_sf() #2820

Closed
@clauswilke

Description

@clauswilke

Reprex below. Primarily reporting this to show the PR I'm about to make didn't mess this up. It's already broken. :-)

library(ggplot2)
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"))
#> Reading layer `nc' from data source `/Library/Frameworks/R.framework/Versions/3.5/Resources/library/sf/shape/nc.shp' using driver `ESRI Shapefile'
#> Simple feature collection with 100 features and 14 fields
#> geometry type:  MULTIPOLYGON
#> dimension:      XY
#> bbox:           xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> epsg (SRID):    4267
#> proj4string:    +proj=longlat +datum=NAD27 +no_defs

# works
ggplot(nc) +
  geom_sf() + 
  geom_line(
    data = data.frame(x = c(-80, -80), y = c(34, 36.5)),
    aes(x, y),
    color = "red"
  )

# doesn't work
ggplot(nc) +
  geom_sf() + 
  geom_hline(yintercept = 35)
#> Error in unit(x0, default.units): 'x' and 'units' must have length > 0

# doesn't work
ggplot(nc) +
  geom_sf() + 
  geom_vline(xintercept = -80)
#> Error in unit(y0, default.units): 'x' and 'units' must have length > 0

Created on 2018-08-10 by the reprex package (v0.2.0).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions