Created
March 26, 2021 12:53
-
-
Save ryanburge/88b5a77becc1a96d056167b96affe74e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arr <- read_csv("D://arrivals.csv") | |
arr <- arr %>% | |
mutate(name = replace_na(`Basic data and indicators`, "REMOVE")) %>% | |
select(-`Basic data and indicators`) | |
tot <- arr %>% | |
filter(X3 == "Total arrivals" | name != "REMOVE") %>% | |
relocate(name) | |
tot <- tot %>% | |
select(-starts_with("X")) %>% | |
select(-starts_with("X")) | |
tot$name[tot$name == "REMOVE"] <- NA | |
tot$name <- zoo::na.locf(tot$name, fromLast=FALSE) | |
tot <- tot %>% | |
pivot_longer(!name, names_to = "type") | |
tot <- tot %>% | |
filter(value != "NA") | |
tot <- tot %>% | |
mutate(type = as.numeric(type)) | |
tot$name <- quanteda::char_tolower(tot$name) | |
tot$name <- stringr::str_to_title(tot$name) | |
tot <- tot %>% | |
rename(year = type) %>% | |
rename(country = name) | |
cull <- tot %>% | |
group_by(country) %>% | |
summarise(sum = sum(value)) %>% | |
filter(sum >= 500000) | |
tot <- left_join(tot, cull) %>% | |
filter(sum != "NA") | |
arr1 <- tot %>% | |
mutate(color = frcode(country == "France" ~ "a", | |
country == "United States Of America" ~ "b", | |
country == "China" ~ "c", | |
country == "Spain" ~ "d", | |
country == "Mexico" ~ "e", | |
TRUE ~ "f")) | |
arr1 %>% | |
ggplot(., aes(x = year, y = value, group = country, color = color)) + | |
geom_point() + | |
geom_line() + | |
theme_rb(legend = FALSE) + | |
add_text(x = 2000, y = 180000, word = "France", sz = 4) + | |
add_text(x = 2005, y = 160000, word = "USA", sz = 4) + | |
add_text(x = 2015, y = 145000, word = "China", sz = 4) + | |
add_text(x = 2012, y = 110000, word = "Spain", sz = 4) + | |
add_text(x = 2000, y = 115000, word = "Mexico", sz = 4) + | |
scale_color_manual(values = c("#4E79A7", "#F28E2B", "#E15759", "#76B7B2", "#59A14F", "azure3")) + | |
labs(x = "", y = "", title = "Number of Arrivals Per Year by Country", caption = "@ryanburge\nData: UNWTO") + | |
ggsave("E://tableau_test.png", type = "cairo-png") | |
# https://git.io/JYm7R |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment