Nations Chart- Jason Laucel

Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

Running Code

When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

1 + 1
[1] 2

You can add options to executable code like this

[1] 4

The echo: false option disables the printing of code (only output is displayed).

nations_data <- read.csv("/Users/jasonlaucel/Downloads/nations.csv")
# new variable using mutate

nations_data <- mutate(nations_data, GDP_trillion = gdp_percap * population / 10^12)
# Chart 1 using dplyr, and necessary geom's, and palette

chart1 <- nations_data %>%
  filter(country %in% c("Bolivia", "Ecuador", "Grenada", "Georgia")) %>%
  ggplot(aes(x = year, y = GDP_trillion, color = country)) +
  geom_point() +
  geom_line() +
  scale_color_brewer(palette = "Set1")
# Extra measure to ensure data is numeric for calculations

nations_data$gdp <- as.numeric(nations_data$gdp)
# Chart 2 w/ dplyr group, summarise mutate, set 2

suppressMessages({

chart2 <- nations_data %>%
  group_by(region, year, .groups = "drop") %>%
  summarise(GDP = sum(gdp, na.rm = TRUE)) %>%
  ggplot(aes(x = year, y = GDP, fill = region)) +
  geom_area(color = "white", size = 0.1) +
  scale_fill_brewer(palette = "Set2") +
  scale_y_continuous(labels = scales::comma) +  # Format y-axis labels with commas
  theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 8))  # Angle and adjust font size of x-axis labels
}
)
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
print(chart1)

print(chart2)