Search code examples
rggplot23drayshader

Problem turning ggplot into 3D graph (using rayshader)


I am trying to turn a ggplot into a 3D plot using the rayshader package. The ggplot is made with geom_raster() and works fine. This is how it looks like: image attached

Here is the code for the 2D plot. Although, I think that's not where the core of the problem is. Because as already mentioned, it works until here.

Plot = Score_image %>% 
  ggplot(aes(x=as.numeric(x),
             y=as.numeric(y), fill= PC_1)) + 
  geom_raster()+
  theme_void()+
  scale_fill_viridis(na.value = "white")

Then I try to turn it into a 3D plot with plot_gg(Plot) and I receive the following error code:

Error in png::readPNG(paste0(heightmaptemp, ".png")) : 
  unable to open C:\Users\...\AppData\Local\Temp\RtmpGQuKkm\file16dc6dd3339f.png

I have no idea what the error means and I didn't find anything online. I tried re-installing rayshader, but that didn't help. plot_gg works with also with other grahps that I have tried.

Does anyone know what the problem is?


Solution

  • Had the same problem and got resolved if instead of using theme_void() setting explicitly the elements as blank:

        Plot = Score_image %>% 
        ggplot(aes(x=as.numeric(x),
                 y=as.numeric(y), fill= PC_1)) + 
        geom_raster() +
        scale_fill_viridis(na.value = "white") +
        theme(legend.position = "none", 
            axis.line=element_blank(), 
            axis.text.x=element_blank(), axis.title.x=element_blank(),
            axis.text.y=element_blank(), axis.title.y=element_blank(),
            axis.ticks=element_blank(), 
            panel.background = element_blank()) # Clean Everything