Stamen maps with spplot

[This article was first published on Omnia sunt Communia! » R-english, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Several R packages provide an interface to query map services (Google Maps, Stamen Maps or OpenStreetMap) to obtain raster images from them. As far as I know, there are three packages devoted to this task: RgoogleMaps, OpenStreetMap and ggmap. The latter two are increasingly popular with a wide collection of providers.

Both of them use the background image to configure the graphical window defining functions (automap and ggmap, respectively) to display the images with ggplot2. Additional information can be layered upon this background image with ggplot2 functions. In my opinion, this approach is somewhat strange. I feel more comfortable with the approach implemented in the spplot function of the sp package, which relies on the main data to be displayed to configure the graphical window instead of using an auxiliary image as the starting point.

Although none of these two packages include functions to work with spplot, it is not difficult to build a mixed solution. The key point is that the result of their queries is mainly a raster image which can be easily displayed with the grid.raster function after some corrections.

The next code displays the location of the photovoltaic systems installed in California grouped by nominal power using data available from the OpenPV project. The procedure is:

  • Download the data and define the coordinates and projection.
  • Download an image from the Stamen Maps service according to the spatial extent of the data (this example uses ggmap but a similar approach can be followed with the OpenStreetMap package).
  • Use grid.raster to display the image using the coordinates of its corners to define the width, height and center location.
  • Display the variable with circles of different sizes and colours over the background image.

stamen_spplot


To leave a comment for the author, please follow the link and comment on their blog: Omnia sunt Communia! » R-english.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)