class: center, middle, inverse, title-slide # Tidyverse cont’d ### Data Visualization for Social Good
CorrelAid Switzerland
### February 2021 --- layout: true <div class="my-footer"> <span style="text-align:center"> <span> <img src="https://raw.githubusercontent.com/therbootcamp/therbootcamp.github.io/master/_sessions/_image/by-sa.png" height=14 style="vertical-align: middle"/> </span> <a href="https://therbootcamp.github.io/"> <span style="padding-left:82px"> <font color="#7E7E7E"> https://correlaid.org/correlaid-x/switzerland/ </font> </span> </a> <a href="https://correlaid.org/correlaid-x/switzerland/"> <font color="#7E7E7E"> Data Visualization for Social Good | February 2021 </font> </a> </span> </div> --- # The R <mono>tidyverse</mono> can do a lot more .pull-left5[ <font size = 6> 1. `tidyverse` core<br> 2. `tidyverse` extended<br> </font> ] .pull-right5[ <p align="center"><img border="0" alt="W3Schools" src="https://www.oreilly.com/library/view/the-art-of/9781593273842/httpatomoreillycomsourcenostarchimages915868.png.jpg" width="400px"></p> ] --- .pull-left3[ # <mono>tidyverse</mono> core <ul> <li class="m1"><span>The tidyverse is...</span></li><br> <ul class="level"> <li><span>A collection of user-friendly <high>packages</high> for analyzing <high>tidy data</high></span></li><br> <li><span>An <high>ecosystem</high> for analytics and data science with common design principles</span></li><br> <li><span>A <high>dialect</high> of the R language</span></li> </ul> </ul> ] .pull-right6[ <br> <p align="left"> <img src="image/tidyverse.png" style="height:540px"> </p> ] --- .pull-left2[ # `tidyverse` extended <ul> <li class="m1"><span>The tidyverse is...an <high>ecosystem</high> for analytics and data science with common design principles</span></li> </ul> ] .pull-right65[ <br><br> <p align="left"> <img src="image/hexwall.png" style="height:480px"> </p> ] --- # <img src="https://github.com/thomasp85/gganimate/raw/master/man/figures/logo.png" style="height:48px"> <mono>gganimate</mono> <font style="font-size:24px">for animations</font> .pull-left45[ ```r basel %>% ggplot(aes(x = year, col = quarter)) + geom_point(aes(y = wealth_mean)) + geom_line(aes(y = wealth_mean)) + guides(col = FALSE) + theme_minimal() + # add animation transition_reveal(year) ``` ] .pull-right45[ <p align="center"> <img src="image/lines_anim.gif" style="height:420px"> </p> ] --- # <img src="https://github.com/thomasp85/gganimate/raw/master/man/figures/logo.png" style="height:48px"> <mono>gganimate</mono> <font style="font-size:24px">for animations</font> .pull-left5[ ```r plot = basel_map %>% # original code left_join(basel, by = c('TYPE' = 'quarter')) %>% ggplot(aes(fill = wealth_mean)) + geom_sf(col = 'white') + guides(fill = FALSE) + theme_void() + # add animation ggtitle("{closest_state}") + theme(plot.title = element_text( hjust = 0.5,size=20)) + transition_states(year) ``` ] .pull-right45[ <p align="center"> <img src="image/map_anim.gif" style="height:420px"> </p> ] --- # <img src="https://avatars.githubusercontent.com/u/5997976?s=200&v=4" style="height:48px"> <mono>plotly</mono> <font style="font-size:24px">for interactive graphics</font> .pull-left5[ ```r # original plot plot <- basel_map %>% left_join(basel, by = c('TYPE' = 'quarter')) %>% ggplot(aes(x = year, col = TYPE)) + geom_point(aes(y = wealth_mean)) + geom_line(aes(y = wealth_mean)) + guides(col = FALSE) + theme_minimal() # plotlify ggplotly(plot) ``` ] .pull-right45[
] --- .pull-left45[ # <img src="https://github.com/rstudio/hex-stickers/raw/master/PNG/rmarkdown.png" style="height:48px"> <mono>RMarkdown</mono> <font style="font-size:24px">for reports</font> <p align="left"><img style="height:440px" src="image/markdown_map.png"></p> ] .pull-right45[ <br><br> <p align="center"><img style="height:510px;box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);" src="image/markdown_map_pdf.png"></p> ] --- # <img src="https://github.com/rstudio/hex-stickers/raw/master/PNG/shiny.png" style="height:48px"> <mono>shiny</mono> <font style="font-size:24px">for web apps</font> .pull-left45[ ```r ui <- fluidPage( tabsetPanel( tabPanel( selectInput( "var", "Variable", choices = list("wealth_mean", "wealth_median", "wealth_gini"))), mainPanel(plotOutput("basel")))) server <- function(input, output) { output$basel <- renderPlot({ ggplot(map) + geom_sf( col = 'white', mapping = aes_string( fill = input$var)) + guides(fill = FALSE) + theme_void()})} ``` ] .pull-right45[ <iframe width="400" height="600" src="https://econpsychbasel.shinyapps.io/basel/" frameborder="0" allowfullscreen></iframe> ] --- # <img src="https://github.com/rstudio/hex-stickers/raw/master/PNG/rvest.png" style="height:48px"> <mono>rvest</mono> <font style="font-size:24px">for web scraping</font> ```r # Tabelle laden von Wikipedia (Pakete nicht vergessen) read_html("https://en.wikipedia.org/wiki/R_(programming_language)") %>% html_node(xpath = '//*[@id="mw-content-text"]/div[1]/table[2]') %>% html_table() %>% as_tibble() ``` ``` ## # A tibble: 21 x 3 ## Release Date Description ## <chr> <chr> <chr> ## 1 0.16 "" "This is the last alpha version developed primarily by Ihaka and G… ## 2 0.49 "1997-04-2… "This is the oldest source release which is currently available on… ## 3 0.60 "1997-12-0… "R becomes an official part of the GNU Project. The code is hosted… ## 4 0.65.1 "1999-10-0… "First versions of update.packages and install.packages functions … ## 5 1.0 "2000-02-2… "Considered by its developers stable enough for production use.[55… ## 6 1.4 "2001-12-1… "S4 methods are introduced and the first version for Mac OS X is m… ## 7 1.8 "2003-10-0… "Introduced a flexible condition handling mechanism for signalling… ## 8 2.0 "2004-10-0… "Introduced lazy loading, which enables fast loading of data with … ## 9 2.1 "2005-04-1… "Support for UTF-8 encoding, and the beginnings of internationaliz… ## 10 2.6.2 "2008-02-0… "Last version to support Windows 95, 98, Me and NT 4.0[56]" ## # … with 11 more rows ``` --- # <img src="https://cran.r-project.org/web/packages/tidytext/readme/man/figures/tidytext.png" style="height:48px"> <mono>tidytext</mono> <font style="font-size:24px">for text analysis</font> .pull-left5[ ```r # Wörter zählen counts <- read_html(".../R_(programming_language)") %>% html_text() %>% tibble() %>% unnest_tokens(w, ".") %>% filter(!str_detect(w, '[:digit:]')) %>% anti_join(stop_words) %>% count(word, sort = TRUE) %>% top_n(100) # Wordwolke wordcloud(counts$word, counts$n) ``` ] .pull-right4[ ![](NextSteps_files/figure-html/unnamed-chunk-10-1.png)<!-- --> ] --- # <img src="https://www.tidymodels.org/images/tidymodels.png" style="height:48px"> <mono>tidymodels</mono> <font style="font-size:24px">for machine learning</font> .pull-left4[ <ul> <li class="m1"><span>Framework for machine learning.</span></li><br> <li class="m2"><span>Includes</span></li> <ul class="level"> <li><span>All sorts of models, including wrapper to <a href="https://keras.rstudio.com/">keras</a>, for deep learning.</span></li> <li><span>Model tuning</span></li> <li><span>Model evaluation</span></li> <li><span>etc.</span></li> </ul> </ul> ] .pull-right45[ <p align="center"><img src="image/tidymodels.png" style="height:420px"></p> ] --- .pull-left45[ # <img src="https://dbplyr.tidyverse.org/logo.png" style="height:48px"> <mono>dbplyr</mono><br> <font style="font-size:24px">for wrangling remote databases</font> <ul> <li class="m1"><span>R tidyverse is able to interface with most database types</high>: <mono>MySQL</mono>, <mono>MariaDB</mono>, <mono>BigQuery</mono>, <mono>Redshift</mono>, etc. See <a href="https://db.rstudio.com/databases">db.rstudio.com</a>.</font></span></li> <li class="m2"><span><mono>dplyr</mono> will be <high>translated in the backround</high> to the appropriate query language</span></li> </ul> ] .pull-right45[ <br> ```r # Verbinge mit MySQL Datenbank con <- dbConnect(MySQL(), user='studiech_rbootca', password='Du*5hA+7NU:8T', dbname='studiech_rbootcamp', host='studie.ch', port = 3306) # Extrahiere Tabelle Customers basel <- tbl(con, "basel") basel ``` ``` ## # Source: table<basel> [?? x 20] ## # Database: mysql 5.7.26-log-cll-lve ## # [studiech_rbootca@studie.ch:/studiech_rbootcamp] ## id geschlecht alter_jahre groesse ## <dbl> <chr> <dbl> <dbl> ## 1 1 f 87 165 ## 2 2 m 54 175. ## 3 3 f 34 147. ## 4 4 m 31 166. ## 5 5 m 24 180. ## # … with more rows, and 16 more ## # variables ``` ] --- # Books An incomplete list of good books loosely sorted by required amount of R experience.<br><br> <table width="80%" style="cellspacing:0; cellpadding:0; border:none;"> <tr> <td> <a href="http://r4ds.had.co.nz/"><img border="0" alt="W3Schools" src="http://r4ds.had.co.nz/cover.png" height="180"></a> </td> <td> <a href="https://covers.oreillystatic.com/images/0636920028574/cat.gif"><img border="0" alt="W3Schools" src="https://covers.oreillystatic.com/images/0636920028574/cat.gif" height="180"></a> </td> <td> <a href="https://ggplot2-book.org/"><img border="0" alt="W3Schools" src="https://images-na.ssl-images-amazon.com/images/I/31uoy-qmhEL._SX331_BO1,204,203,200_.jpg" height="180"></a> </td> <td> <a href="https://www.springer.com/de/book/9783540799979"><img border="0" alt="W3Schools" src="https://images.springer.com/sgw/books/medium/9783540799979.jpg" height="180" ></a> </td> <td> <a href="https://bookdown.org/ndphillips/YaRrr/"><img border="0" alt="W3Schools" src="https://bookdown.org/ndphillips/YaRrr/images/YaRrr_Cover.jpg" height="180" ></a> </td> <td> <a href="https://www.orellfuessli.ch/shop/home/artikeldetails/ID35367941.html?ProvID=10917736&gclid=Cj0KCQiAg_HhBRDNARIsAGHLV5238Q26gQmFttHRnYGjcAhz4CslStb-3qBegvuZS5gnCpWSLNlQvF0aAgfOEALw_wcB"><img border="0" alt="W3Schools" src="https://assets.thalia.media/img/35367941-00-00.jpg" height="180" ></a> </td> </tr> <tr style="background-color:#ffffff"> <td> <a href="http://appliedpredictivemodeling.com/"><img border="0" alt="W3Schools" src="http://static1.squarespace.com/static/51156277e4b0b8b2ffe11c00/t/51157487e4b0b8b2ffe16829/1509217882069/?format=1500w" height="180" ></a> </td> <td> <a href="http://www-bcf.usc.edu/~gareth/ISL/ISLR%20First%20Printing.pdf"><img border="0" alt="W3Schools" src="https://images-na.ssl-images-amazon.com/images/I/41EaH4W9LVL._SX332_BO1,204,203,200_.jpg" height="180" ></a> </td> <td> <a href="https://www.manning.com/books/deep-learning-with-r"><img border="0" alt="W3Schools" src="https://images-na.ssl-images-amazon.com/images/I/51h5d4dYaoL._SX396_BO1,204,203,200_.jpg" height="180" ></a> </td> <td> <a href="https://csgillespie.github.io/efficientR/"><img border="0" alt="W3Schools" src="https://csgillespie.github.io/efficientR/figures/f0_web.png" height="180" ></a> </td> <td> <a href="www.rcpp.org/"><img border="0" alt="W3Schools" src="https://assets.thalia.media/img/artikel/09be684f8f904312649b0aabdf417c7992cbcdad-00-00.jpeg" height="180" ></a> </td> <td> <a href="http://adv-r.had.co.nz/"><img border="0" alt="W3Schools" src="https://images-na.ssl-images-amazon.com/images/I/41RJLhZ32VL._SX329_BO1,204,203,200_.jpg" height="180" ></a> </td> </tr> </table> <br> --- class: center, middle # Thank you!