incidents_per_suburb <- q6 %>%
group_by(Suburb) %>%
summarise(total_incidents = sum(Count)) %>%
arrange(desc(total_incidents))
merged_data <- cross_join(incidents_per_suburb, map)
suburb_most_incidents <- merged_data[which.max(merged_data$total_incidents), "Suburb"]
head(merged_data)
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")
Map1
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.
A minimal reproducible example consists of the following items:
A minimal dataset, necessary to reproduce the issue
The minimal runnable code necessary to reproduce the issue, which can be run
on the given dataset, and including the necessary information on the used packages.
Let's quickly go over each one of these with examples:
Minimal Dataset (Sample Data)
You need to provide a data frame that is small enough to be (reasonably) pasted on a post, but big enough to reproduce your issue.
Let's say, as an example, that you are working with the iris data frame
head(iris)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1 5.1 3.5 1.4 0.…
system
Closed
March 11, 2024, 2:44am
3
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.