I want to make a barplot with 2 variables.
I have a variable called "sexe" and the second is called "surchage_mentale". And i want this type of graph :
But with yes : women/men, and no : women/men
df <- structure(list(sexe = c("women", "men", "women", "men", "women", "men", "women", "men"), surcharge_mentale = c("yes", "yes", "no", "yes", "yes", "no", "yes", "yes")
sexe_surchargementale <- df %>% select(sexe, surcharge_mentale)
#first method
ggplot(sexe_surchargementale, aes(x = "surcharge_mentale", fill = "sexe")) +
geom_bar(position = "dodge")
#second method
sexe_surchargementale %>%
pivot_longer(everything(), names_to = "name", values_to = "response") %>%
group_by(name, response) %>%
summarise(cnt = n()) %>%
ggplot(aes(x = name, y = cnt, fill = response)) +
geom_bar(stat = "identity", position = "dodge") +
labs(title="")
I put a sample of my Data. The first method doesn't work and I don't understand why, I'm complety lost.


aes(x = surcharge_mentale, fill = sexe)instead ofaes(x = "surcharge_mentale", fill = "sexe").")