DS Labs

Author

Ike Charistan

DS Labs Datasets

Loading the package DSLabs

In this chunk, I am just loading the package into the dataset that I am going 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"        

Loading the Dataset

In this chunk, I’m going the load the dataset that I picked, “greenhouse_gases”, then I’m going to do some wrangling to check if the Data is clean.

Visualisation

In this code, I filtered the dataset to include only the years 20, 40, 60, 80, and 100. Then, I created a scatterplot to show how the concentration of different gases changed during those selected years. Each point represents a gas, with different colors showing different gas types. I also added a smooth trend line to show the overall pattern, and customized the plot with a title, axis labels, and a clean black-and-white theme.

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.4     ✔ tidyr     1.3.1
✔ purrr     1.0.4     
── 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
greenhouse_gases |>
  filter(year %in% c(20, 40, 60, 80, 100)) |>
  ggplot(aes(x = year, y = concentration)) +
  geom_point(aes(color = gas), alpha = 0.5) +
  geom_smooth() +
  labs(
    x = "Year",
    y = "Concentration",
    color = "Gas",
    title = "Concentration of Gas at Selected Years"
  ) +
  theme(legend.position = c(0.11, 0.78)) +
  theme_bw()
Warning: A numeric `legend.position` argument in `theme()` was deprecated in ggplot2
3.5.0.
ℹ Please use the `legend.position.inside` argument of `theme()` instead.
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'