Martin John Hadley
Academic Research Technology Specialist
University of Oxford
Code for talk available here, https://goo.gl/pU5tu4
R is a scripting language and a very powerful tool for data analysis and presentation, primarily due to the huge user base and their dedication to developing free and open source libraries/packages covering a vast range of different knowledge domains:
R provides an excellent workflow for reproducible research; combining code with data, textual explanations and interactive data visualisations.
RStudio is a free, open-source IDE (integrated development environment) that provides an extremely powerful and friendly interface for developing with R.
RStudio is also the name of the developers of RStudio - they have developed an impressive stack of technologies for making R easier to use and more powerful for reproducible research and creating interactive data visualisatons.
Some of the technology they’ve built includes:
RMarkdown allows for code, text, images and interactive data visualisations to be combined together in the same document.
This presentation was built using RMarkdown and published to the free hosting platform RPubs.
library(leaflet)
africa_data_points = data.frame(
lat = rnorm(26, mean = 6.9, sd = 20),
lng = rnorm(26, mean = 17.7, sd = 20),
size = runif(26, 5, 10),
label = letters
)
leaflet(data = africa_data_points) %>%
addTiles() %>%
addCircleMarkers(popup = ~label, radius = ~size)htmlwidgets is a framework for binding R to a JavaScript library of choice, and to bundle this functionality into an easy to use library:
library(leaflet)
leaflet() %>%
addTiles()The htmlwidgets.org website provides an overview of some of the most popular htmlwidgets:
If you use ggplot2 and are not going overboard it’s probably you can directly covert your charts into interactive charts using the plotly library:
## verbatim from https://plot.ly/ggplot2/geom_ribbon/
library(ggplot2)
p1 <- ggplot(new.dat,aes(x=x,y=pred)) +
geom_line() +
geom_ribbon(aes(ymin=pred-2*SE2,ymax=pred+2*SE2),alpha=0.2,fill="red") +
geom_ribbon(aes(ymin=pred-2*SE,ymax=pred+2*SE),alpha=0.2,fill="blue") +
geom_point(data=dtfr,aes(x=x,y=y), size=1) +
scale_y_continuous("y")
p1library(plotly)
ggplotly(p1)If you’re interested in building interactive maps, charts, networks with the ability for users to zoom/pan/filter* then these are the only tools you need:
Where can I learn more?!
Training here: 14th and 21st November 14:00-17:00
Lynda course: Creating Interactive Presentations with Shiny and R
You might be exciting and want to have multiple [interdependent] charts, or for users of your visualisations to see additional information when they select data.
Shiny is a web framework developed by RStudio that allows impressively interactive web applications to be created using R.
There’s no need* to learn HTML or JavaScript to build these interactive apps.
Expense is related to complexity, so let’s answer that first
shinyapps.io is a hosted solution for sharing Shiny apps on the web, run by RStudio.
There’s a free tier of the service available that you can sign up for right now.
You can deploy 5 interactive applications for free, with a total of 25 interactive hours per month.
All accounts have a limited number of “active hours” - this is the time during which an app is running.
When starting off with Shiny you’re not going to hit 25 hours per month, experiment freely.
If you start hitting up against the 25 hours - the University is investing in a shinyapps.io subscription [and later a full service]
Publishing your Shiny app to shinyapps.io is incredibly simple if you’re using RStudio, simply click on the publish button.
The Live Data project has been funded by IT Services to support researchers in creating interactive data visualisations, during this project we’ve learned how impressive [and easy to use] Shiny is for building visualisation case studies.
These are two of the visualisations we’ve built that I want to particularly highlight:
Built by Dean Attali:
There is a step-by-step guide to learning Shiny produced by RStudio here: http://shiny.rstudio.com/tutorial/. This is how I originally learned Shiny in May 2015, it’s a good course but may assume some knowledge you don’t have.
But there are other online tutorials available, in fact Dean Attali has a great tutorial on hosting your own Shiny server.
Training here: 14th and 21st November 14:00-17:00
Lynda course: Creating Interactive Presentations with Shiny and R