Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Script population of regions in japan by age group (%)
- # call libraries
- library(ggplot2)
- library(ggthemes)
- library(tidyr)
- library(plyr)
- # 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
- data14.long.region <- data14.long %>% dplyr::filter(region == "桑名市")
- data15_64.long.region <- data15_64.long %>% dplyr::filter(region == "桑名市")
- data65.long.region <- data65.long %>% dplyr::filter(region == "桑名市")
- # 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()
- p1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement