Search code examples
rggplot2r-sf

pretty_breaks does not working with geom_sf


I am trying to use scales::pretty_breaks with geom_sf like

library(terra)
library(sf)

filename <- system.file("ex/lux.shp", package="terra")
s <- vect(filename)

ggplot() +
  geom_sf(data = st_as_sf(s), fill="white") +
  theme_bw()+ 
  scale_x_continuous(breaks = scales::pretty_breaks(n = 3)) +
  scale_y_continuous(breaks = scales::pretty_breaks(n = 3))

It returns me the following error

Error in min(lon) : invalid 'type' (closure) of argument

How to solve this error?


Solution

  • This was a bug in ggplot2 as reported here which has been fixed in the development version. The development version of ggplot2 can be installed using

    install.packages("pak") 
    pak::pak("tidyverse/ggplot2")
    

    With the development version of ggplot2, the code given in the question works fine.