{"id":22966583,"url":"https://github.com/favstats/usa_refugee_data","last_synced_at":"2026-01-27T11:05:34.224Z","repository":{"id":108352023,"uuid":"149364113","full_name":"favstats/usa_refugee_data","owner":"favstats","description":"Visualizing Refugee Influx in the United States","archived":false,"fork":false,"pushed_at":"2019-04-27T11:13:46.000Z","size":19329,"stargazers_count":27,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-03T22:06:48.225Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/favstats.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-18T23:27:28.000Z","updated_at":"2025-02-20T18:39:43.000Z","dependencies_parsed_at":"2023-05-21T23:30:29.410Z","dependency_job_id":null,"html_url":"https://github.com/favstats/usa_refugee_data","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/favstats/usa_refugee_data","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favstats%2Fusa_refugee_data","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favstats%2Fusa_refugee_data/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favstats%2Fusa_refugee_data/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favstats%2Fusa_refugee_data/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/favstats","download_url":"https://codeload.github.com/favstats/usa_refugee_data/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favstats%2Fusa_refugee_data/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28812367,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T07:41:26.337Z","status":"ssl_error","status_checked_at":"2026-01-27T07:41:08.776Z","response_time":168,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-14T20:44:45.966Z","updated_at":"2026-01-27T11:05:34.211Z","avatar_url":"https://github.com/favstats.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"Accepted Refugees United States\n================\nFabio Votta\n21.09.2018\n\nData from:\n\u003chttp://ireports.wrapsnet.org/Interactive-Reporting/EnumType/Report?ItemPath=/rpt_WebArrivalsReports/MX%20-%20Arrivals%20by%20Nationality%20and%20Religion\u003e\n\n## Packages and Folders\n\n``` r\n# Install these packages if you don't have theme yet\n# devtools::install_github(\"favstats/tidytemplate\")\n# install.packages(\"pacman\")\n\npacman::p_load(tidyverse, readxl, sjmisc)\n\n# Creates folders\n# tidytemplate::data_dir()\n# tidytemplate::images_dir()\n```\n\n## Load Data\n\n``` r\nrefugee_dat \u003c- read_excel(\"data/refugee_dat.xls\") %\u003e% \n  drop_na(X__1) %\u003e% \n  rename(cntry = X__1) %\u003e% \n  select(-Religion, -X__2, -X__3, - Total) %\u003e% \n  filter(!(str_detect(cntry, \"Total|Data\"))) %\u003e% \n  gather(year, n, -cntry) %\u003e% \n  mutate(year = str_replace(year, \"CY \", \"\") %\u003e% as.numeric)\n\nrefugee_dat %\u003e% group_by(cntry) %\u003e% tally() %\u003e% arrange(desc(nn)) %\u003e% .[1:10,] %\u003e% .$cntry -\u003e top10\n```\n\n    ## Using `n` as weighting variable\n\n## Static\n\n``` r\nyear_dat \u003c- tibble(year = c(2005, 2009, 2013, 2017), label = c(\"Bush II\", \"Obama I\", \"Obama II\", \"Trump I\"))\n\n\nrefugee_total \u003c- refugee_dat %\u003e% \n  group_by(year) %\u003e% \n  tally() %\u003e% \n  ggplot(aes(year, nn)) +\n  geom_vline(data = year_dat, aes(xintercept = year), alpha = 0.15) +\n  geom_label(data = year_dat, aes(x = year, y = 100000, label = label), \n            angle = 0, color = \"black\") +\n  geom_line(linetype = \"dashed\") + \n  geom_point() +\n  theme_minimal() +\n  scale_color_manual(\"Country\", values = qualitative) +\n  theme(plot.title = element_text(size = 13, face = \"bold\"),\n    plot.subtitle = element_text(size = 11, face = \"bold\"), \n    plot.caption = element_text(size = 10),\n        legend.position = \"bottom\") +\n  scale_x_continuous(breaks = 2002:2018, labels = 2002:2018) +\n  labs(x = \"\", y = \"Number of Refugees\\n\", \n       title = \"Accepted Refugees in the United States of America by Year (2002 - 2018)\", \n       subtitle = \"Total accepted Refugees in Timerange: 943.338\\n\",\n       caption = \"Data: Department of State, Office of Admissions - Refugee Processing Center\\n@FabioFavusMaxim; favstats.eu\")\n```\n\n    ## Using `n` as weighting variable\n\n``` r\nrefugee_total\n```\n\n[![](https://raw.githubusercontent.com/favstats/usa_refugee_data/master/refugee_analysis_files/figure-gfm/unnamed-chunk-2-1.png)](https://raw.githubusercontent.com/favstats/usa_refugee_data/master/refugee_analysis_files/figure-gfm/unnamed-chunk-2-1.png) \n\n\n``` r\ntidytemplate::ggsave_it(refugee_total, width = 10, height = 6)\n```\n\n## Colored\n\n``` r\nqualitative \u003c- c('#a6cee3','#1f78b4','#b2df8a','#33a02c','#fb9a99','#e31a1c','#fdbf6f','#ff7f00','#cab2d6','#6a3d9a')\n\ngg_refugee_static_data \u003c- refugee_dat %\u003e% \n  filter(cntry %in% top10) \n\nlabel_dat \u003c- gg_refugee_static_data %\u003e% \n  group_by(cntry) %\u003e% \n  summarize(n = max(n)) %\u003e% \n  select(-cntry) %\u003e% \n  inner_join(gg_refugee_static_data)\n```\n\n    ## Joining, by = \"n\"\n\n``` r\ngg_refugee_static \u003c- gg_refugee_static_data %\u003e% \n  ggplot(aes(year, n)) +\n  geom_vline(data = year_dat, aes(xintercept = year), alpha = 0.15) +\n  geom_label(data = year_dat, aes(x = year, y = 22000, label = label), \n            angle = 0, color = \"black\") +\n  geom_line(aes(linetype = cntry, color = cntry)) +\n  theme_minimal() +\n  ggrepel::geom_label_repel(data = label_dat, aes(label = cntry, color = cntry), show.legend = F) + \n  geom_point(data = label_dat, aes(color = cntry)) + \n  scale_color_manual(\"Country\", values = qualitative) +\n  scale_linetype(\"Country\") +\n  theme(plot.title = element_text(size = 13, face = \"bold\"),\n    plot.subtitle = element_text(size = 11, face = \"bold\"), \n    plot.caption = element_text(size = 10),\n    legend.key.width = unit(3, \"line\"),\n    legend.position = \"bottom\") +\n  scale_x_continuous(breaks = 2002:2018, labels = 2002:2018) +\n  labs(x = \"\", y = \"Number of Refugees\\n\", \n       title = \"Accepted Refugees in the United States of America by Year (2002 - 2018)\", subtitle = \"Top 10 Origin Countries\\n\",\n       caption = \"Data: Department of State, Office of Admissions - Refugee Processing Center\\n@FabioFavusMaxim; favstats.eu\") \n  # geom_rect(aes(xmin = 2002, xmax = 2005, ymin = 22000, ymax = 22000),\n  #             color = \"black\",\n  #             alpha = 0.8,\n  #             inherit.aes = FALSE)\n\ngg_refugee_static\n```\n\n[![](https://raw.githubusercontent.com/favstats/usa_refugee_data/master/refugee_analysis_files/figure-gfm/unnamed-chunk-3-1.png)](https://raw.githubusercontent.com/favstats/usa_refugee_data/master/refugee_analysis_files/figure-gfm/unnamed-chunk-3-1.png) \n\n``` r\ntidytemplate::ggsave_it(gg_refugee_static, width = 12, height = 8)\n```\n\n## Animated\n\n``` r\nlibrary(gganimate)\n\ngg_refugee \u003c- refugee_dat %\u003e%\n  filter(cntry %in% top10) %\u003e%\n  ggplot(aes(year, n, color = cntry)) +\n  geom_vline(data = year_dat, aes(xintercept = year), alpha = 0.15) +\n  geom_label(data = year_dat, aes(x = year, y = 22000, label = label),\n            angle = 0, color = \"black\") +\n  geom_line() +\n  geom_segment(aes(xend = 2018, yend = n), alpha = 0.5) +\n  geom_point() +\n  geom_text(aes(x = 2019, label = cntry)) +\n  theme_minimal() +\n  scale_color_manual(\"Country\", values = qualitative) +\n  theme(plot.title = element_text(size = 13, face = \"bold\"),\n    plot.subtitle = element_text(size = 12, face = \"bold\"),\n    plot.caption = element_text(size = 10),\n        legend.position = \"bottom\") +\n  scale_x_continuous(breaks = 2002:2018, labels = 2002:2018) +\n  labs(x = \"\", y = \"Number of Refugees\\n\",\n       title = \"Accepted Refugees in the United States of America by Year (2002 - 2018)\", subtitle = \"Top 10 Origin Countries\\n\",\n       caption = \"Data: Department of State, Office of Admissions - Refugee Processing Center\\n@FabioFavusMaxim; favstats.eu\")  +\n  guides(color = F, text = F) +\n  transition_reveal(cntry, year, keep_last = T)\n\ngg_refugee %\u003e% animate(\n  nframes = 500, fps = 15, width = 1000, height = 600, detail = 1\n)\n\nanim_save(\"images/gg_refugee.gif\")\n```\n\n[![](https://raw.githubusercontent.com/favstats/usa_refugee_data/master/images/gg_refugee.gif)](https://raw.githubusercontent.com/favstats/usa_refugee_data/master/images/gg_refugee.gif) \n\n\n## Region\n\n### Static\n\n``` r\ngg_refugee_static_region \u003c- refugee_dat %\u003e% \n  mutate(continent = countrycode::countrycode(cntry, \"country.name\", \"continent\")) %\u003e% \n  mutate(region = countrycode::countrycode(cntry, \"country.name\", \"region\")) %\u003e%\n  mutate(continent = case_when(\n    continent == \"Asia\" ~ region,\n    T ~ continent\n  )) %\u003e% \n  mutate(continent = case_when(\n    cntry == \"Tibet\" ~ \"Eastern Asia\",\n    cntry == \"Yemen (Sanaa)\" ~ \"Middle East\",\n    cntry == \"Yugoslavia\" ~ \"Europe\",\n    str_detect(cntry, \"Georgia|Armenia|Azerbaijan\") ~ \"Central Asia\",\n    continent == \"Western Asia\" ~ \"Middle East\",\n    T ~ continent\n  )) %\u003e% \n  # group_by(continent) %\u003e% tally\n  # filter(continent == \"Western Asia\")\n  group_by(year, continent) %\u003e% \n  tally() \n```\n\n    ## Warning in countrycode::countrycode(cntry, \"country.name\", \"continent\"): Some values were not matched unambiguously: Tibet, Yemen (Sanaa), Yugoslavia\n\n    ## Warning in countrycode::countrycode(cntry, \"country.name\", \"region\"): Some values were not matched unambiguously: Tibet, Yemen (Sanaa), Yugoslavia\n\n    ## Using `n` as weighting variable\n\n``` r\n# gg_refugee_static_region %\u003e% filter(continent == \"Southern Asia\") %\u003e% summarize_all(sum)\n  \nlabel_dat \u003c- gg_refugee_static_region %\u003e% \n  group_by(continent) %\u003e% \n  summarize(nn = max(nn)) %\u003e% \n  select(-continent) %\u003e% \n  inner_join(gg_refugee_static_region) %\u003e% \n  filter(!(year == 2018 \u0026 continent == \"Eastern Asia\")) %\u003e% \n  filter(!(year == 2004 \u0026 continent == \"Eastern Asia\")) %\u003e% \n  mutate(nn = ifelse(continent == \"Southern Asia\", 10385, nn)) %\u003e% \n  mutate(year = ifelse(continent == \"Southern Asia\", 2015, year))\n```\n\n    ## Joining, by = \"nn\"\n\n``` r\ngg_static_region \u003c- gg_refugee_static_region %\u003e%   \n  ggplot(aes(year, nn)) +\n  geom_vline(data = year_dat, aes(xintercept = year), alpha = 0.15) +\n  geom_label(data = year_dat, aes(x = year, y = 41000, label = label), \n            angle = 0, color = \"black\") +\n  geom_line(aes(linetype = continent, color = continent)) +\n  theme_minimal() +\n  ggrepel::geom_label_repel(data = label_dat, \n                            aes(label = continent, color = continent), \n                            show.legend = F, seed = 13092018) +\n  geom_point(data = label_dat, aes(color = continent)) +\n  scale_color_manual(\"Region\", values = qualitative) +\n  scale_linetype(\"Region\") +\n  theme(plot.title = element_text(size = 13, face = \"bold\"),\n    # plot.subtitle = element_text(size = 11, face = \"bold\"), \n    plot.caption = element_text(size = 10),\n    legend.key.width = unit(3, \"line\"),\n    legend.position = \"bottom\") +\n  scale_x_continuous(breaks = 2002:2018, labels = 2002:2018,\n                     minor_breaks = seq(2002, 2018, 1)) +\n  labs(x = \"\", y = \"Number of Refugees\\n\", \n       title = \"Refugees arriving in the United States of America by Year (2002 - 2018)\", \n       caption = \"Data: Department of State, Office of Admissions - Refugee Processing Center\\nfavstats.eu; @favstats\") \n  # geom_rect(aes(xmin = 2002, xmax = 2005, ymin = 22000, ymax = 22000),\n  #             color = \"black\",\n  #             alpha = 0.8,\n  #             inherit.aes = FALSE)\n\ngg_static_region\n```\n\n[![](https://raw.githubusercontent.com/favstats/usa_refugee_data/master/refugee_analysis_files/figure-gfm/unnamed-chunk-5-1.png)](https://raw.githubusercontent.com/favstats/usa_refugee_data/master/refugee_analysis_files/figure-gfm/unnamed-chunk-5-1.png) \n\n\n``` r\ntidytemplate::ggsave_it(gg_static_region, width = 12, height = 8)\n```\n\n### Percent\n\n``` r\ngg_static_region_perc \u003c- gg_refugee_static_region %\u003e% \n  group_by(year) %\u003e% \n  mutate(total = sum(nn)) %\u003e% \n  mutate(perc = tidytemplate::get_percentage(nn, total))  \n  \nlabel_dat \u003c- gg_static_region_perc %\u003e% \n  group_by(continent) %\u003e% \n  summarize(perc = max(perc)) %\u003e% \n  select(-continent) %\u003e% \n  inner_join(gg_static_region_perc)\n```\n\n    ## Joining, by = \"perc\"\n\n``` r\ngg_region_perc \u003c- gg_static_region_perc %\u003e% \n  ggplot(aes(year, perc)) +\n  geom_vline(data = year_dat, aes(xintercept = year), alpha = 0.15) +\n  geom_label(data = year_dat, aes(x = year, y = 60, label = label),\n            angle = 0, color = \"black\") +\n  geom_line(aes(linetype = continent, color = continent)) +\n  theme_minimal() +\n  ggrepel::geom_label_repel(data = label_dat,\n                            aes(label = continent, color = continent),\n                            show.legend = F, seed = 13092018) +\n  geom_point(data = label_dat, aes(color = continent)) +\n  scale_color_manual(\"Region\", values = qualitative) +\n  scale_linetype(\"Region\") +\n  theme(plot.title = element_text(size = 13, face = \"bold\"),\n    # plot.subtitle = element_text(size = 11, face = \"bold\"), \n    plot.caption = element_text(size = 10),\n    legend.key.width = unit(3, \"line\"),\n    legend.position = \"bottom\") +\n  scale_x_continuous(breaks = 2002:2018, labels = 2002:2018,\n                     minor_breaks = seq(2002, 2018, 1)) +\n  labs(x = \"\", y = \"Percentage of Refugees\\n\", \n       title = \"Refugees arriving in the United States of America by Year (2002 - 2018)\\n\",\n       caption = \"Data: Department of State, Office of Admissions - Refugee Processing Center\\nfavstats.eu; @favstats\") \n\ngg_region_perc\n```\n\n[![](https://raw.githubusercontent.com/favstats/usa_refugee_data/master/refugee_analysis_files/figure-gfm/unnamed-chunk-6-1.png)](https://raw.githubusercontent.com/favstats/usa_refugee_data/master/refugee_analysis_files/figure-gfm/unnamed-chunk-6-1.png) \n\n\n``` r\ntidytemplate::ggsave_it(gg_region_perc, width = 12, height = 8)\n```\n\n### Animation\n\n``` r\nlibrary(gganimate)\n\ngg_anim_region \u003c- gg_refugee_static_region %\u003e%\n  mutate(continent = ifelse(continent == \"South-Eastern Asia\", \"S.E. Asia\", continent)) %\u003e% \n  ggplot(aes(year, nn, color = continent)) +\n  geom_vline(data = year_dat, aes(xintercept = year), alpha = 0.15) +\n  geom_label(data = year_dat, aes(x = year, y = 41000, label = label),\n            angle = 0, color = \"black\") +\n  geom_line() +\n  geom_segment(aes(xend = 2018, yend = nn), alpha = 0.5) +\n  geom_point() +\n  geom_text(aes(x = 2019, label = continent)) +\n  theme_minimal() +\n  scale_color_manual(\"Country\", values = qualitative) +\n  theme(plot.title = element_text(size = 13, face = \"bold\"),\n    # plot.subtitle = element_text(size = 12, face = \"bold\"),\n    plot.caption = element_text(size = 10),\n        legend.position = \"bottom\") +\n  scale_x_continuous(breaks = 2002:2018, labels = 2002:2018,\n                     minor_breaks = seq(2002, 2018, 1)) +\n  labs(x = \"\", y = \"Number of Refugees\\n\",\n       title = \"Refugees arriving in the United States of America by Year (2002 - 2018)\\n\",\n       caption = \"Data: Department of State, Office of Admissions - Refugee Processing Center\\nfavstats.eu; @favstats\")  +\n  guides(color = F, text = F) +\n  transition_reveal(continent, year, keep_last = T)\n\ngg_anim_region %\u003e% animate(\n  nframes = 500, fps = 15, width = 1000, height = 600, detail = 1\n)\n\nanim_save(\"images/gg_anim_region.gif\")\n```\n\n[![](https://raw.githubusercontent.com/favstats/usa_refugee_data/master/images/gg_anim_region.gif)](https://raw.githubusercontent.com/favstats/usa_refugee_data/master/images/gg_anim_region.gif) \n\n## Religion Data\n\n``` r\nrelig_refugee \u003c- read_excel(\"data/refugee_dat.xls\") %\u003e% \n  drop_na(Religion) %\u003e% \n  rename(religion = Religion) %\u003e% \n  select(-X__1, -X__2, -X__3, - Total) %\u003e% \n  # filter(!(str_detect(cntry, \"Total|Data\"))) %\u003e% \n  gather(year, n, -religion) %\u003e% \n  mutate(year = str_replace(year, \"CY \", \"\") %\u003e% as.numeric) %\u003e% \n  # group_by(religion, year) %\u003e% \n  # mutate(n = sum(n)) %\u003e% \n  mutate(religion_cat = case_when(\n    str_detect(religion, \"Moslem|Ahmadiyya\") ~ \"Muslim\",\n    str_detect(religion, \"Christ|Baptist|Chald|Coptic|Greek|Jehovah|Lutheran|Mennonite|Orthodox|Pentecostalist|Protestant|Uniate|Adventist|Cath|Meth|Old Believer\") ~ \"Christian\",\n    str_detect(religion, \"Atheist|No Religion\") ~ \"Atheist/No Religion\",\n    religion == \"Hindu\" ~ \"Hindu\",\n    T ~ \"Other/Unknown\"\n  )) %\u003e% \n  # filter(religion == \"Unknown\") %\u003e% \n  # .$n %\u003e% sum%\u003e% \n  group_by(religion_cat, year) %\u003e% \n  summarize(n = sum(n)) \n```\n\n### Static\n\n``` r\nlabel_dat \u003c- relig_refugee %\u003e% \n  filter(year == 2018)\n\ngg_relig \u003c- relig_refugee  %\u003e% \n  ggplot(aes(year, n)) +\n  geom_vline(data = year_dat, aes(xintercept = year), alpha = 0.15) +\n  geom_label(data = year_dat, aes(x = year, y = 48000, label = label),\n            angle = 0, color = \"black\") +\n  geom_line(aes(color = religion_cat), size = .8) +\n  theme_minimal() +\n  ggrepel::geom_text_repel(data = label_dat, \n                           aes(label = religion_cat, color = religion_cat), \n                           nudge_x = 2,\n                           show.legend = F, \n                           direction = \"y\", min.segment.length = 0.7) +\n  geom_point(data = label_dat, aes(color = religion_cat)) +\n  ggthemes::scale_color_gdocs(\"Religion\") +\n  # scale_color_manual(\"Religion\", values = qualitative) +\n  scale_linetype(\"Religion\") +\n  theme(plot.title = element_text(size = 13, face = \"bold\"),\n    plot.subtitle = element_text(size = 11, face = \"bold\"), \n    plot.caption = element_text(size = 10),\n    legend.key.width = unit(3, \"line\"),\n    legend.position = \"bottom\") +\n  scale_x_continuous(breaks = 2002:2018, labels = 2002:2018, \n                     limits = c(2002, 2021),\n                     minor_breaks = seq(2002, 2018, 1)) +\n  labs(x = \"\", y = \"Number of Refugees\\n\", \n       title = \"Refugees arriving in the United States of America by Year (2002 - 2018)\", subtitle = \"Aggregated by Religion\\n\",\n       caption = \"Data: Department of State, Office of Admissions - Refugee Processing Center\\nfavstats.eu; @favstats\") +\n  guides(color = F)\n\ngg_relig\n```\n\n[![](https://raw.githubusercontent.com/favstats/usa_refugee_data/master/refugee_analysis_files/figure-gfm/unnamed-chunk-9-1.png)](https://raw.githubusercontent.com/favstats/usa_refugee_data/master/refugee_analysis_files/figure-gfm/unnamed-chunk-9-1.png) \n\n\n``` r\ntidytemplate::ggsave_it(gg_relig, width = 10, height = 6)\n```\n\n### Animated\n\n``` r\nlibrary(gganimate)\n\ngg_religion \u003c- relig_refugee %\u003e%\n  ggplot(aes(year, n, color = religion_cat)) +\n  geom_vline(data = year_dat, aes(xintercept = year), alpha = 0.15) +\n  geom_label(data = year_dat, aes(x = year, y = 48000, label = label),\n            angle = 0, color = \"black\", size = 6) +\n  geom_line(size = 1) +\n  geom_segment(aes(xend = 2018, yend = n), alpha = 0.5) +\n  geom_point(size = 2) +\n  geom_text(aes(x = 2019, label = religion_cat), \n            size = 6, face = \"bold\", nudge_x = .75) +\n  theme_minimal() +\n  ggthemes::scale_color_gdocs(\"Religion\") +\n  theme(plot.title = element_text(size = 18, face = \"bold\"),\n    plot.subtitle = element_text(size = 16, face = \"bold\"),\n    plot.caption = element_text(size = 14),\n    axis.title = element_text(size = 14, face = \"bold\"),\n    axis.text = element_text(size = 14),\n        legend.position = \"bottom\") +\n  scale_x_continuous(breaks = 2002:2018, \n                     labels = c(\"'02\", \"'03\", \"'04\",\n                                \"'05\", \"'06\", \"'07\",\n                                \"'08\", \"'09\", \"'10\",\n                                \"'11\", \"'12\", \"'13\",\n                                \"'14\", \"'15\", \"'16\",\n                                \"'17\", \"'18\"), \n                     limits = c(2002, 2020.5),\n                     minor_breaks = seq(2002, 2018, 1)) +\n  labs(x = \"\", y = \"Number of Refugees\\n\\n\",\n       title = \"Refugees arriving in the United States of America by Year (2002 - 2018)\", subtitle = \"Aggregated by Religion\\n\\n\",\n       caption = \"Data: Department of State, Office of Admissions - Refugee Processing Center\\nfavstats.eu; @favstats\")  +\n  guides(color = F, text = F) +\n  transition_reveal(religion_cat, year, keep_last = T)\n\ngg_religion %\u003e% animate(\n  nframes = 500, fps = 15, width = 1000, height = 600, detail = 1\n)\n\nanim_save(\"images/gg_religion.gif\")\n```\n\n[![](https://raw.githubusercontent.com/favstats/usa_refugee_data/master/images/gg_religion.gif)](https://raw.githubusercontent.com/favstats/usa_refugee_data/master/images/gg_religion.gif) \n\n\n\n## Maps\n\n``` r\nload(\"data/world_map.Rdata\")\n\nrefugee_map_total \u003c- refugee_dat %\u003e% \n  mutate(id = countrycode::countrycode(cntry, \"country.name\", \"country.name\")) %\u003e% \n  mutate(id = ifelse(cntry == \"Tibet\", yes = \"China\", no = id)) %\u003e%\n  group_by(id) %\u003e% \n  summarize(n = sum(n, na.rm = T)) %\u003e% \n  full_join(world_map) %\u003e% \n  mutate(n = cut(n,  \n                 breaks = c(1, 100, 10000, 50000, 100000, 175000), \n                 labels = c(\"\u003c 100\", \"100 - 10.000\", \n                          \"10.001 - 50.000\", \"50.001 - 100.000\", \n                            \"100.001 - 175.000\")))\n```\n\n### Total Map\n\n``` r\nrefugee_map_total %\u003e% \n  ggplot() +\n  geom_map(map = world_map,\n         aes(x = long, y = lat, group = group, map_id = id),\n         color = \"#7f7f7f\", fill = \"gray80\", size = 0.15) +\n  geom_map(data = refugee_map_total, \n           map = world_map,\n        aes(map_id  = id, \n            fill = n), size = 0.01) + \n  theme_void() +\n#  scale_fill_gradient(low = \"red\", high = \"blue\") + \n  coord_equal() +\n  viridis::scale_fill_viridis(\"Number of Refugees\", \n                              direction = -1,\n                              option = \"D\", \n                              discrete = T, \n                              # begin = .2, \n                              # end = .8, \n                              na.value = \"grey\",\n                        #       limits = c(0, 1), \n                        # breaks = c(0, .20, .40, .60, .8, 1),\n                        labels = c(\"\u003c 100\", \"100 - 10.000\", \n                          \"10.000 - 50.000\", \"50.000 - 100.000\", \n                            \"100.000 - 175.000\", \"No Refugees\")) +\n  # facet_wrap(~year, ncol = 6) +\n  theme(\n    plot.title = element_text(size = 18, face = \"bold\", hjust = 0.5),\n    plot.caption = element_text(size = 14),\n    legend.justification = c(1, 0),\n    legend.position = c(0.2, 0.25),\n    legend.title = element_text(size = 10), \n    #axis.ticks.length = unit(3, \"cm\"),\n    legend.direction = \"vertical\") +\n  # guides(fill = guide_colorbar(barwidth = 0.7, barheight = 15,\n  #               title.position = \"bottom\", title.hjust = 0.5,\n  #               label.theme = element_text(colour = \"black\", size = 6, angle = 0))) +\n  labs(x = \"\", y = \"\",\n       title = \"Refugees arriving in the United States of America by Nationality (2002 - 2018)\",\n       caption = \"Data: Department of State, Office of Admissions - Refugee Processing Center   \\nfavstats.eu; @favstats   \")   \n```\n\n[![](https://raw.githubusercontent.com/favstats/usa_refugee_data/master/images/refugee_total_map.png)](https://raw.githubusercontent.com/favstats/usa_refugee_data/master/images/refugee_total_map.png) \n\n``` r\n\nggsave(filename = \"images/refugee_total_map.png\", height = 6, width = 12) \n\n```\n\n\n\n## Extended Data (1975 - 2018)\n\n``` r\nrefuge_admissions75 \u003c- 'https://static1.squarespace.com/static/580e4274e58c624696efadc6/t/5b8ff632aa4a999f85f99e8d/1536161330411/Graph+Refugee+Admissions+since+1975%289.5.18%29.pdf'\n\n# Extract the table\nout \u003c- extract_tables(refuge_admissions75)\n\nfirst_pages \u003c- do.call(rbind, out[-length(out)]) %\u003e% as_tibble()\n\ncorrect_names \u003c- first_pages[2,] %\u003e% as.character()\n\nfinal1 \u003c- first_pages %\u003e% \n  set_names(correct_names) %\u003e% \n  .[-c(1:2),] %\u003e% \n  .[-c(length(.)),] \n\nlast_page \u003c- cbind(\n   out[[3]][,1],\n   out[[3]][,2],\n   out[[3]][,3],\n   out[[3]][,5],\n   out[[3]][,6],\n   out[[3]][,7],\n   out[[3]][,8],\n   out[[3]][,9],\n   out[[3]][,10],\n   out[[3]][,11]\n) %\u003e% as_tibble() \n  \ncorrect_lastpage \u003c- last_page[2,] %\u003e% as.character()\n\nfinal2 \u003c- last_page %\u003e% \n  set_names(correct_lastpage) %\u003e% \n  .[-c(1:2),] \n\n\n\nadmissions75 \u003c- bind_rows(final1, final2) %\u003e% \n  select(-Total) %\u003e% \n  mutate_all(parse_number) %\u003e% \n  na.omit() %\u003e% \n  gather(region, n, -`Fiscal\\rYear`) %\u003e% \n  janitor::clean_names()\n```\n\n### Plot It\n\n``` r\nyear_lab \u003c- paste0(\"'\", stringi::stri_sub(1975:2018, -2 , -1))\n\nyear_dat \u003c- tibble(fiscal_year = c(seq(1976, 2016, 4)), \n                   label = c(\"Carter I\", \"Reagan I\", \"Reagan II\", \n                             \"H.W. Bush I\", \"Clinton I\", \"Clinton II\", \"Bush I\", \n                             \"Bush II\", \"Obama I\", \"Obama II\", \"Trump I\"))\n\nn_refugee_2018 \u003c- admissions75 %\u003e% \n  filter(fiscal_year == 2018) %\u003e% \n  summarize(n = sum(n)) %\u003e% \n  .$n\n\nn_refugee_2002 \u003c- admissions75 %\u003e% \n  filter(fiscal_year == 2002) %\u003e% \n  summarize(n = sum(n)) %\u003e% \n  .$n\n\nn_refugee_1992 \u003c- admissions75 %\u003e% \n  filter(fiscal_year == 1992) %\u003e% \n  summarize(n = sum(n)) %\u003e% \n  .$n\n\nn_refugee_1980 \u003c- admissions75 %\u003e% \n  filter(fiscal_year == 1980) %\u003e% \n  summarize(n = sum(n)) %\u003e% \n  .$n\n\nn_refugee_1975 \u003c- admissions75 %\u003e% \n  filter(fiscal_year == 1975) %\u003e% \n  summarize(n = sum(n)) %\u003e% \n  .$n\n\nadmissions75 %\u003e% \n  summarize(n = sum(n)) %\u003e% \n  .$n\n\n\nadmissions75 %\u003e% \n  mutate(region = case_when(\n    region == \"Former\\rSoviet\\rUnion\" ~ \"(Former) Soviet Union\",\n    region == \"Latin America\\rCaribbean\" ~ \"Latin America/Caribbean\",\n    region == \"Near East\\rSouth Asia\" ~ \"Near East/South Asia\",    \n    region == \"PSI\" ~ \"Private Sector Initiative\",   \n    T ~ region\n  )) %\u003e% \n  ggplot(aes(fiscal_year, n))  +\n  geom_vline(data = year_dat, aes(xintercept = fiscal_year), alpha = 0.35) +\n  geom_label(data = year_dat, aes(x = fiscal_year, y = 220000, label = label),\n            angle = 0, color = \"black\") +\n  geom_area(aes(fill = region), alpha = 0.9) +\n  geom_hline(yintercept = n_refugee_2018, \n             linetype = \"dashed\", color = \"black\", alpha = 0.85) +\n  annotate(\"label\", x = 1978, y = 115000, \n           fill = \"lightgrey\", alpha = 0.85, label.size = NA,\n           label = \"End of\\n Vietnam War\") +\n  annotate(\"label\", x = 1984, y = 185000, \n           fill = \"lightgrey\", alpha = 0.85, label.size = NA,\n           label = \"Refugee Act of 1980\") +\n  annotate(\"label\", x = 1997, y = 150000, \n           fill = \"lightgrey\", alpha = 0.85, label.size = NA,\n           label = \"Fall of Soviet Union\") +\n  annotate(\"label\", x = 2000, y = 105000, \n           fill = \"lightgrey\", alpha = 0.85, label.size = NA,\n           label = \"Drop after 9/11\") +\n  annotate(\"label\", x = 2015, y = 110000, \n           fill = \"lightgrey\", alpha = 0.85, label.size = NA,\n           label = \"Number of Refugees in 2018\\n lowest since 1977\") +\n  theme_minimal() +\n  scale_y_continuous(labels = scales::comma) +\n  scale_fill_manual(\"Region\", values = qualitative) +\n  geom_curve(aes(x = 1977, y = 125000, xend = 1975, yend = n_refugee_1975),\n  arrow = arrow(length = unit(0.03, \"npc\")), curvature = 0.2) +\n  geom_curve(aes(x = 1982, y = 190000, xend = 1980, yend = n_refugee_1980),\n  arrow = arrow(length = unit(0.03, \"npc\")), curvature = 0.2) +\n  geom_curve(aes(x = 1994, y = 150000, xend = 1992, yend = n_refugee_1992),\n  arrow = arrow(length = unit(0.03, \"npc\")), curvature = 0.2) +\n  geom_curve(aes(x = 2000, y = 100000, xend = 2002, yend = n_refugee_2002),\n  arrow = arrow(length = unit(0.03, \"npc\")), curvature = -0.3) +\n  geom_curve(aes(x = 2016, y = 100000, xend = 2018, yend = n_refugee_2018),\n  arrow = arrow(length = unit(0.03, \"npc\")), curvature = -0.2) +\n  theme(plot.title = element_text(size = 13, face = \"bold\"),\n    # plot.subtitle = element_text(size = 11, face = \"bold\"), \n    plot.caption = element_text(size = 10),\n    legend.key.width = unit(3, \"line\"),\n    legend.position = \"bottom\") +\n  scale_x_continuous(breaks = 1975:2018, labels = year_lab,\n                     minor_breaks = seq(1975, 2018, 1)) +\n  labs(x = \"\", y = \"Number of Refugees\\n\", \n       title = \"Refugees arriving in the United States of America by Year (1975 - 2018)\\n\", \n       caption = \"Data: Department of State, Office of Admissions - Refugee Processing Center\\nTotal Number of Accepted Refugees since 1975: 3.340.709\\nfavstats.eu; @favstats\") \n\n```\n\n[![](https://raw.githubusercontent.com/favstats/usa_refugee_data/master/images/refugee75.png)](https://raw.githubusercontent.com/favstats/usa_refugee_data/master/images/refugee75.png) \n\n``` r\nggsave(filename = \"images/refugee75.png\", height = 7, width = 13) \n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffavstats%2Fusa_refugee_data","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffavstats%2Fusa_refugee_data","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffavstats%2Fusa_refugee_data/lists"}