library(tidyverse)
setwd("C:/Users/Shea/Documents/data110/csvs")
nations <- read_csv("nations.csv")Country GDP
nations <- mutate(nations, gdp_Trillions=gdp_percap*population/(10^12))Plot 1
set1 <- filter(nations, country %in% list("China", "Germany", "Japan", "United States"))
p1 <- set1 |>
ggplot(aes(x=year, y=gdp_Trillions, group_by(country), color=country)) +
labs(x = "Year", y = "GDP ($trillion)", title = "China's Rise to Become the Largest Economy") +
geom_line(aes(x = year, y = gdp_Trillions)) +
geom_point(aes(x = year, y = gdp_Trillions)) +
scale_color_brewer(palette = "Set1")
p1 + theme_minimal()Plot 2
regions1 <- group_by(nations, region, year)
regions2 <- summarise(regions1, GDP=sum(gdp_Trillions, na.rm=TRUE))p2 <- regions2 |>
ggplot(aes(x=year, y=GDP, group_by(region), fill=region)) +
labs(x = "Year", y = "GDP ($trillion)", title = "GDP by World Bank Region") +
geom_area(aes(x = year, y = GDP), color="White") +
scale_fill_brewer(palette = "Set2")
p2 + theme_minimal()