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:
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.2.0 ✔ readr 2.1.6
✔ forcats 1.0.1 ✔ stringr 1.6.0
✔ ggplot2 4.0.2 ✔ tibble 3.3.1
✔ lubridate 1.9.5 ✔ tidyr 1.3.2
✔ purrr 1.2.1
── 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)setwd("C:/Users/gun26/OneDrive/Desktop/Data-110/w6")nations<-read.csv("nations.csv")nations_m <- nations %>%mutate(gdp_tn = (gdp_percap*population)/10^12)chart1_data <- nations_m %>%filter(country %in%c("China", "Germany", "Japan", "United States"))ggplot(chart1_data, aes(x = year, y = gdp_tn, color = country)) +geom_line() +geom_point() +scale_color_brewer(palette="Set1") +labs(title ="GDP in Trillions for Four Countries",x ="Year", y ="GDP (Trillions $)")+theme_minimal()
chart2_data <- nations_m %>%group_by(region, year) %>%summarise(total_gdp =sum(gdp_tn, na.rm =TRUE), .groups ="drop")ggplot(chart2_data, aes(x = year, y = total_gdp, fill = region)) +geom_area(color ="white", linewidth =0.2) +scale_fill_brewer(palette ="Set2") +labs(title ="GDP by Region", x ="Year", y ="Total GDP (Trillions $)") +theme_minimal()