Skip to content

Instantly share code, notes, and snippets.

@emhart
Created October 29, 2015 05:36
Show Gist options
  • Save emhart/68888b7bcf1794f08cdf to your computer and use it in GitHub Desktop.
Save emhart/68888b7bcf1794f08cdf to your computer and use it in GitHub Desktop.
Create javascript leaflet maps of prism data
library(devtools)
install_github("ropensci/prism")
library(leaflet)
library(raster)
library(prism)
## Set default path for raster files
options(prism.path = "~/prismtmp")
get_prism_normals(type="tmean",resolution = "4km",annual =T, keepZip=F)
## Grab the data, ls_prism_data(absPath=T) will show you all the data you've downloaded
norm <- grep("tmean_30yr_normal_4kmM2_annual",ls_prism_data(absPath=T)[,2],value=T)
rast <- raster(norm)
## Create color pallette and plot
pal <- colorNumeric(c("#0000FF", "#FFFF00", "#FF0000"), values(rast),
na.color = "transparent")
leaflet() %>% addTiles(urlTemplate = 'http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}') %>%
addRasterImage(rast,colors = pal,opacity=.65) %>% addLegend(pal = pal, values = values(rast),
title = "Deg C")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment