options(scipen=999)
library(ggplot2)
## Warning in as.POSIXlt.POSIXct(Sys.time()): unknown timezone 'zone/tz/2019b.
## 1.0/zoneinfo/Australia/Sydney'
pop = read.csv("~/Dropbox/Science Evaluation/Dan so Vietnam/Dan so VN 1979 - 2019 Long.csv")
pop$Age.group = as.factor(pop$Age.group)
pop$Age.group = factor(pop$Age, levels=unique(pop$Age.group))
pop$Gender = factor(pop$Gender, levels=c("Male", "Female"))
Age = c(rep("65+", 5), rep("0-14", 5), rep("15-64", 5))

Num = c(4.7, 4.8, 5.8, 6.4, 7.7, 42.6, 38.3, 33.1, 24.5, 23.1, 52.7, 56.9, 61.1, 69.1, 69.2)

Year = c(1979, 1989, 1999, 2009, 2019, 1979, 1989, 1999, 2009, 2019, 1979, 1989, 1999, 2009, 2019) 

dat = data.frame(Age, Num, Year)

dat$Age = factor(dat$Age, levels=c("65+", "15-64", "0-14"))

library(ggplot2)

# Area plot
p = ggplot(data=dat, aes(x=Year, y=Num)) 
p = p + geom_area(aes(fill = Age))
p + ylab("Percent") + theme(legend.position="top")

# Stack bar plot with actual value 
p = ggplot(data=dat, aes(x=Year, y=Num, fill=Age, label=Num))
p = p + geom_bar(stat="identity")
p + geom_text(size=3, position=position_stack(vjust=0.5)) + ylab("Percent") + theme(legend.position="top")

Plotting data

p = ggplot(data=pop, aes(x=Age.group, fill=Gender, y=ifelse(test=Gender=="Male", yes=-pop1979, no=pop1979))) 
p = p + geom_bar(stat = "identity") + coord_flip()
p + xlab("") + ylab("Population 1979") + theme(legend.position="top")

p = ggplot(data=pop, aes(x=Age.group, fill=Gender, y=ifelse(test=Gender=="Male", yes=-pop2009, no=pop2009))) 
p = p + geom_bar(stat = "identity") + coord_flip()
p + xlab("") + ylab("Population 2009") + theme(legend.position="top")

p = ggplot(data=pop, aes(x=Age.group, fill=Gender, y=ifelse(test=Gender=="Male", yes=-pop2019, no=pop2019))) 
p = p + geom_bar(stat = "identity") + coord_flip()
p + xlab("") + ylab("Population 2019") + theme(legend.position="top")

Plotting percentage data

p = ggplot(data=pop, aes(x=Age.group, fill=Gender, y=ifelse(test=Gender=="Male", yes=-pc1979, no=pc1979))) 
p = p + geom_bar(stat = "identity") + coord_flip()
p1 = p + xlab("") + ylab("Population 1979") + theme(legend.position="top", axis.text.x=element_text(size=8))

p = ggplot(data=pop, aes(x=Age.group, fill=Gender, y=ifelse(test=Gender=="Male", yes=-pc1999, no=pc1999))) 
p = p + geom_bar(stat = "identity") + coord_flip()
p2 = p + xlab("") + ylab("Population 1999") + theme(legend.position="top", axis.text.x=element_text(size=8))

p = ggplot(data=pop, aes(x=Age.group, fill=Gender, y=ifelse(test=Gender=="Male", yes=-pc2009, no=pc2009))) 
p = p + geom_bar(stat = "identity") + coord_flip()
p3 = p + xlab("") + ylab("Population 2009") + theme(legend.position="top", axis.text.x=element_text(size=8))

p = ggplot(data=pop, aes(x=Age.group, fill=Gender, y=ifelse(test=Gender=="Male", yes=-pc2019, no=pc2019))) 
p = p + geom_bar(stat = "identity") + coord_flip()
p4 = p + xlab("") + ylab("Population 2019") + theme(legend.position="top", axis.text.x=element_text(size=8))

library(gridExtra)
## Warning: package 'gridExtra' was built under R version 3.4.1
grid.arrange(p1, p2, p3, p4, ncol=2)