Loaded in the necessary - libraries tidyverse, dplyr, ggplot2
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.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── 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
library(dplyr)
library(ggplot2)
Imported “nations” data set using the read function
nations <-read.csv("nations.csv")
Originally used 1,000,000,000,000 which gave very large values for the y-axis, I was able to figure out how to change the values using 10^12 through the help of ChatGPT
nations_mut <- nations |>mutate(gdp = gdp_percap * population /10^12)
Selected four countries and filtered them - I chose to compare four countries within the Middle East
plot1 <-ggplot(middleeast, aes(x = year, y = gdp, color = country)) +geom_line(alpha =0.3) +geom_point() +scale_color_brewer(palette ="Set1") +labs(title ="GDP In Middle Eastern Countries Over The Years",x ="Year",y ="GDP (trillions of dollars)")plot1
Got “summarise() has grouped output by ‘region’. You can override using the .groups argument.” as a message and decided to research the argument which led me to stackoverflow where I was able to figure out how to use it.
plot2 <-ggplot(summarize, aes(x = year, y = sum_gdp, fill = region)) +geom_area(color ="white") +scale_fill_brewer(palette ="Set2") +labs(title ="GDP In Different Regions Over The Years",x ="Year",y ="GDP (trillions of dollars)")plot2