class: title-slide <br> <br> .right-panel[ <br> # Improving Data Visualizations ## Dr. Mine Dogucu ] --- class: middle .panelset[ .panel[ .panel-name[Plot] <img src="Lab-04b-improve-dataviz_files/figure-html/unnamed-chunk-2-1.png" style="display: block; margin: auto;" /> ] .panel[ .panel-name[English] - Using the `babies` data, - Map `gestation` to x-axis, `bwt` to y-axis, `smoke` to shape and color. - Add a layer of points and set the size of the points to 4. ] .panel[ .panel-name[R] ``` r ggplot(babies, aes(x = gestation, y = bwt, shape = smoke, color = smoke)) + geom_point(size = 4) ``` ] ] --- class: middle ## Labs .panelset[ .panel[ .panel-name[Plot] <img src="Lab-04b-improve-dataviz_files/figure-html/unnamed-chunk-4-1.png" style="display: block; margin: auto;" /> ] .panel[ .panel-name[English] - Using the `babies` data, - Map `gestation` to x-axis, `bwt` to y-axis, `smoke` to shape. - Add a layer of points and set the size of the points to 4. - .highlight-text[Add labels to x-axis (Gestation), y-axis (Birth Weight), and the title of the plot (Palmer babies).] .panel[ .panel-name[R] ``` r ggplot(babies, aes(x = gestation, y = bwt, shape = smoke, color = smoke)) + geom_point(size = 4) + * labs(x = "Gestation (days)", * y = "Birth Weight (ounces)", * title = "Gestation and Birth Weight by Mother's Smoker Status") ``` ] ] ] --- .left-panel[ ``` r ggplot(babies, aes(x = gestation, y = bwt, shape = smoke, color = smoke)) + geom_point() + labs(x = "Gestation (days)", y = "Birth Weight (ounces)", title = "Gestation and Birth Weight by Mother's Smoker Status") * theme_bw() ``` ] .right-panel[ ![](Lab-04b-improve-dataviz_files/figure-html/unnamed-chunk-7-1.png)<!-- --> ] --- class: middle ## Themes .panelset[ .panel[ .panel-name[`theme_gray()`] <img src="Lab-04b-improve-dataviz_files/figure-html/unnamed-chunk-8-1.png" style="display: block; margin: auto;" /> ] .panel[ .panel-name[`theme_bw()`] <img src="Lab-04b-improve-dataviz_files/figure-html/unnamed-chunk-9-1.png" style="display: block; margin: auto;" /> ] .panel[ .panel-name[`theme_classic()`] <img src="Lab-04b-improve-dataviz_files/figure-html/unnamed-chunk-10-1.png" style="display: block; margin: auto;" /> ] .panel[ .panel-name[`theme_dark()`] <img src="Lab-04b-improve-dataviz_files/figure-html/unnamed-chunk-11-1.png" style="display: block; margin: auto;" /> ] .panel[ .panel-name[`theme_minimal()`] <img src="Lab-04b-improve-dataviz_files/figure-html/unnamed-chunk-12-1.png" style="display: block; margin: auto;" /> ] .panel[ .panel-name[`theme_void()`] <img src="Lab-04b-improve-dataviz_files/figure-html/unnamed-chunk-13-1.png" style="display: block; margin: auto;" /> ] ] --- .left-panel[ ``` r ggplot(babies, aes(x = gestation, y = bwt, shape = smoke, color = smoke)) + geom_point() + labs(x = "Gestation (days)", y = "Birth Weight (ounces)", title = "Baby Gestation and Birth Weight by Mother's Smoker Status") + theme_bw() + theme(title = element_text(size = 12), axis.title = element_text(size = 10, face="bold")) ``` ] .right-panel[ ![](Lab-04b-improve-dataviz_files/figure-html/unnamed-chunk-15-1.png)<!-- --> ] --- class: middle ``` r ?theme ``` There are more aspects of a theme that we can control. --- class: middle .left-panel[ ``` r ggplot(babies, aes(x = gestation, y = bwt, shape = smoke, color = smoke)) + geom_point(size = 4) + * facet_grid(.~parity) ``` ] .right-panel[ <img src="Lab-04b-improve-dataviz_files/figure-html/unnamed-chunk-18-1.png" style="display: block; margin: auto;" /> ] --- class: middle .left-panel[ ``` r ggplot(babies, aes(x = gestation, y = bwt, shape = smoke, color = smoke)) + geom_point(size = 4) + * facet_grid(parity~.) ``` ] .right-panel[ <img src="Lab-04b-improve-dataviz_files/figure-html/unnamed-chunk-20-1.png" style="display: block; margin: auto;" /> ] --- class: middle You can do much more in ggplot. - Use images - Make maps - Pick colors that you want --- class: middle Check out [the ggplot flipbook](https://evamaerey.github.io/ggplot_flipbook/ggplot_flipbook_xaringan.html#1) for some inspiration. --- class: middle - [BBC](https://bbc.github.io/rcookbook/) - [fivethirtyeight](https://blog.revolutionanalytics.com/2016/07/data-journalism-with-r-at-538.html?utm_content=bufferc03e0&utm_medium=social&utm_source=twitter.com&utm_campaign=buffer) - [NY Times](https://livefreeordichotomize.com/2021/04/07/nytimes-map-how-to/)