Hi,
I want to do something like these
I have some countrys that reach two different values and those one, i need to add a "stripe" pattern above the solid colour, so colour=first value and stripe=second value. But i am not been able so far, to do both. The two values are in diferent columns.
Maybe you have some ideas??
Hi, Does it have to be stripes? You could use biscale
.
First attempt :
library(tidyverse)
library( maps)
library(ggpattern)
library(cowplot)
crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests)
states_map <- map_data("state")
crimes$second_val <- forcats::fct_na_value_to_level(ifelse(crimes$Murder>15,"Yes",NA),
level = ("Missing"))
(states_needing_patterns <- crimes |> filter(second_val != "Missing") |> pull(state))
#legend hacks
pattern_leg <- cowplot::get_legend(ggplot(crimes, aes(map_id = state)) +
geom_map_pattern(
map = states_map,
pattern_fill = 'red',
pattern_aspect_ratio = 1.75,
colour = 'black',
fill="white",
aes(pattern=second_val)
) +scale_pattern_manual(
values=c("Yes"="stripe",
"Missing"="none")
)
)
fill_leg <- cowplot::get_legend(main_p <- ggplot(crimes, aes(map_id = state,
fill=Assault)) +
geom_map(
map = states_map,
aes(fill = Assault)
))
main_p <- ggplot(crimes, aes(map_id = state,fill=Assault)) +
geom_map_pattern(
map = states_map,
pattern_fill = 'red',
pattern_aspect_ratio = 1.75,
colour = 'black',
aes(pattern=second_val)
) +scale_pattern_manual(
values=c("Yes"="stripe",
"Missing"="none")
) +
expand_limits(x = states_map$long, y = states_map$lat) +
coord_map()+
theme(legend.position = "none")
plot_grid(plotlist = list(
main_p,
plot_grid(plotlist = list(NULL,pattern_leg,
fill_leg,NULL
),nrow=4,ncol=1,rel_heights = c(1,5,5,3))),
nrow =1,ncol=2,rel_widths = c(3,1))
1 Like
Thank you for the idea, I calculated the over all mortality so if a divide the country I would have to explain that is only for representation, it does not means that the half of the country rich one mortality and the other half the other one. I will considered like an option! thank you!!
This topic was automatically closed 42 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.