Session 10
PMAP 8921: Data Visualization with R
Andrew Young School of Policy Studies
Summer 2021
Making interactive graphics
Making interactive graphics
Sharing content
Single plots with plotly
Easy!
Single plots with plotly
Easy!
Dashboards with flexdashboard
Slightly more complicated
Single plots with plotly
Easy!
Dashboards with flexdashboard
Slightly more complicated
Complete interactive apps with Shiny
Super complicated!
Plotly is special software for
creating interactive plots with JavaScript
Plotly is special software for
creating interactive plots with JavaScript
No knowledge of JavaScript needed!
Plotly is special software for
creating interactive plots with JavaScript
No knowledge of JavaScript needed!
ggplotly()
in the plotly R package translates
between R and Javascript for you!
Save a self-contained HTML version of it withsaveWidget()
in the htmlwidgets R package
# This is like ggsave, but for interactive HTML plotshtmlwidgets::saveWidget(interactive_plot, "fancy_plot.html")
The documentation for ggplot2 + plotly is full of
examples of how to customize everything
Rely on that ↑ + Google to make
really fancy (and easy!) interactive plots
Single plots with plotly
Easy!
Single plots with plotly
Easy!
Dashboards with flexdashboard
Slightly more complicated
Use basic R Markdown to build a dashboard!
Make any kind of block arrangement
Add other elements like text and gauges
The documentation for flexdashboard is
full of examples and details of everything you can do
Rely on that ↑ + Google to make
really fancy (and easy!) dashboards!
Single plots with plotly
Easy!
Dashboards with flexdashboard
Slightly more complicated
Single plots with plotly
Easy!
Dashboards with flexdashboard
Slightly more complicated
Complete interactive apps with Shiny
Super complicated!
Shiny is a complete web application framework for interactive statistics
Shiny is a complete web application framework for interactive statistics
It's super complex and hard for beginners
Shiny is a complete web application framework for interactive statistics
It's super complex and hard for beginners
I've never made a standalone Shiny app!
(And I don't plan on trying anytime soon)
You can use reactive Shiny things in flexdashboards
without building a complete Shiny app!
I have done this
When knitting to PDF or Word, you make a standalone file
E-mail it, message it, Slack it, whatever
When knitting to PDF or Word, you make a standalone file
E-mail it, message it, Slack it, whatever
When knitting to HTML, you make a website
When knitting to PDF or Word, you make a standalone file
E-mail it, message it, Slack it, whatever
When knitting to HTML, you make a website
By default it's a standalone .html
file with graphics embedded,
so you can still e-mail it, etc., but it can get huge if there are lots of images
When knitting to PDF or Word, you make a standalone file
E-mail it, message it, Slack it, whatever
When knitting to HTML, you make a website
By default it's a standalone .html
file with graphics embedded,
so you can still e-mail it, etc., but it can get huge if there are lots of images
Standalone files won't work well if there's anything interactive
When knitting to PDF or Word, you make a standalone file
E-mail it, message it, Slack it, whatever
When knitting to HTML, you make a website
By default it's a standalone .html
file with graphics embedded,
so you can still e-mail it, etc., but it can get huge if there are lots of images
Standalone files won't work well if there's anything interactive
You can also post it online!
RPubs for knitted HTML documents
Built in to RStudio; works with ggplotly!
RPubs for knitted HTML documents
Built in to RStudio; works with ggplotly!
RPubs or shinyapps.io for flexdashboards
RPubs for knitted HTML documents
Built in to RStudio; works with ggplotly!
RPubs or shinyapps.io for flexdashboards
Your own web server for anything, if you have one
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
o | Tile View: Overview of Slides |
Esc | Back to slideshow |
Session 10
PMAP 8921: Data Visualization with R
Andrew Young School of Policy Studies
Summer 2021
Making interactive graphics
Making interactive graphics
Sharing content
Single plots with plotly
Easy!
Single plots with plotly
Easy!
Dashboards with flexdashboard
Slightly more complicated
Single plots with plotly
Easy!
Dashboards with flexdashboard
Slightly more complicated
Complete interactive apps with Shiny
Super complicated!
Plotly is special software for
creating interactive plots with JavaScript
Plotly is special software for
creating interactive plots with JavaScript
No knowledge of JavaScript needed!
Plotly is special software for
creating interactive plots with JavaScript
No knowledge of JavaScript needed!
ggplotly()
in the plotly R package translates
between R and Javascript for you!
library(gapminder)library(plotly)gapminder_2007 <- filter(gapminder, year == 2007)my_plot <- ggplot( data = gapminder_2007, mapping = aes(x = gdpPercap, y = lifeExp, color = continent)) + geom_point() + scale_x_log10() + theme_minimal()
ggplotly(my_plot)
my_plot <- ggplot( data = gapminder_2007, mapping = aes(x = gdpPercap, y = lifeExp, color = continent)) + geom_point(aes(text = country)) + scale_x_log10() + theme_minimal()
interactive_plot <- ggplotly( my_plot, tooltip = "text") interactive_plot
car_hist <- ggplot(mpg, aes(x = hwy)) + geom_histogram(binwdith = 2, boundary = 0, color = "white")
ggplotly(car_hist)
Save a self-contained HTML version of it withsaveWidget()
in the htmlwidgets R package
# This is like ggsave, but for interactive HTML plotshtmlwidgets::saveWidget(interactive_plot, "fancy_plot.html")
The documentation for ggplot2 + plotly is full of
examples of how to customize everything
Rely on that ↑ + Google to make
really fancy (and easy!) interactive plots
Single plots with plotly
Easy!
Single plots with plotly
Easy!
Dashboards with flexdashboard
Slightly more complicated
Use basic R Markdown to build a dashboard!
Make any kind of block arrangement
Add other elements like text and gauges
The documentation for flexdashboard is
full of examples and details of everything you can do
Rely on that ↑ + Google to make
really fancy (and easy!) dashboards!
Single plots with plotly
Easy!
Dashboards with flexdashboard
Slightly more complicated
Single plots with plotly
Easy!
Dashboards with flexdashboard
Slightly more complicated
Complete interactive apps with Shiny
Super complicated!
Shiny is a complete web application framework for interactive statistics
Shiny is a complete web application framework for interactive statistics
It's super complex and hard for beginners
Shiny is a complete web application framework for interactive statistics
It's super complex and hard for beginners
I've never made a standalone Shiny app!
(And I don't plan on trying anytime soon)
You can use reactive Shiny things in flexdashboards
without building a complete Shiny app!
I have done this
When knitting to PDF or Word, you make a standalone file
E-mail it, message it, Slack it, whatever
When knitting to PDF or Word, you make a standalone file
E-mail it, message it, Slack it, whatever
When knitting to HTML, you make a website
When knitting to PDF or Word, you make a standalone file
E-mail it, message it, Slack it, whatever
When knitting to HTML, you make a website
By default it's a standalone .html
file with graphics embedded,
so you can still e-mail it, etc., but it can get huge if there are lots of images
When knitting to PDF or Word, you make a standalone file
E-mail it, message it, Slack it, whatever
When knitting to HTML, you make a website
By default it's a standalone .html
file with graphics embedded,
so you can still e-mail it, etc., but it can get huge if there are lots of images
Standalone files won't work well if there's anything interactive
When knitting to PDF or Word, you make a standalone file
E-mail it, message it, Slack it, whatever
When knitting to HTML, you make a website
By default it's a standalone .html
file with graphics embedded,
so you can still e-mail it, etc., but it can get huge if there are lots of images
Standalone files won't work well if there's anything interactive
You can also post it online!
RPubs for knitted HTML documents
Built in to RStudio; works with ggplotly!
RPubs for knitted HTML documents
Built in to RStudio; works with ggplotly!
RPubs or shinyapps.io for flexdashboards
RPubs for knitted HTML documents
Built in to RStudio; works with ggplotly!
RPubs or shinyapps.io for flexdashboards
Your own web server for anything, if you have one