library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(readr)
nations <- read_csv("nations.csv")
## Rows: 5275 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): iso2c, iso3c, country, region, income
## dbl (5): year, gdp_percap, population, birth_rate, neonat_mortal_rate
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
nations <- mutate(nations, gdp_trillions = gdp_percap * population / 1e12)
Chart_One <- nations %>%
filter(country %in% c("United States", "Vietnam", "Germany", "Italy")) %>%
ggplot(aes(x = year, y = gdp_trillions, color = country)) +
geom_point() +
geom_line() +
scale_color_brewer(palette = "Set1") +
labs(title = "GDP of Selected Countries Over Time",
x = "Year",
y = "GDP (Trillions USD)")
Chart_Two <- nations %>%
group_by(region, year) %>%
summarise(sum_GDP = sum(gdp_trillions, na.rm = TRUE)) %>%
ggplot(aes(x = year, y = sum_GDP, fill = region)) +
geom_area(color = "white", size = 0.2) +
scale_fill_brewer(palette = "Set2") +
labs(title = "Total GDP by Region Over Time",
x = "Year",
y = "Total GDP (Trillions USD)")
## `summarise()` has grouped output by 'region'. You can override using the
## `.groups` argument.
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
print(Chart_One)

print(Chart_Two)
