library (tidyverse)Nations HW
setwd("/Users/jeffreyren/Downloads/Directory")
data <- read_csv("nations.csv")data <- data |>
mutate(gdp_trillion = (gdp_percap * population) / 1e12)
data1 <- data |>
filter(country %in% c("China", "United States", "Japan", "Australia"))graph1 <- ggplot(data1, aes(x = year, y = gdp_trillion, color = country)) +
geom_point() +
geom_line() +
scale_color_brewer(palette = "Set1") +
labs(title = "GDP of China, U.S., Japan, and Australia",
x = "Years",
y = "GDP (in trillions of $)")
graph1data2 <- 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.
graph2 <- ggplot(data2, aes(x = year, y = GDP, fill = region)) +
geom_area(color = "white") +
scale_fill_brewer(palette = "Set2") +
labs(title = "GDP by Region",
x = "Years",
y = "GDP (in trillions of $)",
fill = "Region")
graph2