WDI(country = "all", indicator = "NE.GDI.TOTL.ZS", start = 2016, end = 2016, extra = TRUE) %>%
select(countryname = country, countrycode = iso3c, value = NE.GDI.TOTL.ZS) %>%
mutate(value = value/100) %>%
arrange(countrycode) %>%
right_join(map_data("world") %>%
filter(region != "Greenland", region != "Antarctica") %>%
left_join(iso3166 %>%
select(region = mapname, countrycode = a3) %>%
mutate(region = case_when(region == "China(?!:Hong Kong|:Macao)" ~ "China",
region == "Finland(?!:Aland)" ~ "Finland",
region == "UK(?!r)" ~ "UK",
region == "Norway(?!:Bouvet|:Svalbard|:Jan Mayen)" ~ "Norway",
TRUE ~ region)),
by = "region"),
by = "countrycode") %>%
ggplot(aes(long, lat, group = group)) +
geom_polygon(aes(fill = value), colour = alpha("black", 1/2), size = 0.1) +
scale_fill_viridis_c(labels = scales::percent_format(accuracy = 1),
breaks = seq(0, 0.6, 0.1),
values = c(0, 0.2, 0.4, 0.6, 1)) +
theme_void() +
theme(legend.position = c(0.1, 0.4),
legend.title = element_blank())
WDI(country = "all", indicator = "NE.GDI.TOTL.ZS", start = 2016, end = 2016, extra = T) %>%
select(countryname = country, countrycode = iso3c, value = NE.GDI.TOTL.ZS) %>%
mutate(value = value/100) %>%
arrange(countrycode) %>%
head %>%
beautiful_table
countryname | countrycode | value |
---|---|---|
Aruba | ABW | 0.2201351 |
Afghanistan | AFG | 0.1780879 |
Angola | AGO | 0.2721471 |
Albania | ALB | 0.2522382 |
Andorra | AND | NA |
Arab World | ARB | 0.2959508 |
map_data("world") %>%
filter(region != "Greenland", region != "Antarctica") %>%
left_join(iso3166 %>%
select(region = mapname, countrycode = a3) %>%
mutate(region = case_when(region == "China(?!:Hong Kong|:Macao)" ~ "China",
region == "Finland(?!:Aland)" ~ "Finland",
region == "UK(?!r)" ~ "UK",
region == "Norway(?!:Bouvet|:Svalbard|:Jan Mayen)" ~ "Norway",
TRUE ~ region)),
by = "region") %>%
head %>%
beautiful_table
long | lat | group | order | region | subregion | countrycode |
---|---|---|---|---|---|---|
-69.89912 | 12.45200 | 1 | 1 | Aruba | NA | ABW |
-69.89571 | 12.42300 | 1 | 2 | Aruba | NA | ABW |
-69.94219 | 12.43853 | 1 | 3 | Aruba | NA | ABW |
-70.00415 | 12.50049 | 1 | 4 | Aruba | NA | ABW |
-70.06612 | 12.54697 | 1 | 5 | Aruba | NA | ABW |
-70.05088 | 12.59707 | 1 | 6 | Aruba | NA | ABW |
WDI(country = "all", indicator = "NE.GDI.TOTL.ZS", start = 2016, end = 2016, extra = TRUE) %>%
select(countryname = country, countrycode = iso3c, value = NE.GDI.TOTL.ZS) %>%
mutate(value = value/100) %>%
arrange(countrycode) %>%
right_join(map_data("world") %>%
filter(region != "Greenland", region != "Antarctica") %>%
left_join(iso3166 %>%
select(region = mapname, countrycode = a3) %>%
mutate(region = case_when(region == "China(?!:Hong Kong|:Macao)" ~ "China",
region == "Finland(?!:Aland)" ~ "Finland",
region == "UK(?!r)" ~ "UK",
region == "Norway(?!:Bouvet|:Svalbard|:Jan Mayen)" ~ "Norway",
TRUE ~ region)),
by = "region"),
by = "countrycode") %>%
head %>%
beautiful_table
countryname | countrycode | value | long | lat | group | order | region | subregion |
---|---|---|---|---|---|---|---|---|
Aruba | ABW | 0.2201351 | -69.89912 | 12.45200 | 1 | 1 | Aruba | NA |
Aruba | ABW | 0.2201351 | -69.89571 | 12.42300 | 1 | 2 | Aruba | NA |
Aruba | ABW | 0.2201351 | -69.94219 | 12.43853 | 1 | 3 | Aruba | NA |
Aruba | ABW | 0.2201351 | -70.00415 | 12.50049 | 1 | 4 | Aruba | NA |
Aruba | ABW | 0.2201351 | -70.06612 | 12.54697 | 1 | 5 | Aruba | NA |
Aruba | ABW | 0.2201351 | -70.05088 | 12.59707 | 1 | 6 | Aruba | NA |
us <- map_data("state")
ggplot() +
geom_map(data = sh_top10_state_fig2b %>%
left_join(fips_statenames_xwalk_short, by = "state") %>%
mutate(mean_s_stateig10 = mean_s_stateig10 /100),
map = us,
aes(fill = mean_s_stateig10, map_id = region),
color = "white", size = 0.15) +
geom_map(data = us, map = us,
aes(long, lat, map_id = region),
color = "#2b2b2b", fill = NA, size = 0.20) +
scale_fill_viridis(name = "Top 10% \nShare",
labels = percent_format(accuracy = 1),
values = c(0, 0.2, 0.4, 0.5, 1)) +
theme_map() +
theme(legend.position = c(0.87, 0.1))
sh_top10_state_fig2b %>%
left_join(fips_statenames_xwalk_short, by = "state") %>%
mutate(value = mean_s_stateig10 /100) %>%
right_join(map_data("state"), by = "region") %>%
ggplot(aes(long, lat, group = group)) +
geom_polygon(aes(fill = value), colour = alpha("black", 1/2), size = 0.2) +
scale_fill_viridis_c(labels = scales::percent_format(accuracy = 1),
breaks = c(0.05, 0.08, 0.10, 0.12, 0.15),
values = c(0, 0.2, 0.4, 0.5, 1)) +
theme_void() +
theme(legend.position = c(0.9, 0.2)) + labs(fill = "Top 10%\nShare")
map_data("county") %>%
left_join(county_code_name %>%
select(county_code, subregion = county_name3, region = state_name3),
by = c("region", "subregion")) %>%
left_join(dataraw_county_long %>%
filter(variable == "mortgage", date == as.Date("2007-10-01")) %>%
select(county_code, value),
by = "county_code") %>%
ggplot(aes(long, lat, group = group)) +
geom_polygon(aes(fill = value), colour = alpha("black", 1/2), size = 0.2) +
scale_fill_viridis_c(labels = scales::dollar_format(accuracy = 1),
na.value = "white",
breaks = c(25000, 50000, 75000, 100000, 125000)) +
theme_void() +
theme(legend.position = c(0.9, 0.2)) +
labs(fill = "Per Capita\nMortgage Debt")
map_data("county") %>%
left_join(county_code_name %>%
select(county_code, subregion = county_name3, region = state_name3),
by = c("region", "subregion")) %>%
left_join(dataraw_county_long %>%
filter(variable == "UNR", date == as.Date("2007-10-01")) %>%
select(county_code, value) %>%
mutate(value = value/100),
by = "county_code") %>%
ggplot(aes(long, lat, group = group)) +
geom_polygon(aes(fill = value), colour = alpha("black", 1/2), size = 0.2) +
scale_fill_viridis_c(labels = scales::percent_format(accuracy = 1),
na.value = "white",
breaks = c(0, 0.05, 0.10, 0.15, 0.20),
values = c(0, 0.1, 0.2, 0.3, 1)) +
theme_void() +
theme(legend.position = c(0.9, 0.2)) + labs(fill = "Unemp.\nRate")
map_data("county") %>%
filter(region == "california") %>%
left_join(county_code_name %>%
select(county_code, subregion = county_name3, region = state_name3),
by = c("region", "subregion")) %>%
left_join(dataraw_county_long %>%
filter(variable == "mortgage", date == as.Date("2006-10-01")) %>%
select(county_code, value),
by = "county_code") %>%
ggplot(aes(long, lat, group = group)) +
geom_polygon(aes(fill = value), colour = alpha("black", 1/2), size = 0.2) +
scale_fill_viridis_c(na.value = "white",
labels = scales::dollar_format(accuracy = 1)) +
theme_void() +
theme(legend.position = c(0.9, 0.8)) +
labs(fill = "Per Capita\nMortgage Debt") +
coord_fixed(ratio = 1)
map_data("county") %>%
filter(region == "texas") %>%
left_join(county_code_name %>%
select(county_code, subregion = county_name3, region = state_name3),
by = c("region", "subregion")) %>%
left_join(dataraw_county_long %>%
filter(variable == "mortgage", date == as.Date("2006-10-01")) %>%
select(county_code, value),
by = "county_code") %>%
ggplot(aes(long, lat, group = group)) +
geom_polygon(aes(fill = value), colour = alpha("black", 1/2), size = 0.2) +
scale_fill_viridis_c(na.value = "white",
labels = scales::dollar_format(accuracy = 1)) +
theme_void() +
theme(legend.position = c(0.1, 0.2)) +
labs(fill = "Per Capita\nMortgage Debt") +
coord_fixed(ratio = 1)
map_data("county") %>%
filter(region == "massachusetts") %>%
left_join(county_code_name %>%
select(county_code, subregion = county_name3, region = state_name3),
by = c("region", "subregion")) %>%
left_join(dataraw_county_long %>%
filter(variable == "mortgage", date == as.Date("2006-10-01")) %>%
select(county_code, value),
by = "county_code") %>%
ggplot(aes(long, lat, group = group)) +
geom_polygon(aes(fill = value), colour = alpha("black", 1/2), size = 0.2) +
scale_fill_viridis_c(na.value = "white",
labels = scales::dollar_format(accuracy = 1)) +
theme_void() +
theme(legend.position = c(0.2, 0.2)) +
labs(fill = "Per Capita\nMortgage Debt") +
coord_fixed(ratio = 1)
map_data("county") %>%
left_join(county_code_name %>%
select(county_code, subregion = county_name3, region = state_name3),
by = c("region", "subregion")) %>%
left_join(mme_percap_county %>%
select(county_code = fips, value) %>%
mutate(value = value/100),
by = "county_code") %>%
ggplot(aes(long, lat, group = group)) +
geom_polygon(aes(fill = value), colour = alpha("black", 1/2), size = 0.2) +
scale_fill_viridis_c(labels = scales::percent_format(),
na.value = "white",
breaks = c(-0.05, -0.02, 0, 0.02, 0.05),
values = c(0, 0.25, 0.5, 0.75, 1)) +
theme_void() +
theme(legend.position = c(0.9, 0.2)) + labs(fill = "Unemp.\nRate")
map_data("county") %>%
left_join(county_code_name %>%
select(county_code, subregion = county_name3, region = state_name3),
by = c("region", "subregion")) %>%
left_join(county_to_cbsa %>%
select(county_code, cbsa_code),
by = "county_code") %>%
left_join(cbsa_nodate %>%
select(cbsa_code, value = elasticity),
by = "cbsa_code") %>%
ggplot(aes(long, lat, group = group)) +
geom_polygon(aes(fill = value), colour = alpha("black", 1/2), size = 0.2) +
scale_fill_viridis_c(na.value = "white",
labels = scales::dollar_format(accuracy = 1)) +
theme_void() +
theme(legend.position = c(0.2, 0.2)) +
labs(fill = "Per Capita\nMortgage Debt") +
coord_fixed(ratio = 1)
ggplot() +
geom_map(data = df_state_demographics, map = us,
aes(fill = per_capita_income, map_id = region),
color = "white", size = 0.15) +
geom_map(data = us, map = us,
aes(long, lat, map_id = region),
color = "#2b2b2b", fill = NA, size = 0.20) +
scale_fill_viridis(name = "Per Capita \nIncome",
labels = dollar_format(accuracy = 1),
values = c(0, 0.2, 0.3, 0.4, 1)) +
theme_map() + theme(legend.position = c(0.87, 0.1))
ggplot() +
geom_map(data = df_state_demographics, map = us,
aes(fill = median_rent, map_id = region),
color = "white", size = 0.15) +
geom_map(data = us, map = us,
aes(long, lat, map_id = region),
color = "#2b2b2b", fill = NA, size = 0.20) +
scale_fill_viridis(name = "Median Rent",
labels = dollar_format(accuracy = 1),
values = c(0, 0.2, 0.3, 0.4, 1)) +
theme_map() + theme(legend.position = c(0.87, 0.1))
ggplot() +
geom_map(data = df_state_demographics, map = us,
aes(fill = median_age, map_id = region),
color = "white", size = 0.15) +
geom_map(data = us, map = us,
aes(long, lat, map_id = region),
color = "#2b2b2b", fill = NA, size = 0.20) +
scale_fill_viridis(name = "Median Age",
labels = comma,
values = c(0, 0.2, 0.3, 0.5, 0.7, 1)) +
theme_map() + theme(legend.position = c(0.87, 0.1))
df_county_demographics %>%
left_join(county.regions, by = "region") %>%
rename(fips = region, subregion = county.name) %>%
left_join(us, by = "subregion") %>%
ggplot(., aes(x = long, y = lat, group = group, fill = per_capita_income)) +
geom_polygon() + coord_map() +
theme_map() +
geom_map(data = us, map = us,
aes(long, lat, map_id = region),
color = "#2b2b2b", fill = NA, size = 0.20) +
scale_fill_viridis(name = "Per Capita \nIncome",
labels = dollar_format(accuracy = 1),
values = c(0, 0.2, 0.3, 0.4, 1)) +
theme(legend.position = c(0.87, 0.1))
df_county_demographics %>%
left_join(county.regions, by = "region") %>%
rename(fips = region, subregion = county.name) %>%
left_join(us, by = "subregion") %>%
ggplot(., aes(x = long, y = lat, group = group, fill = median_rent)) +
geom_polygon() + coord_map() +
theme_map() +
geom_map(data = us, map = us,
aes(long, lat, map_id = region),
color = "#2b2b2b", fill = NA, size = 0.20) +
scale_fill_viridis(name = "Monthly Rent",
labels = scales::dollar,
breaks = c(200, 400, 800, 1200, 1600),
values = c(0, 0.2, 0.4, 0.5, 1)) +
theme(legend.position = c(0.87, 0.1))
df_county_demographics %>%
left_join(county.regions, by = "region") %>%
rename(fips = region, subregion = county.name) %>%
left_join(us, by = "subregion") %>%
ggplot(., aes(x = long, y = lat, group = group, fill = median_age)) +
geom_polygon() + coord_map() +
theme_map() +
geom_map(data = us, map = us,
aes(long, lat, map_id = region),
color = "#2b2b2b", fill = NA, size = 0.20) +
scale_fill_viridis(name = "Median Age",
labels = comma,
values = c(0, 0.2, 0.3, 0.5, 0.7, 1)) +
theme(legend.position = c(0.87, 0.1))
# Some EU Contries
some.eu.countries <- c(
"Portugal", "Spain", "France", "Switzerland", "Germany",
"Austria", "Belgium", "UK", "Netherlands",
"Denmark", "Poland", "Italy",
"Croatia", "Slovenia", "Hungary", "Slovakia",
"Czech republic"
)
# Retrievethe map data
some.eu.maps <- map_data("world", region = some.eu.countries)
# Compute the centroid as the mean longitude and lattitude
# Used as label coordinate for country's names
region.lab.data <- some.eu.maps %>%
group_by(region) %>%
summarise(long = mean(long), lat = mean(lat))
ggplot(some.eu.maps, aes(x = long, y = lat)) +
geom_polygon(aes( group = group, fill = region))+
geom_text(aes(label = region), data = region.lab.data, size = 3, hjust = 0.5)+
scale_fill_viridis_d()+
theme_void()+
theme(legend.position = "none")