我喜欢使用rayshader
包绘制 3D 图并放置一些感兴趣的坐标,但它不起作用。
如果我在示例中进行 dem 高程rayshader
,就可以了:
library(rayshader)
library(ggplot2)
library(raster)
#Here, I load a map with the raster package.
loadzip = tempfile()
download.file("https://tylermw.com/data/dem_01.tif.zip", loadzip)
localtif = raster::raster(unzip(loadzip, "dem_01.tif"))
unlink(loadzip)
#And convert it to a matrix:
elmat = raster_to_matrix(localtif)
# Plot elevation
ggelmat = elmat %>%
reshape2::melt() %>%
ggplot() +
geom_tile(aes(x=Var1,y=Var2,fill=value)) +
scale_x_continuous("X",expand = c(0,0)) +
scale_y_continuous("Y",expand = c(0,0)) +
coord_fixed()
ggelmat
# \donttest{
plot_gg(ggelmat, multicore = TRUE, raytrace = TRUE, width = 7, height = 4,
scale = 300, windowsize = c(1400, 866), zoom = 0.6, phi = 30, theta = 30, show.legend = FALSE)
render_snapshot(clear = TRUE)
但是,如果我创建一些随机点并尝试放入情节中:
#Create some 100 random coordinates
# grab 100 cell index numbers at random
samp <- sample(localtif, 100, replace = FALSE)
# and their location coordinates
samplocs <- xyFromCell(localtif, samp)
samplocs.df<-as.data.frame(samplocs)
pts<-spsample(localtif, 100, type = 'random')
pts.df<-as.data.frame(pts)
# Plot elevation with some coordinates
ggelmat2 = elmat %>%
reshape2::melt() %>%
ggplot() +
geom_point(data = samplocs.df, mapping = aes(x = x, y = y)) +
geom_tile(aes(x=Var1,y=Var2,fill=value)) +
scale_x_continuous("X",expand = c(0,0)) +
scale_y_continuous("Y",expand = c(0,0)) +
coord_fixed()
ggelmat2
# \donttest{
plot_gg(ggelmat2, multicore = TRUE, raytrace = TRUE, width = 7, height = 4,
scale = 300, windowsize = c(1400, 866), zoom = 0.6, phi = 30, theta = 30, show.legend = FALSE)
render_snapshot(clear = TRUE)
#
它不起作用!另一个问题,我相信这是解决方案的一部分,是否可以在 X 和 Y 轴上显示原始图像系统坐标?