The inspiration!

D3 visualisations by Eamonn Maguire

D3 visualisations by Eamonn Maguire

Using R code in your presentation

Example of some code

summary(mtcars)
      mpg             cyl             disp             hp             drat             wt             qsec             vs        
 Min.   :10.40   Min.   :4.000   Min.   : 71.1   Min.   : 52.0   Min.   :2.760   Min.   :1.513   Min.   :14.50   Min.   :0.0000  
 1st Qu.:15.43   1st Qu.:4.000   1st Qu.:120.8   1st Qu.: 96.5   1st Qu.:3.080   1st Qu.:2.581   1st Qu.:16.89   1st Qu.:0.0000  
 Median :19.20   Median :6.000   Median :196.3   Median :123.0   Median :3.695   Median :3.325   Median :17.71   Median :0.0000  
 Mean   :20.09   Mean   :6.188   Mean   :230.7   Mean   :146.7   Mean   :3.597   Mean   :3.217   Mean   :17.85   Mean   :0.4375  
 3rd Qu.:22.80   3rd Qu.:8.000   3rd Qu.:326.0   3rd Qu.:180.0   3rd Qu.:3.920   3rd Qu.:3.610   3rd Qu.:18.90   3rd Qu.:1.0000  
 Max.   :33.90   Max.   :8.000   Max.   :472.0   Max.   :335.0   Max.   :4.930   Max.   :5.424   Max.   :22.90   Max.   :1.0000  
       am              gear            carb      
 Min.   :0.0000   Min.   :3.000   Min.   :1.000  
 1st Qu.:0.0000   1st Qu.:3.000   1st Qu.:2.000  
 Median :0.0000   Median :4.000   Median :2.000  
 Mean   :0.4062   Mean   :3.688   Mean   :2.812  
 3rd Qu.:1.0000   3rd Qu.:4.000   3rd Qu.:4.000  
 Max.   :1.0000   Max.   :5.000   Max.   :8.000  

Inline code

So, sqrt(81)*4*pi becomes 113.0973355.

Import some data

I_jean <- read.delim("http://bit.ly/avml_ggplot2_data")
head(I_jean)

Static plots

p <- ggplot(mtcars, aes(x = factor(1), fill = factor(cyl))) + 
  geom_bar(width = 0.8, position = "dodge", colour = "black")
p

Interactive plots!

ggplotly(p)

Make more plots!

# Code from https://jofrhwld.github.io/avml2012/
# Taken as an example only under fair-use practice
# All rights reserved by the original author
p <- ggplot(I_jean, aes(x = Dur_msec, y = F1.n)) + 
  geom_point() + 
  stat_smooth(method="loess") +
  scale_x_log10(breaks = c(50, 100,200,300,400)) +
  scale_y_reverse() +
  ylab("Normalized F1") +
  xlab("Vowel duration (msec)") +
  theme_bw() +
  labs(title = "394 tokens of 'I' from one speaker")
ggplotly(p)

Making a reveal.js presentation

R Markdown with embedded R code

The source file itself

“But I hate / don’t use R…”

Other “engines” for code chunks

Language In RMarkdown Plotly available
Python Yes Yes
JavaScript Yes Yes
SQL Yes No
Bash Yes No

More: http://rmarkdown.rstudio.com/authoring_knitr_engines.html

“But I don’t want to install R and its packages…”

RStudio via Docker

RStudio via Docker

RStudio via Docker

Using RStudio in your browser

  • Caveat! Non-R engines don’t work out of the box
  • Create a directory for your project
  • Add this Dockerfile and this docker-compose.yml to the directory
  • Run $ docker-compose up -d
  • Open RStudio in your browser at localhost:8787 or 0.0.0.0:8787
  • Log in with “rstudio” as both the username and password
  • To shutdown: $ docker-compose down

Questions?

LS0tCnRpdGxlOiAiSW50ZXJhY3RpdmUsIGFubm90YXRhYmxlLCBjb2RlLWRyaXZlbiBwcmVzZW50YXRpb25zIgphdXRob3I6ICJBY2hpbnR5YSBSYW8iCmRhdGU6ICIxOSBNYXkgMjAxNyIKb3V0cHV0OgogIGh0bWxfbm90ZWJvb2s6CiAgICBjb2RlX2ZvbGRpbmc6IGhpZGUKICAgIGZpZ19jYXB0aW9uOiB5ZXMKICAgIGhpZ2hsaWdodDogdGFuZ28KICAgIHRoZW1lOiB1bml0ZWQKICAgIHRvYzogeWVzCi0tLQoKPHNjcmlwdCBzcmM9Imh0dHBzOi8vaHlwb3RoZXMuaXMvZW1iZWQuanMiIGFzeW5jPjwvc2NyaXB0PgpgYGB7ciBzZXR1cCwgaW5jbHVkZT1GQUxTRX0Ka25pdHI6Om9wdHNfY2h1bmskc2V0KGVjaG8gPSBUUlVFKQpsaWJyYXJ5KHBsb3RseSkKYGBgCgojIFRoZSBpbnNwaXJhdGlvbiEKCiFbRDMgdmlzdWFsaXNhdGlv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