This dataset, taken from the DS Labs in R, aims to investigate how CO2 levels have changed over the past 800,000 years, particularly during the period from 1880 to 2001, which aligns with the onset of the Industrial Revolution.
These libraries will help me plot graph and others in my analysis
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(highcharter)
Registered S3 method overwritten by 'quantmod':
method from
as.zoo.data.frame zoo
Attaching package: 'highcharter'
The following object is masked from 'package:dslabs':
stars
library(ggthemes)library(ggrepel)
loading the data set
This is loading the data set for the historic levels of co2
data("historic_co2")view(historic_co2)
Ploting co2 concentration in the atmospher over 800000years
using the ggplot library in tidyverse to plot the line graph of co2 for over 80000years
scale_x_continuous(labels = number_format()) +minimal() removes the scientific notation on the x axis
library(ggplot2)library(scales)
Attaching package: 'scales'
The following object is masked from 'package:purrr':
discard
The following object is masked from 'package:readr':
col_factor
ggplot(historic_co2, aes(x = year, y = co2)) +geom_line(color ="red") +labs(title ="Historic CO2 Levels in the atm over 800000 years",x ="Year",y ="CO2 Concentration (ppm)") +scale_x_continuous(labels =number_format()) +# Removes scientific notation for yeartheme_minimal()
for the highchart for co2 cocentration over 800000years
using the library highchart to create an interactive line graph which shows you the levels of co2
highchart() %>%hc_add_series(data = historic_co2, type ="line", hcaes(x = year, y = co2), name ="CO2 Levels") %>%hc_title(text ="Historic CO2 Levels in the atms Over 800000years") %>%hc_xAxis(title =list(text ="Year")) %>%hc_yAxis(title =list(text ="CO2 Concentration")) %>%hc_tooltip(shared =TRUE) %>%hc_chart(type ="line") %>%hc_add_theme(hc_theme_google())
Filter the dataset for years between 1880 and 2001
this chunk filters out only years from 1880 to 2001
df <- historic_co2 %>%filter(year >=1880& year <=2001)
line graph for co2 concentration from 1880 to 2001
creating the line line graph using the ggplot library in tidyverse
ggplot(df, aes(x = year, y = co2)) +geom_line(color ="red") +labs(title ="Co2 Levels from 1880 to 2001",x ="Year",y ="CO2 Concentration (ppm)") +theme_minimal()
creating a highchart for from 1880 to 2001
creating an interactive line graph from 1880 to 2001 using the library highchart
highchart() %>%hc_add_series(data = df, type ="line", hcaes(x = year, y = co2), name ="CO2 Levels") %>%hc_title(text ="CO2 Levels from 1880 to 2001") %>%hc_xAxis(title =list(text ="Year")) %>%hc_yAxis(title =list(text ="CO2 Concentration (ppm)")) %>%#hc_tooltip(shared = TRUE) %>%#hc_chart(type = "line") %>%hc_add_theme(hc_theme_google())
Disccusion
From 1880 to 2001, a clear upward trend in carbon dioxide (CO2) levels is evident, particularly following the Industrial Revolution. This period marked a significant transformation in energy production and consumption, as societies shifted from agrarian economies to industrialized ones. The burning of fossil fuels, especially coal, became a primary energy source for factories, transportation, and electricity generation. This dramatic increase in coal usage, along with the development of various industrial machinery and processes, led to substantial CO2 emissions, contributing to a notable rise in atmospheric carbon levels.
While the dataset may not explicitly identify all contributing factors, it is reasonable to assume that these industrial practices are significant causes of increased CO2 levels. However, it is important to remember that correlation does not imply causation; just because two trends coincide does not mean one directly causes the other. A thorough analysis of the historical context and additional factors influencing CO2 emissions is essential for understanding the complexities of climate change and its drivers.
Conclusion
I did not encounter any problems with this dataset, as it was already cleaned; however, it has two sources of data collection: ice cores and Mauna Loa. While both sources exhibit a lot of similarities in their datasets, they produce two distinct lines on the chart, highlighting slight variations in CO2 measurements over time.