Dslabs: death_prob

Author

Arif

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.2     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.4.2     ✔ tibble    3.2.1
✔ lubridate 1.9.2     ✔ tidyr     1.3.0
✔ purrr     1.0.1     
── 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("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-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-mice_weights.R"                 
[10] "make-mnist_27.R"                     
[11] "make-movielens.R"                    
[12] "make-murders-rda.R"                  
[13] "make-na_example-rda.R"               
[14] "make-nyc_regents_scores.R"           
[15] "make-olive.R"                        
[16] "make-outlier_example.R"              
[17] "make-polls_2008.R"                   
[18] "make-polls_us_election_2016.R"       
[19] "make-reported_heights-rda.R"         
[20] "make-research_funding_rates.R"       
[21] "make-stars.R"                        
[22] "make-temp_carbon.R"                  
[23] "make-tissue-gene-expression.R"       
[24] "make-trump_tweets.R"                 
[25] "make-weekly_us_contagious_diseases.R"
[26] "save-gapminder-example-csv.R"        
data("death_prob")
library(highcharter)
Registered S3 method overwritten by 'quantmod':
  method            from
  as.zoo.data.frame zoo 
Highcharts (www.highcharts.com) is a Highsoft software product which is
not free for commercial and Governmental use

Attaching package: 'highcharter'
The following object is masked from 'package:dslabs':

    stars
library(RColorBrewer)
highchart () %>%
  hc_add_series(data = death_prob,
                   type = "area",
                   hcaes(x=age,
                   y = prob, 
                   group = sex))
cols <- brewer.pal(4, "Set1")
highchart () %>%
  hc_add_series(data = death_prob,
                   type = "area",
                   hcaes(x = age,
                   y = prob, 
                   group = sex)) %>%
  hc_colors(cols) %>% 
  hc_chart(style = list(fontFamily = "Georgia",
                        fontWeight = "bold")) %>%
  hc_plotOptions(series = list(stacking = "normal",
                               marker = list(enabled = FALSE,
                               states = list(hover = list(enabled = FALSE))),
                               lineWidth = 0.5,
                               lineColor = "white")) %>%
  hc_xAxis(title = list(text="Year")) %>%
  hc_yAxis(title = list(text="Death Probability")) %>%
  hc_legend(align = "right", verticalAlign = "bottom",
            layout = "horizontal") 
cols <- brewer.pal(4, "Set1")
highchart() %>%
  hc_add_series(data = death_prob,
                   type = "line",
                   hcaes(x = age,
                   y = prob, 
                   group = sex)) %>%
  hc_colors(cols) %>%
  hc_xAxis(title = list(text="Age")) %>%
  hc_yAxis(title = list(text="Death Probability")) %>%
  hc_plotOptions(series = list(marker = list(symbol = "square"))) %>%
  hc_legend(align = "right", 
            verticalAlign = "top")