Nations GDP Visualization

Author

Charlene Stephia

##load the dataset

library(readr)
nations_2_ <- read_csv("nations (2).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.
View(nations_2_)

##loading libraries

library(ggplot2)
Warning: package 'ggplot2' was built under R version 4.4.2
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(RColorBrewer)

library(readr)

##Convert GDP to trillions of dollars

nations <- nations_2_ %>%

  mutate(gdp = (gdp_percap * population) )

##Filter for selected countries

selected_countries <- c("United States", "China", "Germany", "India")



nations_filtered <- nations_2_ %>%

  filter(country %in% selected_countries)

##Line and Point Chart(graph one)

ggplot(nations_filtered, aes(x = year, y = gdp_percap, color = country)) +

  geom_line(size = 1) + 

  geom_point(size = 2) + 

  scale_color_brewer(palette = "Set1") +

  labs(title = "GDP Trends of Selected Countries",

       x = "Year",

       y = "GDP (Trillions of USD)",

       color = "Country") +

  theme_minimal()
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.

##CHART 2: GDP Trends by Region(Summarize GDP by region and year)

nations_region <- nations %>%

  group_by(region, year) %>%

  summarise(GDP = sum(gdp, na.rm = TRUE), .groups = "drop")

##Area Chart

ggplot(nations_region, aes(x = year, y = GDP, fill = region)) +

  geom_area(color = "white", size = 0.2) +

  scale_fill_brewer(palette = "Set2") +

  labs(title = "Regional GDP Trends Over Time",

       x = "Year",

       y = "Total GDP (Trillions of USD)",

       fill = "Region") +

  theme_minimal()