Nation Dataset Charts

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/kwils/OneDrive/Desktop/DATA 110")
data <- read.csv("nations (1).csv")
data <- data |>
  mutate(gdp_trillion = (gdp_percap * population) / 1e12)
filtered_data <- data |>
  filter(country %in% c("China", "India", "United States", "Mexico"))
chart1 <- ggplot(filtered_data, aes(x = year, y = gdp_trillion, color = country)) +
  geom_point() +
  geom_line() +
  scale_color_brewer(palette = "Set1") +
  labs(title = "GDP of Four Countries Over Time",
       x = "Year",
       y = "GDP (trillions of dollars)")
chart1 <- ggplot(filtered_data, aes(x = year, y = gdp_trillion, color = country)) +
  geom_point() +
  geom_line() +
  scale_color_brewer(palette = "Set1") +
  labs(title = "GDP of Four Countries Over Time",
       x = "Year",
       y = "GDP (trillions of dollars)")
print(chart1)

grouped_data <- data |>
  group_by(region, year) |>
  summarize(GDP = sum(gdp_trillion, na.rm = TRUE))
`summarise()` has grouped output by 'region'. You can override using the
`.groups` argument.
chart2 <- ggplot(grouped_data, aes(x = year, y = GDP, fill = region)) +
  geom_area(color = "white", size = 0.1) +  
  scale_fill_brewer(palette = "Set2") +
  labs(title = "GDP by Region Over Time",
       x = "Year",
       y = "GDP (trillions of dollars)",
       fill = "Region")
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
print(chart2)