Hello Applied Epi Community
I am attempting to create a heat map (chlorophyll map) as a plot map using ggplots. I have created this with a base map, but how do I write code to create a chlorophyll map with a plot map using ggplots?
I am attempting to map out hospitals in my county, color coded based on their hospital bed size range.
Here is the the plot and base code I have:
#Here is my plot code for a plot map for color by hospital bed size
ggplot() +
geom_sf(data = City_Boundaries_Lines, fill=“white”) +
geom_sf(data = LA_county_hospital_data_sf, mapping = aes(color = bed_size_range), alpha = 0.5) +
labs(color = “Bed Size Range”,
title = "Hospital Bed Size Ranges in LA County ")
Here is my base code for a heat map based on hospital bed size
ggplot() +
geom_spatraster_rgb(data = base_osm_cropped) + # plot basemap
geom_sf(data = sle_adm3_cropped, fill = NA) + # cropped county boundaries, empty
geom_sf(data = LA_county_hospital_data_sf, # hospital points
alpha = 0.7) + # semi-transparent
geom_sf(data = LA_county_hospital_data_sf, mapping = aes(color = bed_size_range), alpha = 0.5) +
labs(color = “Bed Size Range”,
title = "Hospital Bed Size Ranges in LA County ")
#Hospital Bed Size Range Heat Map
SL_density ← pointdensity(df = LA_county_hospital_data, # linelist data (NOT AN “sf” object)
lat_col = “LATITUDE”, # latitude data from surv dataframe
lon_col = “LONGITUDE”, # longitude data from surv dataframe
grid_size = 0.1, # how the map grid is divided
radius = 1) # kilometre radius used for point density, change to 1.6 for 1 mile
ggplot() +
basemap for ggplot first layer
geom_spatraster_rgb(data = base_osm_cropped) +
point density points from pointdensity function
geom_point(data = SL_density, aes(x = lon, y = lat, colour = count), shape = 16, size = 8, alpha = 0.5) +
eliminate grey area edges of basemap
coord_sf(expand = FALSE) +
introduce cleaner theme for ggplot
theme_void() +
color gradient of points based on density
scale_colour_gradient(low = “green”, high = “red”) +
label for color on legend
labs(color = “Density count\nper 1km radius”) +
add scale bar and north arrow
annotation_scale(location = “bl”) + # add scale to bottom-left
annotation_north_arrow(location = “br”, # add north arrow to bottom-right
height = unit(0.5, “cm”), # size of north arrow
width = unit(0.5, “cm”))