Nation Charts

# Load the necessary libraries
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)

setwd("C:/Users/danie/Downloads")
Nations <- read.csv("nations.csv")
nations_data <- Nations %>%
  mutate(GDP_trillions = (gdp_percap * population) / 1e12)

first_chart <- nations_data %>%
  filter(country %in% c("China", "India", "United States", "Brazil")) %>%
  ggplot(aes(x = year, y = GDP_trillions, color = country)) +
  geom_point() +
  geom_line() +
  scale_color_brewer(palette = "Set1") +
  labs(x = "Year", y = "GDP (Trillions)", title = "GDP Over Time (Top 4 Countries)")
first_chart

GDP <- nations_data %>%
  group_by(region, year) %>%
  summarise(GDP = sum(gdp_percap, na.rm = TRUE)) %>%
  ggplot(aes(x = year, y = GDP, fill = region)) +
  geom_area(color = "white", size = 0.5) +
  scale_fill_brewer(palette = "Set2") +
  labs(x = "Year", y = "Total GDP", title = "Total GDP_percap by Region Over Time")
`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.
GDP