Loading…
Transcript

The R dataviz world

www.milanor.net

20 Nov 2017 - Mariachiara Fortuna - 9th MilanoR meeting

The history

plotly

The history

flexdashboard

ggmap

shinydashboard

r2d3

A first version of R is released under GNU licence

ggplot2 is released

by Hadley Wickham

RStudio fundation

htmlwidget

Shiny is released by RStudio

Lattice

leaflet

2001

2008

1995

2005

2012

2015

2014

2016

2011

2017

Plotting

Plotting

- R base: graphics, lattice

- ggplot2

R base

R's base graphics are implemented in the same way as in the S3 system developed by Becker, Chambers, and Wilks. There is a static device, which is treated as a static canvas and objects are drawn on the device through R plotting commands. The device has a set of global parameters such as margins and layouts which can be manipulated by the user using par() commands. The R graphics engine does not maintain a user visible graphics list, and there is no system of double buffering, so objects cannot be easily edited without redrawing a whole plot.

CRAN Task View: Graphic Displays

ggplot2

  • Implementation of Grammar of graphics
  • Allows the user to add, remove or alter components in a plot at a high level of abstraction

ggplot2

http://www.cookbook-r.com/

Maps

- Based on ggplot:

ggmap

Maps

- Based on leaflet js library: leaflet

ggmap

Spatial visualization with ggplot2

Static output

ggmap

leaflet

Leaflet is one of the most popular open-source JavaScript libraries for interactive maps.

The leaflet R package makes it easy to integrate and control Leaflet maps in R.

Features

  • Interactive panning/zooming
  • Compose maps using map tiles, markers, polygons, lines, popups, geoJSON
  • Render maps in R Markdown documents, Shiny apps, and RStudio IDE / the R console

https://rstudio.github.io/leaflet/

Interactive plots

Interactive

plots

Interactive plots use JavaScript visualization libraries through R

Allow the creation of widgets that can be embed in R Markdown documents and Shiny web applications

Plotly

Plotly allows to easily translate ggplot2 graphics to interactive web-based version, and provides bindings to the plotly.js graphing library.

Plotly

https://plot.ly/r/

htmlwidgets

The htmlwidgets package provides a framework for easily creating R bindings to JavaScript libraries.

Widgets created using the framework can be:

  • Used at the R console for data analysis just like conventional R plots (via RStudio Viewer).
  • Embedded within R Markdown documents and Shiny web applications.
  • Saved as standalone web pages for ad-hoc sharing via email, Dropbox, etc.

http://www.htmlwidgets.org/

packages

packages

develop

By following a small set of conventions, it is possible to create HTML widgets with very little code. All widgets include:

  • Dependencies: JavaScript and CSS assets used by the widget (e.g. the library you are creating a wrapper for).

  • R binding: the function that end users will call to provide input data to the widget. Includes boilerplate functions to use the widget within Shiny.

  • JavaScript binding: the JavaScript code that glues everything together, passing the data and options gathered in the R binding to the underlying JavaScript library.

Dashboards

Dashboards

Interactivity does not necessarily require a server behind it running code. Interactivity can be provided using embedded JavaScript, which would execute at the client-side (like plotly, highcharts, leaflet etc).

If whatever interactivity is required can be offered by an existing package (that uses htmlwidgets), then you can just use flexdashboard and you don't need to deploy it to any Shiny server. Otherwise, you do need to deploy to a Shiny server and you should use either Shiny, or shinydashboard

shiny

Shiny is an R package that builds interactive web apps straight from R.

Shiny needs a server behind it to execute R code on user input. Can implement any layout. Can run interactive code either by processing serverside (in R) or clientside (in embedded JavaScript).

shiny

http://shiny.rstudio.com/

shinydashboard

Business-like dashboards

  • Message menu
  • Notification menu
  • Tasks menu
  • Boxes
  • infoBox and valueBox for KPIs

flexdashboard

flexdashboard uses R Markdown to publish a group of related data visualizations as a dashboard.

It produces standard HTML documents that can be deployed on any web server or even attached to an email message.

It is possible to add Shiny components for additional interactivity and then deploy on Shiny Server or shinyapps.io.

Resources

Interactive visualizations

Resources

Overview

https://www.r-graph-gallery.com/

http://viz.wtf/

http://www.htmlwidgets.org/

https://plot.ly/r/

https://github.com/ramnathv/htmlwidgets

http://civilstat.com/2012/10/basics-of-javascript-and-d3-for-r-users/

http://blog.revolutionanalytics.com/2015/05/a-first-look-at-htmlwidgets.html

https://github.com/hadley/r2d3

http://blog.revolutionanalytics.com/2014/09/how-to-publish-r-and-ggplot2-to-the-web.html

Plotting

Dashboards

http://ramnathv.github.io/swc-nw-dataviz/visualize/base_graphics.html

http://ggplot2.org/

http://www.cookbook-r.com/Graphs/

http://ggplot2.tidyverse.org/reference/

Maps

http://shiny.rstudio.com/

https://rstudio.github.io/shinydashboard/index.html

https://blog.rstudio.com/2016/05/17/flexdashboard-easy-interactive-dashboards-for-r/

http://shiny.rstudio.com/articles/selecting-rows-of-data.html

https://stackoverflow.com/questions/37992147/r-shiny-which-hammer-straight-shiny-flexdashboard-or-shinydashboard

http://rstudio.github.io/shiny/tutorial/

http://stat405.had.co.nz/ggmap.pdf

https://www.nceas.ucsb.edu/~frazier/RSpatialGuides/ggmap/ggmapCheatsheet.pdf

https://rstudio.github.io/leaflet/

The future?

RStudio

  • R viewed as interface language that talk to specialised systems (SQL, spark, tensorflow, html/js, ...)
  • Tidyverse more consistent across packages
  • Focus on Shiny testing and long-running tasks
  • Instead of just having HTML widget, integration of React and similar technologies with Shiny

https://www.analytics-link.com/single-post/2017/08/14/SPOTLIGHT-The-Hadley-Wickham

https://rviews.rstudio.com/2017/01/04/interview-with-joe-cheng/

Others

  • Still lots of integrations and improvings in htmlwidgets: https://github.com/ramnathv/htmlwidgets
  • Focus on ggplot scales: https://github.com/hadley/scales
  • Interactive editing of ggplot graphs: https://github.com/metrumresearchgroup/ggedit
  • Improved integration of Js functionalities in Shiny: https://github.com/daattali/shinyjs
  • Focus on scheduling: https://github.com/r-lib/later