ggplot2 3.4.0与rayshader兼容性问题:linewidth参数异常
解决ggplot2 3.4.0与rayshader在Ubuntu 22.04的兼容问题
针对你遇到的ggplot2 3.4.0替换size为linewidth后,rayshader生成3D图形异常的问题,可尝试以下几种方案:
方案1:更新rayshader至最新版本
rayshader后续版本大概率修复了对ggplot2 3.4.0新增linewidth参数的支持。在R中执行更新命令:
install.packages("rayshader") # 若需开发版,可使用devtools: # devtools::install_github("tylermorganwall/rayshader")
方案2:手动将图层的linewidth参数映射为size
如果更新rayshader后问题仍存在,可在生成ggplot对象后,手动将图层中的linewidth参数替换为size,让rayshader能识别:
library(tidyverse) library(rayshader) p <- df %>% ggplot() + geom_sf(aes(geometry = geometry, fill = value), color = "black", linewidth = 0.25) + scale_fill_viridis_c(option = "C", limits = c(0, 100)) + coord_sf(xlim = c(100, 180), ylim = c(-60, -10)) + theme(legend.position = "none") # 手动替换图层中的linewidth为size p$layers[[1]]$aes_params$size <- p$layers[[1]]$aes_params$linewidth p$layers[[1]]$aes_params$linewidth <- NULL # 继续执行rayshader渲染 plot_gg(p, zoom = 0.6, multicore = TRUE, raytrace = TRUE, phi = 30, theta = 0 ) render_snapshot(filename = "gr_1") rgl::rgl.close()
方案3:临时回退ggplot2版本(备选)
如果上述方案都无效,可暂时回退到兼容版本,待rayshader完全适配后再升级:
# 卸载当前版本并安装指定版本 packageVersion("ggplot2") remove.packages("ggplot2") install.packages("ggplot2", version = "3.3.6")
内容的提问来源于stack exchange,提问作者Zhiqiang Wang
相关产品推荐
相关产品推荐

