R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

devtools::install_github("hrbrmstr/streamgraph")
## Skipping install of 'streamgraph' from a github remote, the SHA1 (76f7173e) has not changed since last install.
##   Use `force = TRUE` to force installation
devtools::session_info()
## - Session info ----------------------------------------------------------
##  setting  value                       
##  version  R version 3.5.1 (2018-07-02)
##  os       Windows 10 x64              
##  system   x86_64, mingw32             
##  ui       RTerm                       
##  language (EN)                        
##  collate  English_United States.1252  
##  ctype    English_United States.1252  
##  tz       America/New_York            
##  date     2019-09-23                  
## 
## - Packages --------------------------------------------------------------
##  package     * version date       lib source        
##  assertthat    0.2.0   2017-04-11 [1] CRAN (R 3.5.2)
##  backports     1.1.4   2019-04-10 [1] CRAN (R 3.5.3)
##  callr         3.2.0   2019-03-15 [1] CRAN (R 3.5.3)
##  cli           1.1.0   2019-03-19 [1] CRAN (R 3.5.3)
##  crayon        1.3.4   2017-09-16 [1] CRAN (R 3.5.2)
##  curl          3.3     2019-01-10 [1] CRAN (R 3.5.3)
##  desc          1.2.0   2018-05-01 [1] CRAN (R 3.5.3)
##  devtools      2.2.0   2019-09-07 [1] CRAN (R 3.5.3)
##  digest        0.6.18  2018-10-10 [1] CRAN (R 3.5.3)
##  DT            0.9     2019-09-17 [1] CRAN (R 3.5.1)
##  ellipsis      0.1.0   2019-02-19 [1] CRAN (R 3.5.3)
##  evaluate      0.13    2019-02-12 [1] CRAN (R 3.5.3)
##  fs            1.3.1   2019-05-06 [1] CRAN (R 3.5.3)
##  glue          1.3.1   2019-03-12 [1] CRAN (R 3.5.3)
##  htmltools     0.3.6   2017-04-28 [1] CRAN (R 3.5.3)
##  htmlwidgets   1.3     2018-09-30 [1] CRAN (R 3.5.3)
##  knitr         1.22    2019-03-08 [1] CRAN (R 3.5.3)
##  magrittr      1.5     2014-11-22 [1] CRAN (R 3.5.2)
##  memoise       1.1.0   2017-04-21 [1] CRAN (R 3.5.3)
##  pkgbuild      1.0.5   2019-08-26 [1] CRAN (R 3.5.3)
##  pkgload       1.0.2   2018-10-29 [1] CRAN (R 3.5.3)
##  prettyunits   1.0.2   2015-07-13 [1] CRAN (R 3.5.2)
##  processx      3.3.0   2019-03-10 [1] CRAN (R 3.5.3)
##  ps            1.3.0   2018-12-21 [1] CRAN (R 3.5.3)
##  R6            2.3.0   2018-10-04 [1] CRAN (R 3.5.2)
##  Rcpp          1.0.2   2019-07-25 [1] CRAN (R 3.5.3)
##  remotes       2.1.0   2019-06-24 [1] CRAN (R 3.5.3)
##  rlang         0.4.0   2019-06-25 [1] CRAN (R 3.5.3)
##  rmarkdown     1.12    2019-03-14 [1] CRAN (R 3.5.3)
##  rprojroot     1.3-2   2018-01-03 [1] CRAN (R 3.5.3)
##  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 3.5.3)
##  stringi       1.4.3   2019-03-12 [1] CRAN (R 3.5.3)
##  stringr       1.4.0   2019-02-10 [1] CRAN (R 3.5.3)
##  testthat      2.2.1   2019-07-25 [1] CRAN (R 3.5.3)
##  usethis       1.5.1   2019-07-04 [1] CRAN (R 3.5.3)
##  withr         2.1.2   2018-03-15 [1] CRAN (R 3.5.3)
##  xfun          0.6     2019-04-02 [1] CRAN (R 3.5.3)
##  yaml          2.2.0   2018-07-25 [1] CRAN (R 3.5.2)
## 
## [1] C:/Users/Jennifer/Documents/R/win-library/3.5
## [2] C:/Program Files/R/R-3.5.1/library
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.5.3
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(babynames)
## Warning: package 'babynames' was built under R version 3.5.3
library(streamgraph)
babynames %>% 
   filter(grepl("^Kr", name)) %>%
   group_by(year, name) %>%
   tally(wt=n) %>%
   streamgraph("name", "n", "year")
babynames %>%
    filter(grepl("^I", name)) %>%
  filter(grepl("^18", year)) %>%
    group_by(year, name) %>%
   tally(wt=n) %>%
   streamgraph("name", "n", "year", offset="zero", interpolate="linear") %>%
   sg_legend(show=TRUE, label="I- names: ")
head(babynames)
## # A tibble: 6 x 5
##    year sex   name          n   prop
##   <dbl> <chr> <chr>     <int>  <dbl>
## 1  1880 F     Mary       7065 0.0724
## 2  1880 F     Anna       2604 0.0267
## 3  1880 F     Emma       2003 0.0205
## 4  1880 F     Elizabeth  1939 0.0199
## 5  1880 F     Minnie     1746 0.0179
## 6  1880 F     Margaret   1578 0.0162
dim(babynames)
## [1] 1924665       5
str(babynames)
## Classes 'tbl_df', 'tbl' and 'data.frame':    1924665 obs. of  5 variables:
##  $ year: num  1880 1880 1880 1880 1880 1880 1880 1880 1880 1880 ...
##  $ sex : chr  "F" "F" "F" "F" ...
##  $ name: chr  "Mary" "Anna" "Emma" "Elizabeth" ...
##  $ n   : int  7065 2604 2003 1939 1746 1578 1472 1414 1320 1288 ...
##  $ prop: num  0.0724 0.0267 0.0205 0.0199 0.0179 ...