Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # population of regions (%) by age group
- # call libraries
- library(ggplot2)
- library(ggthemes)
- library(tidyr)
- library(plyr)
- # install data
- data14 <- read.table("http://pastebin.com/raw/yZPV2abS", sep=",", header=T, check.names=F)
- data15_64 <- read.table("http://pastebin.com/raw/Afpt8KqG", header=T, sep=",", check.names=F)
- data65 <- read.table("http://pastebin.com/raw/WQhuR4Bz", header=T, sep=",", check.names=F)
- # wide to long
- data14.long <- gather(data14, year, rate0_14, c(3:9), factor_key=TRUE)
- data14.long$year <- as.numeric(as.character(data14.long$year))
- data15_64.long <- gather(data15_64, year, rate15_64, c(3:9), factor_key=TRUE)
- data15_64.long$year <- as.numeric(as.character(data15_64.long$year))
- data65.long <- gather(data65, year, rate65, c(3:9), factor_key=TRUE)
- data65.long$year <- as.numeric(as.character(data65.long$year))
- # choose a region
- chooseregion <- "青森市"
- # get the data
- data14.long.region <- data14.long %>% dplyr::filter(region == chooseregion)
- data15_64.long.region <- data15_64.long %>% dplyr::filter(region == chooseregion)
- data65.long.region <- data65.long %>% dplyr::filter(region == chooseregion)
- # merge the age groups
- dataall.long.region <- merge(data14.long.region, merge(data15_64.long.region, data65.long.region))
- # print the data of the city
- dataall.long.region
- # wide to long
- dataall.long.region <- gather(dataall.long.region, group, rate, c(4:6), factor_key=TRUE)
- # plot
- p1 = ggplot(aes(y = rate, x = year, fill = group), data = dataall.long.region) +
- geom_area()+
- ggtitle(chooseregion) +
- labs(x="Year",y="percentage") +
- theme(plot.title = element_text(family = "Trebuchet MS", color="#666666", face="bold", size=16, hjust=0)) +
- theme(axis.title = element_text(family = "Trebuchet MS", color="#666666", face="bold", size=14)) +
- theme_bw(base_family = "HiraKakuProN-W3")
- p1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement