Source:The UN Refugee Agency
---
title: "ANLY 512 Lab Dashboarding"
author: "Xiaoxi Yang"
output:
flexdashboard::flex_dashboard:
source_code: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
library(dplyr)
library(ggplot2)
library(ggthemes)
library(rworldmap)
library(scales)
library(RColorBrewer)
completeData=read.csv("/Users/xiaoxiyang/Downloads/unhcr_popstats_export_demographics_2018_07_06_200215.csv")
latest<-filter(completeData, completeData$Year==2017)
#summary(latest)
CName<-unique(latest$countryName)
clean <- function(x){
as.numeric( gsub('[^0-9]', '0', x))
}
FDdata <- sapply(latest$F..Total, clean)
MDdata <- sapply(latest$M..Total, clean)
latest$total<-(FDdata+MDdata)
countryBasedData<-group_by(latest,latest$countryName)
countryTotal<-aggregate(countryBasedData$total, by=list(countryName=countryBasedData$countryName), FUN=sum)
countryTotal<-data.frame(countryTotal)
sPDF <- joinCountryData2Map(countryTotal
, joinCode='NAME'
, nameJoinColumn='countryName'
, verbose='TRUE')
history<-completeData
summary(history)
CName<-unique(history$countryName)
clean <- function(x){
as.numeric( gsub('[^0-9]', '0', x))
}
FDdata <- sapply(history$F..Total, clean)
MDdata <- sapply(history$M..Total, clean)
history$total<-(FDdata+MDdata)
hiscountryBasedData<-group_by(history,history$countryName)
hiscountryTotal<-aggregate(hiscountryBasedData$total, by=list(countryName=hiscountryBasedData$countryName), FUN=sum)
hiscountryTotal<-data.frame(hiscountryTotal)
hissPDF <- joinCountryData2Map(hiscountryTotal
, joinCode='NAME'
, nameJoinColumn='countryName'
, verbose='TRUE')
```
Column {data-width=500, .tabset}
-----------------------------------------------------------------------
Source:[The UN Refugee Agency](http://popstats.unhcr.org/)
### 2017 Total Refugees by Country of Origin
```{r}
colourPalette <- RColorBrewer::brewer.pal(4,"YlGnBu")
mapParams <- mapCountryData(sPDF
,nameColumnToPlot="x"
,addLegend=TRUE
,catMethod="logFixedWidth"
,colourPalette=colourPalette
,mapTitle="2017 Total Refugees by Country of Origin")
```
### Historical Total Refugees by Country of Origin
```{r}
colourPalette <- RColorBrewer::brewer.pal(4,"YlGnBu")
mapParams <- mapCountryData(hissPDF
,nameColumnToPlot="x"
,addLegend=TRUE
,catMethod="logFixedWidth"
,colourPalette=colourPalette
,mapTitle="2001-2017 Total Refugees by Country of Origin")
```
Column {data-width=350}
-----------------------------------------------------------------------
Source:[The UN Refugee Agency](http://popstats.unhcr.org/)
### Number of Refugees Resettlement by Year
```{r}
completeData=read.csv("/Users/xiaoxiyang/Downloads/unhcr_popstats_export_demographics_2018_07_06_200215.csv")
FDdata_2 <- subset(completeData, select=c("Year", "F..Total"))
FDdata_2$Gender <- "Female"
colnames(FDdata_2) <- c("Year", "Total", "Gender")
MDdata_2 <- subset(completeData, select=c("Year", "M..Total"))
MDdata_2$Gender <- "Male"
colnames(MDdata_2) <- c("Year", "Total", "Gender")
groupdata <- rbind(FDdata_2, MDdata_2)
groupdata$Total <- as.numeric(as.character(groupdata$Total))
groupdata <- aggregate(. ~ Year + Gender, data=groupdata, FUN=sum)
ggplot(aes(x=Year, y=Total, fill=Gender), data=groupdata) +
geom_bar(stat="identity") +
xlab("Year") +
ylab("Numbers")
```
Source:[Refugee Processing Center](http://www.wrapsnet.org/admissions-and-arrivals/)
### Top 10 Languages Spoken by Arrived Refugees
```{r}
completeData=read.csv("/Users/xiaoxiyang/Downloads/Top+Ten+Refugee+Native+Languages.csv")
language_data<-subset(completeData, select=c("NativeLanguage", "CumulativeTotal"))
colourCount = 10
getPalette = colorRampPalette(brewer.pal(9, "Blues"))
ggplot(aes(x="", y=language_data$CumulativeTotal,fill=language_data$NativeLanguage), data=language_data) +
geom_bar(stat="identity") +
coord_polar("y", start=0) +
scale_fill_manual(values = getPalette(colourCount))
```