I use the code dput(head(Refugees_demographics, 2))
and here is the sample dataset below:
structure(list(Year = c(2006, 2007), `Female 0-4` = c(0, 3),
`Female 5-11` = c(0, 0), `Female 12-17` = c(140, 36), `Female 18-59` = c(1118,
519), `Female 60+` = c(121, 85), `F: Total` = c(1379, 643
), `Male 0-4` = c(0, 7), `Male 5-11` = c(6, 1), `Male 12-17` = c(152,
56), `Male 18-59` = c(1323, 870), `Male 60+` = c(595, 88),
`M: Total` = c(2076, 1022)), row.names = c(NA, -2L), class = c("tbl_df",
"tbl", "data.frame"))
I would like to get the following stacked bar chart. (like the photo)
The x-axis would be the year, and the y-axis would be the number of number of refugees. Each year would have two stacked bars. One for male and one for female. Within each bar, it's stacked by their age, i.e. female0-4, female 5-11...etc.
I tried to use the following code but it didn't work and I also have no idea how to group female and male by year.
ggplot() +
geom_bar(aes(y = Refugees_demographics$`Female 0-4`,
x = Refugees_demographics$Year, fill = product),
data = Refugees_demographics, stat="identity")
If someone could help this, I will be greatly appreciated!
Thank you in advance.