The graph is about Rwanda. The country is located in East Africa and it is one of the smallest countries on the African mainland. Rwanda is a less developed country and the data shows the demographic features of the country. It consists of Male and Female population in 2007. By using R-studio, we visualized the data by using bars. Y-axis shows “Age” and X-axis shows “Number of Population”. To visualize Male and Female in the same graph we used negative number for Male population. In addition, we had a problem with R studio’s default factor settings. To solve the problem we used “forcats” by re-ordering factor levels as they appear in the data table.

Load tidyverse and data

library(tidyverse)
## Loading tidyverse: ggplot2
## Loading tidyverse: tibble
## Loading tidyverse: tidyr
## Loading tidyverse: readr
## Loading tidyverse: purrr
## Loading tidyverse: dplyr
## Conflicts with tidy packages ----------------------------------------------
## filter(): dplyr, stats
## lag():    dplyr, stats
library(XML)
#library(plyr)
#library(reshape2)
library(tidyr)
library(ggthemes)
library(forcats)

rwanda_Pop <- read.csv("https://raw.githubusercontent.com/seung-taeko/mini-project-1/master/Rwanda%20popPyramid.csv?token=AZevOB5LeYQ-kvQ4HsV9WqHT_eWCmAbSks5Y9OXHwA%3D%3D", as.is = TRUE)

Filter and modify data for different years

rwanda_2007 <- filter(rwanda_Pop, Year == "2007")
rwanda2 <- gather(rwanda_2007, key = "sex", value = "number", Male, Female)
rwanda2$number <- extract_numeric(rwanda2$number)
## extract_numeric() is deprecated: please use readr::parse_number() instead
rwanda_2008 <- filter(rwanda_Pop, Year == "2008")
rwanda3 <- gather(rwanda_2008, key = "sex", value = "number", Male, Female)
rwanda3$number <- extract_numeric(rwanda3$number)
## extract_numeric() is deprecated: please use readr::parse_number() instead
rwanda_2009 <- filter(rwanda_Pop, Year == "2009")
rwanda4 <- gather(rwanda_2009, key = "sex", value = "number", Male, Female)
rwanda4$number <- extract_numeric(rwanda4$number)
## extract_numeric() is deprecated: please use readr::parse_number() instead
rwanda_2010 <- filter(rwanda_Pop, Year == "2010")
rwanda5 <- gather(rwanda_2010, key = "sex", value = "number", Male, Female)
rwanda5$number <- extract_numeric(rwanda5$number)
## extract_numeric() is deprecated: please use readr::parse_number() instead
rwanda_2011 <- filter(rwanda_Pop, Year == "2011")
rwanda6 <- gather(rwanda_2011, key = "sex", value = "number", Male, Female)
rwanda6$number <- extract_numeric(rwanda6$number)
## extract_numeric() is deprecated: please use readr::parse_number() instead

Plot the graph with refactored the age groups

RWgraph07 <-
  ggplot(data = rwanda2, mapping = aes(x = fct_inorder(rwanda2$Age, ordered = NA), fill = sex)) +
  geom_bar(aes(y = number), stat = "identity") +
  coord_flip() +
  labs(x = "Age", y = "Population",
       title = "Population Pyramid of Rwanda",
       subtitle = "From year 2007 to 2011") +
  geom_text(x = 82, y = 160000, label = "2007", size = 15) +
  theme(axis.text.y = element_blank())
RWgraph07

RWgraph08 <-
  ggplot(data = rwanda3, mapping = aes(x = fct_inorder(rwanda3$Age, ordered = NA), fill = sex)) +
  geom_bar(aes(y = number), stat = "identity") +
  coord_flip() +
  labs(x = "Age", y = "Population",
       title = "Population Pyramid of Rwanda",
       subtitle = "From year 2007 to 2011") +
  geom_text(x = 82, y = 160000, label = "2008", size = 15) +
  theme(axis.text.y = element_blank())
RWgraph08

RWgraph09 <-
  ggplot(data = rwanda4, mapping = aes(x = fct_inorder(rwanda4$Age, ordered = NA), fill = sex)) +
  geom_bar(aes(y = number), stat = "identity") +
  coord_flip() +
  labs(x = "Age", y = "Population",
       title = "Population Pyramid of Rwanda",
       subtitle = "From year 2007 to 2011") +
  geom_text(x = 82, y = 160000, label = "2009", size = 15) +
  theme(axis.text.y = element_blank())
RWgraph09

RWgraph10 <-
  ggplot(data = rwanda5, mapping = aes(x = fct_inorder(rwanda5$Age, ordered = NA), fill = sex)) +
  geom_bar(aes(y = number), stat = "identity") +
  coord_flip() +
  labs(x = "Age", y = "Population",
       title = "Population Pyramid of Rwanda",
       subtitle = "From year 2007 to 2011") +
  geom_text(x = 82, y = 160000, label = "2010", size = 15) +
  theme(axis.text.y = element_blank())
RWgraph10

RWgraph11 <-
  ggplot(data = rwanda6, mapping = aes(x = fct_inorder(rwanda6$Age, ordered = NA), fill = sex)) +
  geom_bar(aes(y = number), stat = "identity") +
  coord_flip() +
  labs(x = "Age", y = "Population",
       title = "Population Pyramid of Rwanda",
       subtitle = "From year 2007 to 2011") +
  geom_text(x = 82, y = 160000, label = "2011", size = 15) +
  theme(axis.text.y = element_blank())
RWgraph11

The results show that Rwanda’s population graph in 2007 is an expansive population pyramids because proportion of young population is relatively large.

The result also suggests that Rwanda has high fertility rate and low average life expectancy, as the triangular shape of the graph suggests.