Mapping
source: rstudio/mapping.md
Links to get to started for mapping in RStudio
-
R-spatial
- This tutorial here is a good place to start
- ggplot, maps
- Making maps with R, by Eric C. Anderson
- Tutorial 5.4 - Mapping and spatial analyses in R
- Making maps of your study sites, Environmental Computing
- Displaying Geo-Spatial Data with R by Martin Schweinberger
- Leaflet for R - Leaflet is one of the most popular open-source JavaScript libraries for interactive maps. It's used by websites ranging from The New York Times and The Washington Post to GitHub and Flickr, as well as GIS specialists like OpenStreetMap, Mapbox, and CartoDB.
- Map Plots Created With R And Ggmap, by Litte Miss Data
- Using spatial data wth R by Claudia A Engel
- Spatial Data Science, analysing species distribution data
- Mapping Australia in R by Charles Coverdale
- Ozmaps Github
- Raster and vector geospatial data with R by Hayley Puckeridge
- Geocomputation with R by Spatial Vision
- Data wrangling for spatial analysis: R Workshop by Dr. Chris J Brown, Prof. David Schoeman, Prof. Anthony J Richardson, Dr. Bill Venables
- Visualizing Climate Data: A Tidy Tuesday Project From January 2020 Using Data From The Australia Wildfires
- Lesson 8. Creating Interactive Spatial Maps in R Using Leaflet by Carson Farmer, Leah Wasser
- tmap package
- Geocomputation with R by Robin Lovelace, Jakub Nowosad, Jannes Muenchow
- An Introduction to Spatial Analysis in R by Seascape models
- Oz viridis by Nicholas Tierney - mapping bom temperature and rainfall data for Australia
- AWAPer - an R-package for catchment-weighted climate data anywhere in Australia
- ClimClass package
- Climate Distance Mapper R script, USGS
- Making maps with R, by Eric C Anderson
- Spatial data in R: Using R as a GIS by Francisco Rodriguez-Sanchez
- Calculating species climate envelopes in R, by Remko Duursma
- Niche - An R Shint app
Useful data sets for mapping
- Australian government, climatology/meteorology/atmosphere
- Interim Biogeographic Regionalisation for Australia (IBRA), Version 7 (Regions), datset download here
- Biodiversity and Climate change virtual lab
Example workflow 1
Following tutorial at this link
library(sp)
library(dplyr)
library(rgdal)
library(raster)
library(ggplot2)
library(readr)
Import csv file containing lon and lat coords
Sites <- read_csv("../../data/sites.csv")
Create buffer around your data points
buffer <- 0.11
geo_bounds <- c(left = min(Sites$Lon)-buffer,
bottom = min(Sites$Lat)-buffer,
right = max(Sites$Lon)+buffer,
top = max(Sites$Lat)+buffer)
Sites.grid <- expand.grid(lon_bound = c(geo_bounds[1], geo_bounds[3]),
lat_bound = c(geo_bounds[2], geo_bounds[4]))
coordinates(Sites.grid) <- ~ lon_bound + lat_bound
Load mapping files Downloaded from GEODATA COAST 100K 2004 shapefiles available here
Aus <- readOGR(dsn = "~/Documents/Programs/R/Maps/Rpackage_Geodata-coast/australia",layer = "cstauscd_r")
Remove coastline clutter from map
Aus_coast <- subset(Aus, FEAT_CODE != "sea")
plot(Aus_coast)
Plot map and points using ggplot2
g1 = ggplot(data = Aus_coast) +
geom_polygon(aes(x = long, y = lat, group = group), fill = NA, color = "black") +
coord_fixed(1.3) + theme_classic()
g2 = g1 + geom_point(data = Sites, aes (x=Lon, y=Lat, colour=Locality, stroke=1.5)) +
scale_colour_viridis_d(option = "plasma")
Customise colour of points
g3 = g1 + geom_point(data = Sites, aes (x=Lon, y=Lat, colour=Locality, stroke=1.5), colour="#CC0000")
Make interactive plot with plotly
library(plotly)
gp <- ggplotly(g3)
gp
To save a html version of the interactive plot execute the following
htmlwidgets::saveWidget(gp, "index.html")
gp
Example workflow 2
Tutorial from Displaying Geo-Spatial Data with R by Martin Schweinberger
Install packages
# clean current workspace
rm(list=ls(all=T))
# set options
options(stringsAsFactors = F) # no automatic data transformation
options("scipen" = 100, "digits" = 4) # suppress math annotation
op <- options(gvis.plot.tag='chart') # set gViz options
# install libraries
install.packages(c("RgoogleMaps", "ggmap", "mapproj", "sf",
"dplyr", "OpenStreetMap", "devtools", "DT"))
# install package from github
devtools::install_github("dkahle/ggmap", ref = "tidyup")
Load library and produce simple map of Australia
# load library
library(OpenStreetMap)
# extract map
AustraliaMap <- openmap(c(-8,110),
c(-45,160),
type = "osm",
# type = "esri",
# type = "nps",
minNumTiles=7)
# plot map
plot(AustraliaMap)