nations

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.0.4     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
setwd("/Users/alassanefaye/Library/Mobile Documents/com~apple~CloudDocs/DATA110 ")
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.
nations1 <- nations %>%
  mutate(gdp_trillions = (gdp_percap * population) / 1e12)
# Create the chart for GDP of selected countries (United States, Senegal, Morocco, Brazil)
chart1_data <- nations1 %>%
  filter(country %in% c("United States", "Senegal", "Morocco", "Brazil"))

Create the plot

ggplot(chart1_data, aes(x = year, y = gdp_trillions, color = country)) +
  geom_point() + 
  geom_line() +
  scale_color_manual(values = c("United States" = "green", 
                                "Senegal" = "aquamarine", 
                                "Morocco" = "blue", 
                                "Brazil" = "purple")) +
  labs(title = "GDP of Selected Countries Over Time", 
       x = "Year", 
       y = "GDP (Trillions of Dollars)") +
  theme_dark()

nations_region <- nations1 %>%
  group_by(region, year) %>%
  summarise(GDP = sum(gdp_trillions, na.rm = TRUE))
`summarise()` has grouped output by 'region'. You can override using the
`.groups` argument.
# Plot GDP trends by region using an area chart
ggplot(nations_region, aes(x = year, y = GDP, fill = region)) +
  geom_area(color = "white", size = 0.2) +  # Thin white line to separate areas
  scale_fill_manual(values = c(
    "#FF5733",  # Vibrant Orange
    "#33FF57",  # Bright Green
    "#5733FF",  # Deep Blue
    "#FFC300",  # Golden Yellow
    "#C70039",  # Rich Red
    "#900C3F",  # Dark Magenta
    "#1E90FF"   # Sky Blue
  )) +
  labs(title = "Regional GDP Trends Over Time",
       x = "Year",
       y = "GDP in Trillions",
       fill = "Region") +
  theme_minimal()
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.