英文:
add 2D image on 3D Plot RGL Device with rayshader in R
问题
我想在 RGL 设备上显示的 3D 绘图中添加图像。我尝试使用 annotation_raster() 和 annotation_custom() 添加图像,但图像是 3D 的,我希望它是平的。有没有可以使用的代码?谢谢。
我尝试了这段代码,但图像是 3D 的,而不是平的。
英文:
I want to add image on 3D plot which is shown on RGL Device. I try add image with annotation_raster() and annotation_custom() but image include be 3D, i expect it be flat. are there code can i use? Thanks..
I try this code but image include 3D, not flat.
image <- magick::image_read("image.png")
image <- rasterGrob(image, interpolate = TRUE,
width=unit(1.5,'cm'),
x = unit(1,"npc"), y = unit(1,"npc"),
hjust = 1, vjust=1)
map <- sf::st_read('map/map.shp', quiet = TRUE)
gg <- ggplot(map) +
geom_sf()+
geom_sf(aes(fill =AREA),linewidth=0.7,colour='black') +
scale_fill_gradient('Area',low='skyblue',high = 'dodgerblue4',na.value = 'white')+
annotation_custom(image)+
theme_bw()+
theme(axis.line = element_blank(),axis.title = element_blank(),
axis.ticks = element_blank(), axis.text = element_blank()
)
plot_gg(gg, height = 8.5, width = 9,
multicore = TRUE,windowsize = c(1050, 600),
offset_edges = TRUE)
答案1
得分: 1
有一些替代方法。在我的工作中,我曾经使用以下方法:使用ggimage::geom_image(aes(x = 20, y = 30, image= "image.png"), size = 1)
(根据你的数据和原始图像大小来调整这些数字)来替换annotation_custom(image)
。这将在3D图表上提供一个2D图像而不是3D图像。在我的机器上使用我的数据时有效。
如果在你的一侧无法正常工作,请提供你的数据(可重现的示例),这样我就可以在我的一侧进行测试。
英文:
There could be some alternatives. One approach that I have used in my work is to use ggimage::geom_image(aes(x = 20, y = 30, image= "image.png"), size = 1)
(adjust those numbers according to your data and original image size) to replace annotation_custom(image)
. This will give a 2D image instead of a 3D image on 3D graph. It worked on my machine with my data.
If it does not work on your side, please provide your data (reproducible example) so I would be able to test it on my side.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论