1

I am making a heat map of flooding incidents in the UK. I am following the example listed here. However, I am using a different base map from the example and it won't show up on the map. For my base map I use shapefiles provided by the UK gov, found here, and named it uk.shp, an sf object. Flooding data is proprietary and I cannot share but the original format is polygon shapefile. I then turn those shapefiles into gridded points so I can plot a continuous heat map, this sf object is named pt.shp.

Here is the the base map, original shapefile, and gridded points overlaid for context. You can see there are many floods here, often laying under the same point. I constructed a grid sf object that repeats a given point and uses flood ID as the unique identifier. Below is an example of the data with proprietary information removed. One possible issue I can think of is st_intersection returned the lat and long of the flooding shapefile (which I set as the mapping aes()) but the point's mapping coords are listed in the geometry column of the data. enter image description here

enter image description here

However, when I use stat_density2d() with my base map, the continuous plot disappears. Below is my plotting code w/ each mapping iteration.

# base map plots
base <- ggplot()+
  geom_sf(data=uk.shp)

enter image description here

# Plot density of the points
ggplot()+
  stat_density2d(data=pt.shp, aes(x=long, y=lat, fill = ..density..), geom='tile', contour = F)

enter image description here

# base map shows up w/o density map? But legend exists so it is being mapped... 
base +
    stat_density2d(data=pt.shp, aes(x=long, y=lat, fill = ..density..), geom='tile', contour = F, alpha = .5) +
    viridis::scale_fill_viridis(option='inferno')

enter image description here

Some issues are clear, like the plotting window of the heatmap has different dimensions than the base map. However, my main issues is I can't overlay the two plots and I don't know why.

DPek
  • 180
  • 2
  • 15

0 Answers0