Introduction.

What is Global Warming?

According to NASA, global warming is the unusually rapid increase in Earths average surface temperature over the past century primarily due to the greenhouse gases released by people burning fossil fuels. The three most important greenhouse gases in the atmosphere are carbon dioxide (CO2), methane (CH4) and nitrrous oxide (N2O). While carbon dioxide is the greenhouse gas we hear the most about, methane and nitrous oxide have greater global warming potential (GWP) too and thus warm up the climate quicker requiring a response from everyone.

#Install.packages(“dslabs”) # these are data science labs

#Installing other essential packages for ggplot2 and hicharter using pacman

pacman::p_load(tidyverse,devtools, zoo, ggsci,plotly, DT, highcharter,BiocManager, RColorBrewer, dslabs)

What is DSLabs?

Dslabs stance for data science labs which is a package that contains a number of datasets which are listed below

data(package="dslabs")
list.files(system.file("script", package = "dslabs"))
##  [1] "make-admissions.R"                   
##  [2] "make-brca.R"                         
##  [3] "make-brexit_polls.R"                 
##  [4] "make-death_prob.R"                   
##  [5] "make-divorce_margarine.R"            
##  [6] "make-gapminder-rdas.R"               
##  [7] "make-greenhouse_gases.R"             
##  [8] "make-historic_co2.R"                 
##  [9] "make-mnist_27.R"                     
## [10] "make-movielens.R"                    
## [11] "make-murders-rda.R"                  
## [12] "make-na_example-rda.R"               
## [13] "make-nyc_regents_scores.R"           
## [14] "make-olive.R"                        
## [15] "make-outlier_example.R"              
## [16] "make-polls_2008.R"                   
## [17] "make-polls_us_election_2016.R"       
## [18] "make-reported_heights-rda.R"         
## [19] "make-research_funding_rates.R"       
## [20] "make-stars.R"                        
## [21] "make-temp_carbon.R"                  
## [22] "make-tissue-gene-expression.R"       
## [23] "make-trump_tweets.R"                 
## [24] "make-weekly_us_contagious_diseases.R"
## [25] "save-gapminder-example-csv.R"

Greenhouse Gas Dataset

We have decided to work with the greenhouse gas dataset from the dslabs package installed above This dataset has three variables or columns (year, gas and concentration level of those gasses in different and varying number of years ). We have different gasses, CO2, CH4 and N2O

view(greenhouse_gases)
write_csv(murders, "greenhouse_gases")

Representing the concentration of greenhouse gasses in the atmosphere for the past 300 to 2000 years using a point-line chart with ggplot2 and hicharter.

Line-point chart of atmospheric gasseous concentration using ggplot2 (first)

Fortunately for us, our dataset is already very clean and well sorted out, we first filter the only three most important gasses (CO2,CH4,Nin the atmosphere O). We draw our sample for the last 300 years (from 1700 to 2000), then we add a title and lable the X and Y axis too

#renaming our dataset after some mordification
gas_polution <- greenhouse_gases %>% 
  filter(gas == c("N2O", "CH4", "CO2")) %>% 
  ggplot(aes(x = year, y = concentration)) + 
   xlim(1700,2000) +
  labs(title = "Representing Greenhouse Gas Emissions for the last 300 years",
  caption = "Source: The Data Science labs Package") +
       xlab("Year") +
       ylab("Concentration of Gases ") +
  theme_light(base_size = 20)

Now using the new dataset from greenhouse gas emission (gas_population), we then draw the line chart

gas_polution +
  geom_line(aes( color = gas)) +
  geom_point() +
  labs(color = "Gas") +
  scale_color_brewer(palette = "Dark2")
## Warning: Removed 84 row(s) containing missing values (geom_path).
## Warning: Removed 84 rows containing missing values (geom_point).

Line-point chart of atmospheric gasseous concentration using Highcharter (second)

We also need to clean, arrange and rename the greenhouse gas dataset if in case it wasn’t clean but forturnately for us, dslabs supplies already cleaned up data.

Greenhouse_gasses <- greenhouse_gases %>% 
  filter(gas == c("N2O", "CH4", "CO2"))
cols <- brewer.pal(5, "Dark2")

We will be able to use hicharter to produce the line chart that shows the representation of greenhouse gasses in the atmosphere for the last 2000 years as per the dataset reveals. Also we are able to add a title, move the lgend to the top, add lables to the X and Y-axis

highchart() %>%
  hc_add_series(data = Greenhouse_gasses,
                   type = "line",
                   hcaes(x = year,
                   y = concentration, 
                   group = gas)) %>%
  hc_colors(cols) %>%
  hc_title(text = "Representing Greenhouse Gas Emissions for the last 2000 years",
           margin = 20,
           align = "center",
           style = list(color = "Black",fontWeight = "bold", useHTML = TRUE)) %>%
   hc_caption(
    text = "Source: The Data Science labs Package",
    align = "left",
    style = list(color = "red", fontWeight = "bold")) %>% 
  hc_xAxis(title = list(text="Year",style = list(color = "black", fontWeight = "bold"))) %>%
  hc_yAxis(title = list(text="Concentration of Gases", style = list(color = "black", fontWeight = "bold"))) %>%
  hc_plotOptions(series = list(marker = list(symbol = "circle"))) %>%
  hc_legend(align = "right", 
            verticalAlign = "top") %>% 
  hc_tooltip(shared = T,
             borderColor = "Black",
             pointFormat = "{point.gas} : {point.concentration:.2f}<br>")