suppressPackageStartupMessages(library(tidyverse))
suppressPackageStartupMessages(library(knitr))
nations_chart <- read_csv("nations.csv", show_col_types = FALSE)DATA 110 - Week 6 Homework
Setup
options(scipen = 999)
nations_base <- nations_chart %>%
mutate(gdp_country = gdp_percap * population / 10^12)nations_4 <- nations_base %>%
filter(country %in% c("Luxembourg", "Hong Kong SAR, China", "Switzerland", "Ireland"))Plot 1: Corporate Friendly Tax Havens
Plot 1 charts the Gross Domestic Product of 4 of the top corporate tax havens. https://en.wikipedia.org/wiki/Tax_haven Though the Cayman Islands is usually among the top 4 tax haven nations, in this data set it only had GDP data for one year (2011) so I replaced it with Switzerland.
p1 <- ggplot(nations_4, aes(x = year, y = gdp_country, color = country)) +
labs(title = "Nations with Corporation Friendly Tax Policies", subtitle = "According to Wikipedia") +
geom_line() +
geom_point() +
xlab("Year") +
ylab("Gross Domestic Product\n in $ Trillions") +
scale_color_brewer(palette = "Set1", name = "Nation") +
theme_minimal()
p1Plot 2: GDP by World Bank Region
nations_regions <- nations_base %>%
group_by(region, year) %>%
summarise(GDP = sum(gdp_country, na.rm = TRUE))`summarise()` has grouped output by 'region'. You can override using the
`.groups` argument.
p2 <- ggplot(nations_regions, aes(x = year, y = GDP)) +
labs(title = "GDP by World Bank Region") +
xlab("Year") +
ylab("GDP ($ trillion") +
geom_area(color = "white", aes(fill = region)) +
scale_fill_brewer(palette = "Set2", name = "Region") +
theme_minimal()
p2