One of the fun things you can do with maps in R is make rasters and shapes that plot on Google Earth. All you really need to do is convert your spatial data to lon-lat coordinates then use one of the KML packages to save the layer as a KML, which can then be viewed in Google Earth. Here is a screen shot of an example from data in my R spatial course.
Here is how to do it for a raster.
Here we export the seagrass raster data (available here)
from my R Spatial Course as KML. You will need the plotKML
package
and its dependencies.
library(raster)
library(rgdal)
library(plotKML)
rseagrass <- raster('raster seagrass.grd')
rsg.ll <- projectRaster(rseagrass, crs = "+proj=longlat +ellps=WGS84", method = 'ngb')
We are using the nearest neighbour ('ngb'
) interpolation here, because the seagrass raster is categorical (0/1 for absence/presence of seagrass).
sgcols <- c('lightblue', 'seagreen')
KML(rsg.ll, 'Seagrass_MoretonBay', col = sgcols)
Designed by Chris Brown. Source on Github