thomasp85 / ggforce

Accelerating ggplot2
https://ggforce.data-imaginist.com
Other
916 stars 106 forks source link

geom_sf not working with units variables #249

Closed MalditoBarbudo closed 2 years ago

MalditoBarbudo commented 2 years ago

When trying to use geom_sf with a units variable it fails. It works nice with base plot, and also with other geometries (i.e. geom_point).

A reproducible example:

library(sf)
#> Linking to GEOS 3.9.1, GDAL 3.3.1, PROJ 8.0.1
library(ggplot2)
library(ggforce)

nc = st_read(system.file("shape/nc.shp", package="sf"))
#> Reading layer `nc' from data source 
#>   `/home/malditobarbudo/R/x86_64-pc-linux-gnu-library/4.1/sf/shape/nc.shp' 
#>   using driver `ESRI Shapefile'
#> Simple feature collection with 100 features and 14 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> Geodetic CRS:  NAD27
nc$a = st_area(nc)

# works
plot(nc["BIR74"])

plot(nc["a"])

# geom_sf works for no units
ggplot(nc, aes(fill = NWBIR74)) +
  geom_sf()

# geom_sf fails for units
ggplot(nc, aes(fill = a)) +
  geom_sf()
#> Error in Ops.units(x, range[1]): both operands of the expression should be "units" objects

# geom_point works
ggplot(nc, aes(x = a, y = NWBIR74)) +
  geom_point()

Created on 2021-10-29 by the reprex package (v2.0.1)

thomasp85 commented 2 years ago

The units scales has moved to the units package. If it is still an issue I suggest you file it there :-)