R 结合光栅图层和ggmap时如何更改光栅数据的颜色

R 结合光栅图层和ggmap时如何更改光栅数据的颜色,r,ggplot2,ggmap,r-raster,R,Ggplot2,Ggmap,R Raster,我目前正在学习有关光栅层的内容,我可以使用inset_raster()将光栅层放在ggmap上。下面是一个示例代码: library(ggmap) library(animation) auckland <- get_map(location = "Auckland", zoom = 14, scale = 2, ## 1280*1280 pixels maptype = "

我目前正在学习有关光栅层的内容,我可以使用inset_raster()将光栅层放在ggmap上。下面是一个示例代码:

library(ggmap)
library(animation)

auckland <- get_map(location = "Auckland",
                   zoom = 14,
                   scale = 2, ## 1280*1280 pixels
                   maptype = "roadmap",
                   color = "color")


auckland_vis <- ggmap(ggmap = auckland)

auckland_vis 

rainbow <- matrix(seq(360, 2000, length = 50 * 50), nrow = 50)
rainbow[sample(1:length(rainbow), 2400, replace = FALSE)] <- NA
rainbow.r <- raster(rainbow)


## inset_raster is used to put a raster layer on a ggmap
auckland_vis + 
  inset_raster(rainbow.r, xmin = attributes(auckland)$bb$ll.lon,
                    xmax = attributes(auckland)$bb$ur.lon,
                    ymin = attributes(auckland)$bb$ll.lat,
                    ymax = attributes(auckland)$bb$ur.lat
               )
库(ggmap)
图书馆(动画)

奥克兰在哪里定义了
london
变量?很抱歉,应该是奥克兰,我会更正,我查看了一些地方以找到答案。但是,您似乎无法使用
插入光栅
更改颜色。在
rasterVis
包中,有一个名为
gplot()
的函数。您可以在《起重机手册》第9页上找到一个示例。这允许您更改颜色。但是,您似乎无法将
ggmap
与它一起使用。试试这个<代码>gplot(rainbow.r)+geom_tile(aes(fill=value))+比例填充梯度(低=白色,高=蓝色)+坐标相等()
。如果你想改变颜色,最好考虑其他方法。@Lambo我有最新消息给你。包含您可能需要的一些信息。如果你想改变颜色,你得用矩阵做点什么。我只是在玩代码,但我还没玩到。@jazzurro谢谢,我会看看的