I have posted this question another time and gave one answer but when I did again I did not give same output.
I have a data frame named mydata
which contains population for different country
.
df<- data_frame(age= c(0,5,10,15,20,25,30,35,40,45,50,55,60,65,70), gender = "male",
population =c(180,160,130,140,150,160,170,90,85,80,75,70,65,60,40), country = 1)
df1<- data_frame(age= c(0,5,10,15,20,25,30,35,40,45,50,55,60,65,70), gender = "female",
population =c(160,150,120,130,140,150,160,80,75,70,65,60,55,50,30),country = 1)
df2<- data_frame(age= c(0,5,10,15,20,25,30,35,40,45,50,55,60,65,70), gender = "male",
population =c(80,77,66,65,69,69,54,50,44,40,38,29,20,12,8), country = 2)
df3<- data_frame(age= c(0,5,10,15,20,25,30,35,40,45,50,55,60,65,70), gender = "female",
population =c(76,70,61,63,60,51,41,39,37,33,30,28,23,22,10), country = 2)
df4<- data_frame(age= c(0,5,10,15,20,25,30,35,40,45,50,55,60,65,70), gender = "male",
population =c(29,27,30,26,24,22,20,18,16,14,12,10,8,6,4), country = 3)
df5<- data_frame(age= c(0,5,10,15,20,25,30,35,40,45,50,55,60,65,70), gender = "female",
population =c(28,24,20,22,23,24,22,21,20,18,16,13,12,10,6), country = 3)
mydata<- rbind(df,df1,df2,df3,df4,df5)
in the code below, I got a population pyramid for three countries. because of different number of population in each country, my population pyramids are different visually and not comparable, how can I change y axis so that I have a comparable population pyramid?
ggplot(data=mydata, aes(x=age, y = ifelse(gender == "male", -population, population), fill=gender)) +
geom_col() +
facet_wrap(~country) +
coord_flip()