For the below overlay bar chart I am a bit confused on why I cant order it so that female is above male. Currently my research has shown that leveraging mutate I can create a factored column, and simply pass the desired levels. However, no matter the order I am still getting male on top and female on bottom.
Please see example data below.
# Data
clm <- c("covid","covid","all","all")
sex <- c("female","male","female","male")
percent <- c(0.6, 0.2, .4, .8)
# Colors
dark <- '#008AFE' # blue
lightest <-'#CCE8FF'
light_accent <-'#FFCB93' #peachy
lightest_accent <- '#FFE5C9'
df <- data.frame("clm" = clm,"sex" = sex, "percent" = percent)
gender_claim <- df %>%
arrange(percent) %>%
mutate(sex=factor(sex, levels = c("male","female"))) %>%
ggplot(aes(x = sex, y = percent)) +
geom_col(data = df[(df$sex == "female") &
(df$clm == "all"), ],
fill = lightest_accent, width = .25) +
geom_col(data = df[(df$sex == "female") &
(df$clm == "covid"), ],
fill = dark, width = .15) +
geom_col(data = df[(df$sex == "male") &
(df$clm == "all"), ],
fill = lightest_accent, width = .25) +
geom_col(data = df[(df$sex == "male") &
(df$clm == "covid"), ],
fill = dark, width = .15) +
scale_y_continuous(limits = c(0, 1), breaks = seq(0, 1, by = .25),
labels = function(y) paste0(round(y*100,0),"%"),
seq(0, 1, by = .25),expand = expansion(mult = c(0, 0))) +
coord_flip()