In this chunk, I’m going the load the dataset that I picked, “greenhouse_gases”, then I’m going to do some wrangling to check if the Data is clean.
library(ggthemes)library(ggrepel)
Loading required package: ggplot2
data("greenhouse_gases")
Visualization
Here is where I am going to create a code to show you some visualizations. I created a heatmap visualization to explore trends in greenhouse gas concentrations (CO₂, CH₄, N₂O) over time using the greenhouse_gases dataset from the dslabs package in R. The code aggregates yearly average concentrations, then uses geom_tile() to represent these values as colored tiles, where warmer colors (reds) indicate higher concentrations and cooler colors (blues) show lower values
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
✔ lubridate 1.9.4 ✔ tibble 3.2.1
✔ purrr 1.0.4 ✔ tidyr 1.3.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
data("greenhouse_gases")# Summarize data: Average concentration per year per gasheatmap_data <- greenhouse_gases %>%group_by(year, gas) %>%summarise(mean_conc =mean(concentration, na.rm =TRUE)) %>%ungroup()
`summarise()` has grouped output by 'year'. You can override using the
`.groups` argument.
# Create heatmapggplot(heatmap_data, aes(x = year, y = gas, fill = mean_conc)) +geom_tile(color ="white", linewidth =0.3) +# White grid linesscale_fill_gradientn(colors =c("#2c7bb6", "#abd9e9", "#ffffbf", "#fdae61", "#d7191c"),name ="Concentration\n(CO2: ppm | CH4/N2O: ppb)" ) +labs(title ="Greenhouse Gas Concentrations Over Time",x ="Year",y ="Gas Type",caption ="Source: dslabs R package" ) +theme_minimal() +theme(axis.text.x =element_text(angle =90, hjust =1),plot.title =element_text(face ="bold", size =14),legend.position ="right" ) +scale_x_continuous(breaks =seq(0, 2020, by =100)) # Custom x-axis breaks
## Recognition at Chatgpt for the line 75.## Recognition at https://www.youtube.com/channel/UCfJyQ3P2k_SuqfxVdqIEQNw : R Programming 101