0

I'd like to plot an R sf object using ggplot2 and the rayshader package on Mac OSX (Ventura, M1 chip).

# Load packages
library(sf)
library(ggplot2)
library(rayshader)

# Create example data
density_data <- data.frame(X=1:5, Y=1:5, Z=1:5)

# Convert to sf object    
my_sf <- sf::st_as_sf(density_data, coords=c("X", "Y"))
st_crs(my_sf) <- "WGS84" # Set CRS. Not really necessary here

# Create a ggplot2 graph
pp <- my_sf |> 
    ggplot(aes(color=Z)) +
    geom_sf(aes(geometry = geometry), show.legend=FALSE)

# Plot the graph
pp 

So far so good. Using it with rayshader provides the problems

plot_gg(pp)

produces the following error

Error in `geom_sf()`:
! Problem while converting geom to grob.
ℹ Error occurred in the 1st layer.
Caused by error in `check.length()`:
! 'gpar' element 'fontsize' must not be length 0
Run `rlang::last_error()` to see where the error occurred.
Warning message:
Removed 5 rows containing missing values (`geom_sf()`) 

Running rayshader v 0.34.6, ggplot2 v 3.4.0.9000, and sf v1.0-9.

ekstroem
  • 5,957
  • 3
  • 22
  • 48

0 Answers0