Search code examples
rggplot2rayshader

Rayshader plot_gg crashes while running example


I've tried to reproduce following rayshader example from https://www.tylermw.com/3d-ggplots-with-rayshader/ :

library(rayshader)
library(ggplot2)
library(tidyverse)
library(sf)
library(viridis)

nc = st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE)
gg_nc = ggplot(nc) +
  geom_sf(aes(fill = AREA)) +
  scale_fill_viridis("Area") +
  ggtitle("Area of counties in North Carolina") +
  theme_classic()

plot_gg(gg_nc, multicore = TRUE, width = 6 ,height=2.7, fov = 70)

but running the plot_gg line i get following error message:

Error in if (whichtype %in% c("text", "line")) { : argument is of length zero

Any idea on what's going on there?


Solution

  • Modify your code to:

    theme_set(theme_classic())
    
    gg_nc = ggplot(nc) +
      geom_sf(aes(fill = AREA)) +
      scale_fill_viridis("Area") +
      ggtitle("Area of counties in North Carolina")
    
    plot_gg(gg_nc, multicore = TRUE, width = 6 ,height=2.7, fov = 70)