【问题标题】:Problem turning ggplot into 3D graph (using rayshader)将 ggplot 转换为 3D 图形的问题(使用光线着色器)
【发布时间】:2022-03-07 10:35:20
【问题描述】:

我正在尝试使用 rayshader 包将 ggplot 转换为 3D 图。 ggplot 是用geom_raster() 制作的,工作正常。这是它的样子:

这是二维绘图的代码。虽然,我认为这不是问题的核心所在。因为如前所述,它一直有效。

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")

然后我尝试使用plot_gg(Plot) 将其转换为 3D 图,我收到以下错误代码:

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

我不知道错误是什么意思,也没有在网上找到任何东西。我尝试重新安装rayshader,但没有帮助。 plot_gg 也适用于我尝试过的其他图形。

有谁知道问题出在哪里?

【问题讨论】:

标签: r ggplot2 3d rayshader


【解决方案1】:

如果不使用 theme_void() 将元素显式设置为空白,则会遇到同样的问题并得到解决:

    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

【讨论】:

  • 现在可以了,太棒了!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-28
  • 2019-03-22
  • 1970-01-01
  • 2021-12-03
  • 1970-01-01
相关资源
最近更新 更多