(1) Install the required software https://workshops.cpsievert.me/20171118/
(2) Run the docker container so that RStudio appears when you visit http://localhost:8787 (in Chrome or Firefox, please!)
(3) In the R console, enter
browseURL("~/day1/index.html")
If you see this popup, press "Try Again".
(4) Go to Tools -> Global Options and configure your pane layout like this.
(5) Share (w/ your neighbor) 3 things you're hoping to take away from this workshop (share them via Slack if you like!)
Maintainer of plotly's R package (for nearly 3 years!)
PhD in statistics from Iowa State
Founder & CEO, Sievert Consulting LLC
plot_ly()
draw a bar chart? What if we want something different?library(plotly)plot_ly(x = c("A", "B"), y = 1:2)
In your R console enter:
file.edit('~/day1/your-turn.R')
Work through the comments/code/questions in this R script.
Feel free to work with your neighbor and ask me questions!
If you have question(s) about it rmarkdown, now would be a good time to ask (we won't have time to cover it together).
PS. Did you know the workshop slides were created with rmarkdown?
The scatter trace type is quite general. It provides the foundation for many charts (e.g., polygons, ribbons, filled areas, etc), extends to different coordinate systems (e.g, scatter3d, scattergeo, and scattermapbox), and rendering systems (e.g., scattergl)
subplot(shareY = TRUE, plot_ly(x = 1:2, y = 1:2), plot_ly(x = 1:2, y = 1:2, mode = "lines"), plot_ly(x = 1:2, y = 1:2, mode = "markers+lines"), plot_ly(x = 1:2, y = 1:2, text = 1:2, mode = "text"), plot_ly(x = 1:2, y = 1:2, text = 1:2, mode = "markers+lines+text"))
file.edit('~/day1/demo.R')
subplot(shareX = TRUE, nrows = 2, plot_ly(logs, x = ~date, y = ~package, z = ~count, type = "heatmap"), plot_ly(logs, x = ~date, y = ~count, color = ~package, mode = "lines"))
These questions drive at least two influential papers:
This figure is from Data Visualization for Social Science (highly recommended!) in reference to Bostock and Heer.
Figure from Heer and Bostock (2010)
installed.packages()
, yikes!plot_ly(logz, x = ~date, y = ~count) %>% group_by(package) %>% add_lines(alpha=0.3)
library(crosstalk)SharedData$new(logz, ~package, "Select package(s)") %>% plot_ly(x = ~date, y = ~count) %>% group_by(package) %>% add_lines(alpha=0.3) %>% highlight(dynamic = TRUE, selectize = TRUE, persistent = TRUE)
Ben Shneiderman
Popular information visualization perspective
Hadley Wickham
Popular statistical graphics perspective
Have a look at some plotly "extension" packages!
Exercise: Most of these packages have a function that returns a plotly object (e.g., heatmaply::heatmaply()
). Use a plotly function to modify/customize the result (e.g., add a title with plotly::layout()
)
For all CRAN packages that use plotly, see the "Reverse dependencies" section on https://cran.r-project.org/package=plotly
y <- sample(c(-1, 1), 1e5, TRUE)x <- seq(Sys.time(), Sys.time() + length(y) - 1, by = "1 sec")plot_ly(x = x, y = cumsum(y)) %>% add_lines() %>% toWebGL()
Consider extracting/visualizing features from each series
Consider a tool like trelliscope for exploring many "groups"
library(dplyr)tx <- txhousing %>% select(city, year, month, median) %>% filter(city %in% c("Galveston", "Midland", "Odessa", "South Padre Island"))tx#> # A tibble: 748 x 4#> city year month median#> <chr> <int> <int> <dbl>#> 1 Galveston 2000 1 95000#> 2 Galveston 2000 2 100000#> 3 Galveston 2000 3 98300#> 4 Galveston 2000 4 111100#> 5 Galveston 2000 5 89200#> 6 Galveston 2000 6 108600#> 7 Galveston 2000 7 99000#> 8 Galveston 2000 8 96200#> 9 Galveston 2000 9 104000#> 10 Galveston 2000 10 118800#> # ... with 738 more rows
ggplot(tx, aes(month, median, group = year)) + geom_line() + facet_wrap(~city, ncol = 2)
TX <- SharedData$new(tx, ~year)p <- ggplot(TX, aes(month, median, group = year)) + geom_line() + facet_wrap(~city, ncol = 2)(gg <- ggplotly(p, tooltip = "year"))
highlight(gg, "plotly_hover", defaultValues = "2006")
highlight(gg, dynamic = TRUE, persistent = TRUE, selectize = TRUE)
highlight( gg, dynamic = TRUE, persistent = TRUE, selected = attrs_selected(mode = "markers+lines", marker = list(symbol = "x")))
p <- ggplot(tx, aes(month, median)) + geom_line(aes(group = year), alpha = 0.2) + geom_line(aes(frame = year), color = "red") + facet_wrap(~city, ncol = 2)ggplotly(p)
Visit this post, replicate the example (no install needed), and use trelliscope to visualize txhousing
(or, more preferably, your own data!)
(1) Install the required software https://workshops.cpsievert.me/20171118/
(2) Run the docker container so that RStudio appears when you visit http://localhost:8787 (in Chrome or Firefox, please!)
(3) In the R console, enter
browseURL("~/day1/index.html")
If you see this popup, press "Try Again".
(4) Go to Tools -> Global Options and configure your pane layout like this.
(5) Share (w/ your neighbor) 3 things you're hoping to take away from this workshop (share them via Slack if you like!)
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 |
Esc | Back to slideshow |