# Check structure of the datasetstr(greenhouse_gases)
'data.frame': 300 obs. of 3 variables:
$ year : num 20 40 60 80 100 120 140 160 180 200 ...
$ gas : chr "CO2" "CO2" "CO2" "CO2" ...
$ concentration: num 278 278 277 277 278 ...
Data Visualisation
# Create heatmapgreenhouse_gases %>%ggplot(aes(x = year, y = gas, fill = concentration)) +geom_tile() +scale_fill_viridis_c(option ="C") +labs(title ="Heatmap of Greenhouse Gas Concentrations",subtitle ="Greenhouse gas concentrations across 2000 years",x ="Year",y ="Gas Type",fill ="Concentration" ) +theme_minimal() +theme(plot.title =element_text(size =16, face ="bold"),plot.subtitle =element_text(size =12),axis.title =element_text(size =12),legend.title =element_text(size =11) )
# Assisted by chatgpt to write code for changing the font of the heading, axes labels and legend.
Graph Description
In this assignment, I used the greenhouse gases dataset from the ds labs package. This dataset looks into the historical atmospheric concentration of three greenhouse gases, i.e., carbon dioxide (CO₂), methane (CH₄), and nitrous oxide (N₂O), spanning the course of 2000 years. I created a heatmap to show how the concentrations of these gases have changed over those years. In the graph, the x-axis represents the year, the y-axis shows the gas type, and the color fill represents concentration levels. I used the geom_tile() function to create the heatmap and applied viridis color palette (“option C”) using scale_fill_viridis_c(). I changed the font sizes of the headings, axis labels, and legend in the theme_minimal() base, which enhanced the overall presentation of the graph. This heatmap shows the stability of greenhouse gas levels throughout the majority of history and a sharp increase in concentrations during recent centuries, especially after the Industrial Revolution.