Problem with merging my data with the map and visualise the maximum.

incidents_per_suburb <- q6 %>%
group_by(Suburb) %>%
summarise(total_incidents = sum(Count)) %>%

merged_data <- cross_join(incidents_per_suburb, map)

suburb_most_incidents <- merged_data[which.max(merged_data$total_incidents), "Suburb"]


suburb_most_incidents <- merged_data[which.max(merged_data$total_incidents), "Suburb"]

Map1 <- ggplot(merged_data, aes(x= long, y= lat, group==group)) +
geom_polygon(aes(fill = "#69b3a2", color = "white")) +
geom_text(data = merged_data, aes(label = ifelse(Suburb == suburb_most_incidents, Suburb, "")),
size = 3, color = "black", check_overlap = TRUE) +
theme_void() +
coord_map() +
labs(title = "Incidents per Suburb")


Hi, it is difficult to work out what is going on without a reproducible example - difficult for spatial data too, though you could create an aspatial example. Does suburb_most_incidents look like what you're after? You could probably add that to merged_data with an if_else() and avoid the at whole section.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.