I’m trying to display proportions to a map – I had previously used this code at a state level but now that I’ve gone down to an SA4 level the legend is playing up.
I’ve read several other posts where the suggestion has been to add drop = FALSE
but my code already has this, so is there something else I’m missing?
My code is in a function because I reproduce many different iterations of this map and parse the values through x
aus_shp<- read_sf("map files/SA4_2021_AUST_GDA2020.shp")
exclude_list <- c('Other Territories')
aus_shp$x <- rep(0,1)
my_colours<- c("#FFFFFF","#D3D3D3","#00B050", "#92D050", "#FFFFB2", "#FED976", "#FEB24C", "#FD8D3C", "#F03B20", "#BD0026")
scale_theme<- function(...){
scale_fill_manual(
values = my_colours,
breaks = waiver(),
limits = levels(aus_shp$x),
labels = c("not availailable","<30 reports", "<1%", "1-<5%", "5-<10%", "10-<15%", "15-<20%", "20-<25%", "25-50%", ">50%"),
name = "% R",
guide = guide_legend(override.aes = list (color = NA), reverse = TRUE),
drop = F)}
state_map<- function(...){
aus_shp$x <- cut(x,
breaks = c(-Inf, 0, 0.1, 1, 5, 10, 15, 20, 25, 50, 100),
right = FALSE)
ggplot(data = aus_shp) +
geom_sf(aes(fill = x))+
theme_void()+
scale_theme()}
x<- runif(108, min = 5, max = 49)
state_map()
For the dummy x variable I’ve generated random data with limits that can replicate the error I come across with my actual data. Please note that the <30 category is coded as 0.0 and the “not available” is coded as 0.1 but doesn’t show in this random example.
You see in this map the categories for <5 and >49 are not showing…
Any ideas?
Thanks in advance