class: center, middle, inverse, title-slide # ASP 460 2.0 Special Topics in Statistics ## Interactive graphics ### Thiyanga Talagala ### 2020-06-26 --- # Data ``` # A tibble: 6 x 7 species island culmen_length culmen_depth flipper_length body_mass sex <fct> <fct> <dbl> <dbl> <int> <int> <fct> 1 Adelie Torgersen 39.1 18.7 181 3750 male 2 Adelie Torgersen 39.5 17.4 186 3800 female 3 Adelie Torgersen 40.3 18 195 3250 female 4 Adelie Torgersen 36.7 19.3 193 3450 female 5 Adelie Torgersen 39.3 20.6 190 3650 male 6 Adelie Torgersen 38.9 17.8 181 3625 female ``` ``` species island culmen_length culmen_depth flipper_length Adelie :146 Biscoe :163 Min. :32.10 Min. :13.10 Min. :172 Chinstrap: 68 Dream :123 1st Qu.:39.50 1st Qu.:15.60 1st Qu.:190 Gentoo :119 Torgersen: 47 Median :44.50 Median :17.30 Median :197 Mean :43.99 Mean :17.16 Mean :201 3rd Qu.:48.60 3rd Qu.:18.70 3rd Qu.:213 Max. :59.60 Max. :21.50 Max. :231 body_mass sex Min. :2700 female:165 1st Qu.:3550 male :168 Median :4050 Mean :4207 3rd Qu.:4775 Max. :6300 ``` --- # Static graphic ![](lectureplotly_files/figure-html/unnamed-chunk-2-1.png)<!-- --> --- # Interactive graphics - allows the use to interact with the graphical information presented on the display. - Cross filtering - Zoom by selecting an area of interest - Hover the line to get exact information. --- # Interactive plot
--- # Interactive plot (cont.)
--- class: duke-orange, center, middle # plotly powered by the JavaScript library plotly.js --- # Introduction to `plot_ly()`: - Mapping variables: Instead of `aes` use `~`
--- # Introduction to `plot_ly()`
--- # Introduction to `plot_ly()`
--- # Introduction to `plot_ly()` - plotly finds a suitable geometric representation for us. - Users can also define geometries. - Functions to encode data - color: map each level to a different colour - colors: specify a range of colours - stroke - span - symbol - linetype --- # `color` argument
--- # `colors` argument .pull-left[
Default ] .pull-right[
colors="Accent" ] --- # Define a colour: I()
--- # layout() > functional approach to a layered grammar of graphics > input: plotly object
--- # Works with %>% operator ```r penguins %>% plot_ly(x = ~species) %>% layout(title="Composition of species") ```
--- # Modify graphs: add_* > add_histogram
--- # Modify graphs > add_bars (requires pre calculated counts)
--- # Modify graphs (cont.)
--- # Line graphs
--- # Boxplots .pull-left[
] .pull-right[
] --- # Boxplot
--- # Combining multiple views - Static or dynamic - Scatterplot matrices - Higer dimensional displayes - Arrange multiple plots in a single plane --- # Combining multiple views `subplot`: merge multiple plotly objects.
--- # Combining multiple views (cont.) - `splom`
--- # Flexdashboard [Click here](https://thiyanga.netlify.app/post/covid19/) [Clickhere](/slides/dashboard_penguins.html)