I'm currently learning something on raster layer and I could put a raster layer on a ggmap using inset_raster(). Here is a sample code below:
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
)
Please ignore whether the points on the map is reasonable or not. I know how to change the colour of a raster data when just using plot()
. I would also like to know how to change the colour of the points in ggmap. For now the colours are always white, pink, yellow and green(what if I want the colours to be blue yellow and red). Is there a function that can specify colour just like the one in ggplot?
Thanks in advance