# Load required packages
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
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── 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(dslabs)
setwd("C:/Users/jman1/OneDrive/Documents/DATA110 Folder")
# Load co2 dataset
co2 <- read_csv("co2.csv")
## Rows: 225 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): month
## dbl (2): year, co2_level
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#Create heatmap
co2_plot <- ggplot(co2, aes(x = year, y = month, fill = co2_level)) +
geom_tile() +
labs(x = "Year",
y = "Month",
fill = "CO2 Level",
title = "Carbon Dioxide Levels by Year and Month") +
scale_fill_gradient(low = "#d6b213", high = "#d43017") +
theme_classic(base_size = 15) +
theme(plot.title = element_text(hjust = 0.5, face = "bold"))
co2_plot

I have created my heatmap using the co2 dataset. I use geom_tile()
and ggplot to create my heatmap with year on the x-axis and month on the
y-axis. I add my labels in and change up the default colors some to make
my graph more visually appealing and then use theme_classic to indicate
the years and months clearly. I finally center the title and embolden it
to make it more visible.