class: center, middle, inverse, title-slide # Introduction to the Tidyverse ## part 2: data visualization with ggplot2 ### Martin Ndemo Sato ### 04/21/2020 --- class: inverse-ns, center background-image: url(tidyhex.png) --- class: inverse-ns, center # Working with data in R ## the <span style = 'color:#E69F00'>tidyverse</span> is a collection of <span style = 'color:#56B4E9'>friendly and consistent</span> tools for data analysis and visualization. --- class: inverse-ns, center # Working with data in R ## <span style = 'color:#6C7B7F'>the tidyverse is a collection of friendly and consistent tools for data analysis and visualization. </span> ## They live as <span style = 'color:#E69F00'>R packages</span> each of which does one thing well. --- background-image: url(https://raw.githubusercontent.com/tidyverse/tidyverse/master/man/figures/logo.png) background-position: 90% 10% ## `library(tidyverse)` will load ## the core tidyverse packages: #### [ggplot2](http://ggplot2.tidyverse.org), for data visualisation. #### [dplyr](http://dplyr.tidyverse.org), for data manipulation. #### [tidyr](http://tidyr.tidyverse.org), for data tidying. #### [readr](http://readr.tidyverse.org), for data import. #### [purrr](http://purrr.tidyverse.org), for functional programming. #### [tibble](http://tibble.tidyverse.org), for tibbles, a modern re-imagining of data frames. #### [stringr](https://github.com/tidyverse/stringr), for strings. #### [forcats](https://github.com/hadley/forcats), for factors. --- background-image: url(http://hexb.in/hexagons/ggplot2.png) background-position: 90% 10% # ggplot2: Elegant Data Visualizations in R ## a Layered Grammar of Graphics --- background-image: url(http://hexb.in/hexagons/ggplot2.png) background-position: 90% 10% # ggplot2: Elegant Data Visualizations in R ## <span style = 'color:#E5E5E5'>a Layered Grammar of Graphics</span> ## Data is mapped to aesthetics; Statistics and plot are linked --- background-image: url(http://hexb.in/hexagons/ggplot2.png) background-position: 90% 10% # ggplot2: Elegant Data Visualizations in R ## <span style = 'color:#E5E5E5'>a Layered Grammar of Graphics</span> ## <span style = 'color:#E5E5E5'>Data is mapped to aesthetics; Statistics and plot are linked</span> ## Sensible defaults; Infinitely extensible --- background-image: url(http://hexb.in/hexagons/ggplot2.png) background-position: 90% 10% ## Publication quality & beyond ### [https://nyti.ms/2jUp36n](https://nyti.ms/2jUp36n) ### [http://bit.ly/2KSGZLu](http://bit.ly/2KSGZLu) --- ```r ggplot() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-1-1.png" style="display: block; margin: auto;" /> --- ```r ggplot(mtcars, aes(x = mpg, y = hp)) ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-2-1.png" style="display: block; margin: auto;" /> --- ```r ggplot(mtcars, aes(x = mpg, y = hp)) + geom_point() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-3-1.png" style="display: block; margin: auto;" /> --- # `ggplot()` #### `ggplot(data = <DATA>, mapping = aes(<MAPPINGS>)) + ` #### `<GEOM_FUNCTION>()` -- ## Add layers with <span style = 'color:#E69F00'><code>+</code></span> -- ## Put `+` at the <span style = 'color:#E69F00'>end</span> of a line -- ## map aesthetics with <span style = 'color:#E69F00'><code>aes()</code></span> --- ```r diabetes <- read_csv("diabetes.csv") ggplot(data = diabetes, mapping = aes(x = weight, y = hip)) + geom_point() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-4-1.png" style="display: block; margin: auto;" /> --- # Aesthetics: `aes()` #### `ggplot(data = <DATA>, mapping = aes(<MAPPINGS>)) + ` #### `<GEOM_FUNCTION>()` -- ## Aesthetics <span style = 'color:#E69F00'>map</span> the data to the <span style = 'color:#56B4E9'>plot</span>. --- # Aesthetics: `aes()` ```r ggplot(mtcars, aes(x = mpg, y = hp, color = cyl)) + geom_point() ggplot(mtcars, aes(x = mpg, y = hp, size = cyl)) + geom_point() ggplot(mtcars, aes(x = mpg, y = hp, alpha = cyl)) + geom_point() ggplot(mtcars, aes(x = mpg, y = hp, shape = cyl)) + geom_point() ``` --- ```r ggplot(data = diabetes, mapping = aes(x = weight, y = hip, color = gender)) + geom_point() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-6-1.png" style="display: block; margin: auto;" /> --- ```r ggplot(data = diabetes, mapping = aes(x = weight, y = hip, size = gender)) + geom_point() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-7-1.png" style="display: block; margin: auto;" /> --- ```r ggplot(data = diabetes, mapping = aes(x = weight, y = hip, alpha = gender)) + geom_point() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-8-1.png" style="display: block; margin: auto;" /> --- ```r ggplot(data = diabetes, mapping = aes(x = weight, y = hip, shape = gender)) + geom_point() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-9-1.png" style="display: block; margin: auto;" /> --- ```r ggplot(data = diabetes) + geom_point(mapping = aes(x = weight, y = hip, color = gender, shape = gender)) ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-10-1.png" style="display: block; margin: auto;" /> --- # geoms ## What shape does the data take? -- ## `geom_point()` -- ## `geom_line()` -- ## `geom_violin()` -- # <span style = 'color:#E69F00'>Check the cheatsheet!</span> --- ```r ggplot(diabetes, aes(gender, chol)) + * geom_boxplot() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-11-1.png" style="display: block; margin: auto;" /> --- ```r ggplot(diabetes, aes(x = glyhb)) + * geom_histogram() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-12-1.png" style="display: block; margin: auto;" /> --- ```r ggplot(diabetes, aes(x = glyhb)) + * geom_density() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-13-1.png" style="display: block; margin: auto;" /> --- ```r diabetes %>% * ggplot(aes(x = frame)) + * geom_bar() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-14-1.png" style="display: block; margin: auto;" /> --- ```r diabetes %>% * drop_na() %>% ggplot(aes(x = frame)) + geom_bar() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-15-1.png" style="display: block; margin: auto;" /> --- ```r diabetes %>% drop_na() %>% * ggplot(aes(x = frame, color = gender)) + geom_bar() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-16-1.png" style="display: block; margin: auto;" /> --- ```r diabetes %>% drop_na() %>% * ggplot(aes(x = frame, fill = gender)) + geom_bar() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-17-1.png" style="display: block; margin: auto;" /> --- ## Positions ### `geom_bar(position = "<POSITION>")` -- ## When we have aesthetics mapped, how are they positioned? -- ## bar: dodge, fill, stacked (default) -- ## point: jitter --- ```r ggplot(mtcars, aes(x = factor(am), y = hp)) + geom_point() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-18-1.png" style="display: block; margin: auto;" /> --- ```r ggplot(mtcars, aes(x = factor(am), y = hp)) + * geom_point(position = "jitter") ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-19-1.png" style="display: block; margin: auto;" /> --- ```r ggplot(mtcars, aes(x = factor(am), y = hp)) + * geom_jitter(width = .1, height = 0) ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-20-1.png" style="display: block; margin: auto;" /> --- ```r diabetes %>% drop_na() %>% ggplot(aes(x = frame, fill = gender)) + * geom_bar(position = "stack") ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-21-1.png" style="display: block; margin: auto;" /> --- ```r diabetes %>% drop_na() %>% ggplot(aes(x = frame, fill = gender)) + * geom_bar(position = "dodge") ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-22-1.png" style="display: block; margin: auto;" /> --- ```r diabetes %>% drop_na() %>% ggplot(aes(x = frame, fill = gender)) + * geom_bar(position = "fill") ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-23-1.png" style="display: block; margin: auto;" /> --- ## Mapping vs setting ## Cool, but how do I just make everything <span style = 'color:#56B4E9'>blue</span>? -- ## `geom_point(aes(x, y), color = "blue")` -- ## To set a color, put it <span style = 'color:#E69F00'>outside</span> `aes()` --- ```r ggplot(mtcars, aes(x = mpg, y = hp, color = cyl)) + geom_point( * color = "blue" ) ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-24-1.png" style="display: block; margin: auto;" /> --- ```r ggplot(mtcars, aes(x = mpg, y = hp, color = cyl)) + geom_point( * aes(color = "blue") ) ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-25-1.png" style="display: block; margin: auto;" /> --- ## Adding layers ```r ggplot(data = <DATA>, mapping = aes(<MAPPINGS>)) + * <GEOM_FUNCTION>() + * <GEOM_FUNCTION>() + * <SCALE_FUNCTION>() + * <THEME_FUNCTION>() ``` --- ## Live Code Part 1 #### 1. Predict what this code will do. Then run it. #### 2. Add a `linetype` aesthetic for `gender`. Run it again. #### 3. Set the color of `geom_smooth()` to "black" #### 4. Add `se = FALSE` to the `geom_smooth()` #### 5. It's hard to see the lines well now. How about setting `alpha = .2` in `geom_point()`? #### 6. Jitter the points. You can either change the geom or change the `position` argument. #### 7. Add another layer, `theme_bw()`. Remember to use `+`. ```r ggplot(diabetes, aes(weight, hip)) + geom_point() + geom_smooth() ``` --- ```r ggplot(diabetes, aes(weight, hip)) + geom_point() + geom_smooth() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-28-1.png" style="display: block; margin: auto;" /> --- ```r ggplot(diabetes, aes(weight, hip)) + geom_point() + geom_smooth(aes(linetype = gender)) ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-29-1.png" style="display: block; margin: auto;" /> --- ```r ggplot(diabetes, aes(weight, hip)) + geom_point() + geom_smooth(aes(linetype = gender), col = "black") ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-30-1.png" style="display: block; margin: auto;" /> --- ```r ggplot(diabetes, aes(weight, hip)) + geom_point() + geom_smooth(aes(linetype = gender), col = "black", se = FALSE) ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-31-1.png" style="display: block; margin: auto;" /> --- ```r ggplot(diabetes, aes(weight, hip)) + geom_point(alpha = .2) + geom_smooth(aes(linetype = gender), col = "black", se = FALSE) ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-32-1.png" style="display: block; margin: auto;" /> --- ```r ggplot(diabetes, aes(weight, hip)) + geom_jitter(alpha = .2) + geom_smooth(aes(linetype = gender), col = "black", se = FALSE) ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-33-1.png" style="display: block; margin: auto;" /> --- ```r ggplot(diabetes, aes(weight, hip)) + geom_jitter(alpha = .2) + geom_smooth(aes(linetype = gender), col = "black", se = FALSE) + theme_bw() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-34-1.png" style="display: block; margin: auto;" /> --- ## Facets ## Easy peazy panels -- ## `facet_grid()` ## `facet_wrap()` -- ## `x ~ y` ## ` ~ y` ## `x ~ .` --- ```r diamonds %>% ggplot(aes(x = carat, price)) + geom_point() + * facet_grid(cut ~ clarity) ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-35-1.png" style="display: block; margin: auto;" /> --- ### facet grid by `gender` and `location` ```r ggplot(diabetes, aes(weight, hip)) + geom_point() + geom_smooth() + * facet_grid(gender ~ location) ``` --- <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-37-1.png" style="display: block; margin: auto;" /> --- ```r diamonds %>% ggplot(aes(x = carat, price)) + geom_point() + * facet_wrap(~clarity) ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-38-1.png" style="display: block; margin: auto;" /> --- ## datasauRus ```r library(datasauRus) datasaurus_dozen ``` ``` *## # A tibble: 1,846 x 3 *## dataset x y ## <chr> <dbl> <dbl> ## 1 dino 55.4 97.2 ## 2 dino 51.5 96.0 ## 3 dino 46.2 94.5 ## 4 dino 42.8 91.4 ## 5 dino 40.8 88.3 ## 6 dino 38.7 84.9 ## 7 dino 35.6 79.9 ## 8 dino 33.1 77.6 ## 9 dino 29.0 74.5 ## 10 dino 26.2 71.4 ## # ... with 1,836 more rows ``` --- ```r datasaurus_dozen %>% * group_by(dataset) %>% summarize(corr = cor(x, y)) %>% mutate(corr = round(corr, 3)) ``` ``` ## # A tibble: 13 x 2 ## dataset corr ## <chr> <dbl> ## 1 away -0.064 ## 2 bullseye -0.069 ## 3 circle -0.068 ## 4 dino -0.064 ## 5 dots -0.06 ## 6 h_lines -0.062 ## 7 high_lines -0.069 ## 8 slant_down -0.069 ## 9 slant_up -0.069 ## 10 star -0.063 ## 11 v_lines -0.069 ## 12 wide_lines -0.067 ## 13 x_shape -0.066 ``` --- ```r datasaurus_dozen %>% ggplot(aes(x, y)) + geom_point() + * facet_wrap(~dataset) ``` --- <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-42-1.png" style="display: block; margin: auto;" /> --- ## Scales -- ## position scales ### `scale_x_continuous()` ### `scale_y_date()` ### `scale_x_log10()` --- ## Scales ## aesthetic scales ### `scale_color_hue()` ### `scale_fill_brewer()` ### `scale_shape_manual()` --- ```r mtcars %>% ggplot(aes(hp, mpg, col = factor(cyl))) + geom_point() + scale_x_log10() + * scale_colour_brewer(palette = "Set2") ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-43-1.png" style="display: block; margin: auto;" /> --- ```r diabetes %>% ggplot(aes(waist, hip, col = weight)) + geom_point() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-44-1.png" style="display: block; margin: auto;" /> --- ```r diabetes %>% ggplot(aes(waist, hip, col = weight)) + geom_point() + * scale_color_viridis_c() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-45-1.png" style="display: block; margin: auto;" /> --- ```r diabetes %>% ggplot(aes(waist, hip, col = gender)) + geom_point() + * scale_color_brewer() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-46-1.png" style="display: block; margin: auto;" /> --- ```r diabetes %>% ggplot(aes(waist, hip, col = gender)) + geom_point() + * scale_color_manual(values = c("#E69F00", "#56B4E9")) ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-47-1.png" style="display: block; margin: auto;" /> --- ```r diabetes %>% ggplot(aes(waist, hip, col = gender)) + geom_point() + * scale_color_manual(name = "Sex", values = c("#E69F00", "#56B4E9")) ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-48-1.png" style="display: block; margin: auto;" /> --- ## Color Palettes ## [https://github.com/EmilHvitfeldt/r-color-palettes](https://github.com/EmilHvitfeldt/r-color-palettes) --- ## Themes -- ## Non-data ink (text, background, etc) -- ## Prespecified themes: `theme_gray()` (default), `theme_minimal()`, `theme_light()`, etc. -- ## `theme()` --- ```r mtcars %>% ggplot(aes(hp, mpg, col = factor(cyl))) + geom_point(size = 3) + scale_x_log() + scale_colour_brewer(name = "Cylinders", palette = "Set2") + * theme_minimal() + theme(axis.text = element_text(size = 16), legend.text = element_text(size = 8, face = "bold"), legend.direction = "horizontal") ``` --- ```r mtcars %>% ggplot(aes(hp, mpg, col = factor(cyl))) + geom_point(size = 3) + scale_x_log() + scale_colour_brewer(name = "Cylinders", palette = "Set2") + theme_minimal() + * theme(axis.text = element_text(size = 16), * legend.text = element_text(size = 8, face = "bold"), * legend.direction = "horizontal") ``` --- <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-51-1.png" style="display: block; margin: auto;" /> --- ```r diabetes %>% ggplot(aes(waist, hip, col = weight)) + geom_point() + scale_color_viridis_c() ``` --- ```r diabetes %>% ggplot(aes(waist, hip, col = weight)) + geom_point() + scale_color_viridis_c() + * theme_minimal() + theme(legend.position = "bottom", axis.ticks = element_blank(), axis.title = element_text(size = 16)) ``` --- ```r diabetes %>% ggplot(aes(waist, hip, col = weight)) + geom_point() + scale_color_viridis_c() + theme_minimal() + * theme(legend.position = "bottom", * axis.ticks = element_blank(), * axis.title = element_text(size = 16)) ``` --- <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-55-1.png" style="display: block; margin: auto;" /> --- ## High-density plots ```r diamonds ``` ``` *## # A tibble: 53,940 x 10 ## carat cut color clarity depth table price x y z ## <dbl> <ord> <ord> <ord> <dbl> <dbl> <int> <dbl> <dbl> <dbl> ## 1 0.23 Ideal E SI2 61.5 55 326 3.95 3.98 2.43 ## 2 0.21 Premium E SI1 59.8 61 326 3.89 3.84 2.31 ## 3 0.23 Good E VS1 56.9 65 327 4.05 4.07 2.31 ## 4 0.290 Premium I VS2 62.4 58 334 4.2 4.23 2.63 ## 5 0.31 Good J SI2 63.3 58 335 4.34 4.35 2.75 ## 6 0.24 Very Good J VVS2 62.8 57 336 3.94 3.96 2.48 ## 7 0.24 Very Good I VVS1 62.3 57 336 3.95 3.98 2.47 ## 8 0.26 Very Good H SI1 61.9 55 337 4.07 4.11 2.53 ## 9 0.22 Fair E VS2 65.1 61 337 3.87 3.78 2.49 ## 10 0.23 Very Good H VS1 59.4 61 338 4 4.05 2.39 ## # ... with 53,930 more rows ``` --- ```r diamonds %>% ggplot(aes(x = carat, price)) + geom_point() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-57-1.png" style="display: block; margin: auto;" /> --- ## High-density plots -- ## Transparency -- ## Binning --- ```r diamonds %>% ggplot(aes(x = carat, price)) + * geom_point(alpha = .05) ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-58-1.png" style="display: block; margin: auto;" /> --- ```r diamonds %>% ggplot(aes(x = carat, price)) + * geom_bin2d() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-59-1.png" style="display: block; margin: auto;" /> --- ```r diamonds %>% ggplot(aes(x = carat, price)) + * geom_hex() ``` <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-60-1.png" style="display: block; margin: auto;" /> --- ## Labels, titles, and legends ## Add a title: #### `ggtitle()`, `labs(title = "My Awesome Plot")` -- ## Change a label: #### `xlab()`, `ylab()`, `labs(x = "X!", y = "Y!!")` -- ## Change a legend: #### scale function, `labs(color = "Wow, labs does everything", fill = "Yup")` --- ## Saving plots -- ## `ggsave(p, path = "figure_name.png", dpi = 320)` --- ## Live Code Part 2 #### 1. Add a title. #### 2. Change the x and y axis labels to include the unites (inches for `hip` and pounds for `weight`). You can use either `labs()` or `xlab()` and `ylab()` #### 3. Add `scale_linetype()` and set the `name` argument to "Sex". #### 4. Save the plot. ```r ggplot(diabetes, aes(weight, hip, linetype = gender)) + geom_jitter(alpha = .2, size = 2.5) + geom_smooth(color = "black", se = FALSE) + theme_bw(base_size = 12) ``` --- ```r ggplot(diabetes, aes(weight, hip, linetype = gender)) + geom_jitter(alpha = .2, size = 2.5) + geom_smooth(color = "black", se = FALSE) + theme_bw(base_size = 12) + labs(x = "Weight (lbs)", y = "Hip (inches)") + ggtitle("Hip and Weight by Sex") + scale_linetype(name = "Sex") ``` --- <img src="intro_to_tidyverse_ggplot2_files/figure-html/unnamed-chunk-63-1.png" style="display: block; margin: auto;" /> --- ```r ggsave(path = "diabetes_figure.png", dpi = 320) ``` --- ```r *diabetes_plot <- ggplot(diabetes, aes(weight, hip, linetype = gender)) + geom_jitter(alpha = .2, size = 2.5) + geom_smooth(color = "black", se = FALSE) + theme_bw(base_size = 12) + labs(x = "Weight (lbs)", y = "Hip (inches)") + ggtitle("Hip and Weight by Sex") + scale_linetype(name = "Sex") ggsave(diabetes_plot, path = "diabetes_figure.png", dpi = 320) ``` --- ```r diabetes_plot <- ggplot(diabetes, aes(weight, hip, linetype = gender)) + geom_jitter(alpha = .2, size = 2.5) + geom_smooth(color = "black", se = FALSE) + theme_bw(base_size = 12) + labs(x = "Weight (lbs)", y = "Hip (inches)") + ggtitle("Hip and Weight by Sex") + scale_linetype(name = "Sex") *ggsave(diabetes_plot, path = "diabetes_figure.png", dpi = 320) ``` --- class: inverse-ns, center, takeaways # You can use this code template to make thousands of graphs with ggplot2. ```r ggplot(data = <DATA>, mapping = aes(<MAPPINGS>)) + <GEOM_FUNCTION>() + <SCALE_FUNCTION>() + <THEME_FUNCTION>() ``` --- class: inverse-ns, center  --- class: inverse, center # Resources ## [R for Data Science](http://r4ds.had.co.nz/): A comprehensive but friendly introduction to the tidyverse. Free online. ## [DataCamp](https://www.datacamp.com/): ggplot2 courses and tidyverse courses ## [ggplot2: Elegant Graphics for Data Analysis](https://smile.amazon.com/ggplot2-Elegant-Graphics-Data-Analysis/dp/331924275X/ref=sr_1_2?ie=UTF8&qid=1524362742&sr=8-2&keywords=ggplot2): The official ggplot2 book --- class: inverse, center, middle  ###
[ndemosato](https://github.com/ndemosato/) ###
[@SatoMartin](https://twitter.com/SatoMartin) Slides created via the R package [xaringan](https://github.com/yihui/xaringan). --- class: inverse-ns, center ## <span style = 'color:#E69F00'>Bonus!</span> --- ## Arranging plots -- ## Spatial plots -- ## Interactive plots -- ## Animated plots --- class: inverse-ns, center # Data Visualization Principles --- class: inverse-ns, center # Data Visualization Principles ## <span style = 'color:#E69F00'>Simplify and focus</span> --- class: inverse-ns, center # Data Visualization Principles ## <span style = 'color:#6C7B7F'>Simplify and focus</span> ## <span style = 'color:#E69F00'>Increase your text size</span> --- class: inverse-ns, center # Data Visualization Principles ## <span style = 'color:#6C7B7F'>Simplify and focus</span> ## <span style = 'color:#6C7B7F'>Increase your text size</span> ## <span style = 'color:#E69F00'>Avoid pie charts (use bar charts)</span> --- class: inverse-ns, center # Data Visualization Principles ## <span style = 'color:#6C7B7F'>Simplify and focus</span> ## <span style = 'color:#6C7B7F'>Increase your text size</span> ## <span style = 'color:#6C7B7F'>Avoid pie charts (use bar charts)</span> ## <span style = 'color:#E69F00'>Avoid line drawings (use fill/color)</span> --- class: inverse-ns, center # Data Visualization Principles ## <span style = 'color:#6C7B7F'>Simplify and focus</span> ## <span style = 'color:#6C7B7F'>Increase your text size</span> ## <span style = 'color:#6C7B7F'>Avoid pie charts (use bar charts)</span> ## <span style = 'color:#6C7B7F'>Avoid line drawings (use fill/color)</span> ## <span style = 'color:#E69F00'>Stay 2D</span>