library(ggplot2)
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.3.2
## 
## 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
setwd("C:/Users/rafiz/OneDrive/Desktop/data110")
nations <- read.csv("nations.csv")

First Chart

#Gathering axis data
nations <- nations |>
  mutate(gdp = gdp_percap * population / 1e12)

countries <- c("China", "Germany" ,"Japan", "United States")
filtered_countries <- nations |>
  filter(country %in% countries)

#Creating chart
ggplot(filtered_countries, aes(x = year, y = gdp, color = country)) +
  geom_point() +
  geom_line() +
  labs(x = "Year", y = "GDP ($ Trillions)", title = "China's Rise to Become the Largest Economy") +
  scale_color_brewer(palette = "Set1") +
  theme_minimal()

Second Chart

#Gathering axis data
nations <- nations |>
  mutate(gdp = gdp_percap * population / 1e12)

region_data <- nations |>
  group_by(region, year) |>
  summarize(GDP = sum(gdp, na.rm = TRUE), .groups = "drop")

#Creating chart
ggplot(region_data, aes(x = year, y = GDP, fill = region)) +
  geom_area(color = "white", linewidth = 0.2) +
  scale_fill_brewer(palette = "Set2") +
  labs(x = "Year", y = "GDP ($ Trillions)", title = "GDP by World Bank Region") +
  theme_minimal()