library(ggmap)
basemap <- get_googlemap(zoom = 15, scale = 4,format="png8", maptype="terrain")
ggmap(basemap) # OK
switch_bg <- function(x) {
xc <- col2rgb(x)
g <- xc["green",]
b <- xc["blue",]
xc["green",] <- b
xc["blue",] <- g
rgb(xc[1,], xc[2,], xc[3,], maxColorValue=255)
}
basemap[] <- switch_bg(basemap)
class(basemap) <- c("ggmap", "raster")
ggmap(basemap) # Does not plot
我想操纵 ggmap 的颜色。由于栅格是颜色矩阵,我想我可以更新矩阵。但是,分配给矩阵会删除类并以某种方式破坏对象。
为什么?