library(dplyr)
library(ggplot2)
Nations GDP Charts
<- read.csv("nations_new.csv") nations
<- nations |>
nations_four filter(country == "China" |
== "Germany" |
country == "Japan" |
country == "United States")
country
<- nations_four |>
p1 ggplot(aes(x = year,
y = (gdp_per_cap * population) / 1000000000000,
color = country)) +
geom_point() +
geom_line() +
scale_color_brewer(palette = "Set1") +
labs(
x = "Year",
y = "GDP (Trillions of Dollars)",
title = "GDP Over Time for Selected Countries",
caption = "Source: Nations Dataset"
)
p1
<- nations |>
nations_region group_by(region, year) |>
summarise(GDP = sum((gdp_per_cap * population) / 1000000000000, na.rm = TRUE),
.groups = "drop")
<- nations_region |>
p2 ggplot(aes(x = year, y = GDP, fill = region)) +
geom_area(color = "white", linewidth = 0.2) +
scale_fill_brewer(palette = "Set2") +
labs(
x = "Year",
y = "Total GDP (Trillions)",
title = "Total GDP by Region Over Time",
caption = "Source: Nations Dataset"
) p2