3

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

Lambo
  • 857
  • 3
  • 14
  • 39
  • 1
    Where is the `london` variable defined? – David Robinson Sep 17 '14 at 00:25
  • Sorry it should be Auckland I will correct that – Lambo Sep 17 '14 at 01:45
  • 1
    I looked into some places to find an answer. But, it seems that you may not be able to change colours using `inset_raster`. In `rasterVis` package, there is a function called `gplot()`. You can find an example on page 9 of the CRAN manual. This allows you to change colours. But, it seems that you cannot use `ggmap` with it. Try this. `gplot(rainbow.r) + geom_tile(aes(fill=value)) + scale_fill_gradient(low = 'white', high = 'blue') + coord_equal()`. If you want to change colours, it may be better to think alternative approaches. – jazzurro Sep 18 '14 at 02:15
  • 1
    @Lambo I have update for you. [This post](http://stackoverflow.com/questions/25847188/geographical-heat-map-of-a-custom-property-in-r-with-ggmap/25936758#25936758) contains some information you may want. It seems that you gotta do something with a matrix if you want to change colours. I just played with the codes, but I am not there yet. – jazzurro Sep 23 '14 at 04:21
  • @jazzurro thanks I'd take a look at that – Lambo Sep 23 '14 at 05:10

0 Answers0