Week 8

Loading DSLabs

Loading DSLabs to explore datasets to work with.

library("dslabs")
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-calificaciones.R"               
 [5] "make-death_prob.R"                   
 [6] "make-divorce_margarine.R"            
 [7] "make-gapminder-rdas.R"               
 [8] "make-greenhouse_gases.R"             
 [9] "make-historic_co2.R"                 
[10] "make-mice_weights.R"                 
[11] "make-mnist_127.R"                    
[12] "make-mnist_27.R"                     
[13] "make-movielens.R"                    
[14] "make-murders-rda.R"                  
[15] "make-na_example-rda.R"               
[16] "make-nyc_regents_scores.R"           
[17] "make-olive.R"                        
[18] "make-outlier_example.R"              
[19] "make-polls_2008.R"                   
[20] "make-polls_us_election_2016.R"       
[21] "make-pr_death_counts.R"              
[22] "make-reported_heights-rda.R"         
[23] "make-research_funding_rates.R"       
[24] "make-stars.R"                        
[25] "make-temp_carbon.R"                  
[26] "make-tissue-gene-expression.R"       
[27] "make-trump_tweets.R"                 
[28] "make-weekly_us_contagious_diseases.R"
[29] "save-gapminder-example-csv.R"        

Choosing a Data Set

data("greenhouse_gases")

Greenhouse gases seemed the most interesting, so let’s explore that further.

Loading More Libraries

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.4.4     ✔ 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(RColorBrewer)
library(ggthemes)

Modifying the Data

Mod_Green <- greenhouse_gases |>
  filter(year >=1800 & year <=2000)

I used the filter command to narrow down data to only include things recorded between the years 1800 and 2000.

Creating the Visualization

ggplot(Mod_Green, aes(x = year, y = concentration, color = gas)) +
  ggtitle("Greenhouse Gases Over The Years") +
  xlab("Year") + 
  ylab("Concentration Levels") + 
  theme_minimal(base_size = 12) +
  geom_point() + 
  geom_line() + 
  scale_color_brewer(palette = 'Accent')

Using ggplot, I was able to create this visualization. The measurement for concentration wasn’t provided, so I didn’t specify it on the y-axis.

Summary

For this visualization, I used the “Greenhouse Gases” data set from DSLabs. After looking at the data set, I used the filter command to only include data between the years of 1800 and 2000. As stated in the previous chunk, I did not include a measurement for the concentration levels. I did not want to assume and provide false information, so I only included the numbers provided in the data set.