I was given this dataframe, which is at the same time a frequency distribution, and was given a task of plotting a histogram of the age distribution of the whole population adding to the plot the male and female profile. What I need to achieve is a histogram like this one for example: Two-variable frequency bar plot with the male and female profile overlapping, but with the AgeClasses on the x axis. This is my code:
AgeClasses <- c('0-9','10-19','20-29','30-39','40-49', '50-59', '60-69','70-79','80-89', '90-99')
Frequencies <- c(1000,900,800,700,600,500,400,300,200,100)
SexRatioFM <- c(0.4,0.42,0.44,0.48,0.52,0.54,0.55,0.58,0.6,0.65)
df$Females <- c(SexRatioFM*Frequencies)
df$Males <- c(Frequencies-Females)
library(ggplot2)
ggplot(df) +
geom_bar(mapping = aes(x = AgeClasses, y = Females), stat = "identity")
I would really appreciate your help in solving this task.