0

I am trying to create a heatmap for Veterans Integrated Service Networks (VISN) level averages. I have found these datasets containing shapefiles.

I have the averages I want to plot based on the VISN, but I'm not sure how to go about creating this map in R.

2

The function sp.kde in the spatialEco package will produce a weighted or unweighted Kernel Density Estimate (KDE), or what you are calling a "heat map". Please note that this works for point feature classes, not polygons or lines.

library(sp)
library(raster)
library(spatialEco)
  data(meuse)
  coordinates(meuse) <- ~x+y

Weighted KDE using cadmium and spatial locations without a reference raster

cadmium.kde <- sp.kde(x = meuse, y = meuse$cadmium, bw = 1000, n = 5000, 
                      standardize = TRUE, scale.factor = 10000  )

Unweighted KDE (spatial locations only)

pt.kde <- sp.kde(x = meuse, bw = 1000, standardize = TRUE, n = 5000, 
                 scale.factor = 10000  )

Plot results

par(mfrow=c(1,2))
  plot(cadmium.kde, main="weighted kde")
    points(meuse, pch=20, col="red")
  plot(pt.kde, main="Unweighted kde")
    points(meuse, pch=20, col="red") 

Using an existing raster

data(meuse.grid)
  coordinates(meuse.grid) = ~x+y
  proj4string(meuse.grid) <- CRS("+init=epsg:28992")
  gridded(meuse.grid) = TRUE
  meuse.grid <- raster(meuse.grid)

  cadmium.kde <- sp.kde(x = meuse, y = meuse$cadmium, newdata = meuse.grid, 
                        bw = 1000, standardize = TRUE, scale.factor = 10000  )

Plot results

dev.new()                     
  plot(cadmium.kde, main="weighted kde")
    points(meuse, pch=20, cex=0.5, col="red")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.