yy <- spTransform(master_buf, proj4string(bohemia::mop2))
xx <- spTransform(master_hull, proj4string(bohemia::mop2))
# Calculate areas of cores
xx@data$core_area_m2 <- geosphere::areaPolygon(x = xx)
yy@data$buffer_area_m2 <- geosphere::areaPolygon(x = yy)
# Get number of people in each cluster
np <- hh_level %>%
dplyr::distinct(hh_id, .keep_all = TRUE) %>%
group_by(cluster) %>%
summarise(people_in_core = sum(n_members[status == 'core']),
people_in_buffer = sum(n_members[status == 'buffer']),
people = sum(n_members))
# Join everything together
xx@data <- left_join(xx@data, np)
yy@data <- left_join(yy@data, np)
yy@data <- left_join(yy@data, xx@data)
yy@data$buffer_area_m2 <- yy@data$buffer_area_m2 - yy@data$core_area_m2
MAP
l <- leaflet(width = '100%') %>%
addProviderTiles(providers$Esri.WorldStreetMap) %>%
addPolygons(data = yy,
color = 'black',
fillColor = 'grey',
fillOpacity = 0.3,
popup = popupTable(yy@data),
label = paste0('Cluster number ', yy@data$cluster,
'. People in buffer: ', yy@data$people_in_buffer,
'. Buffer area: ',
round(yy@data$buffer_area_m2/1000000, 2), ' squared km')
) %>%
addPolygons(data = xx,
stroke = 0,
fillColor = 'red',
fillOpacity = 0.5,
color = 'red',
weight = 1,
popup = popupTable(xx),
label = paste0('Cluster number ', xx@data$cluster, '. People in core: ', xx@data$people_in_core,
'. Core area: ', round(xx@data$core_area_m2/1000000, 2), ' squared km'))
l