class: center middle main-title section-title-4 # Time .class-info[ **Session 13** .light[PMAP 8921: Data Visualization with R<br> Andrew Young School of Policy Studies<br> Summer 2024] ] --- name: outline class: title title-inv-7 # Plan for today -- .box-5.medium.sp-after[Axis issues] -- .box-3.medium.sp-after[Visualizing time] -- .box-1.medium[Starting, ending,<br>and decomposing time] --- layout: false name: axis-issues class: center middle section-title section-title-5 animated fadeIn # Axis issues --- layout: true class: title title-5 --- # Is truncating the y-axis misleading? <img src="13-slides_files/figure-html/truncation-yes-no-1.png" width="864" style="display: block; margin: auto;" /> --- # Don't be too extreme! .box-inv-5.medium[It is actually more legal to<br>truncate the y-axis than you might think!] -- .box-5[When small movements matter] -- .box-5[When the scale itself is distorted] -- .box-5[When zero values are impossible] --- # When is it okay to truncate? .box-inv-5[When small movements matter] -- .pull-left[ <figure> <img src="img/13/us_gdp_us_gdp_chartbuilder-3.png" alt="GDP not truncated, from Quartz" title="GDP not truncated, from Quartz" width="100%"> </figure> ] -- .pull-right[ <figure> <img src="img/13/us_gdp_us_gdp_chartbuilder-2.png" alt="GDP truncated, from Quartz" title="GDP truncated, from Quartz" width="100%"> </figure> ] ??? Stock prices too https://qz.com/418083/its-ok-not-to-start-your-y-axis-at-zero/ --- # When is it okay to truncate? .box-inv-5[When the scale itself is distorted] -- .pull-left.center[ <figure> <img src="img/13/uber-sign.jpg" alt="Sign in an Uber car about rating system" title="Sign in an Uber car about rating system" width="60%"> </figure> ] -- .pull-right[ <figure> <img src="img/13/uber-scale.jpg" alt="Internal rating system at Uber" title="Internal rating system at Uber" width="100%"> </figure> ] ??? https://www.buzzfeed.com/carolineodonovan/the-fault-in-five-stars http://www.businessinsider.com/leaked-charts-show-how-ubers-driver-rating-system-works-2015-2 --- # When is it okay to truncate? .box-inv-5[When zero values are impossible] -- .pull-left[ <figure> <img src="img/13/oral_temperature_sara_bob_chartbuilder.png" alt="Temperature not truncated, from Quartz" title="Temperature not truncated, from Quartz" width="100%"> </figure> ] -- .pull-right[ <figure> <img src="img/13/oral_temperature_sara_bob_chartbuilder-1.png" alt="Temperature truncated, from Quartz" title="Temperature truncated, from Quartz" width="100%"> </figure> ] ??? https://qz.com/418083/its-ok-not-to-start-your-y-axis-at-zero/ --- # Never on bar charts .pull-left.center[ <figure> <img src="img/04/obamacareenrollment-fncchart.jpg" alt="Fox News Obamacare enrollment" title="Fox News Obamacare enrollment" width="100%"> </figure> ] -- .pull-right.center[ <figure> <img src="img/04/econcharts-education.gif" alt="Obama graduation rate" title="Obama graduation rate" width="100%"> </figure> ] --- # Zero is okay too! .box-inv-5.medium[Just because you don't *have to* start at 0<br>doesn't mean you should *never* start at 0] .box-5.small.sp-after[It's often a good idea!] --- # Keep axis scales consistent .center[ <figure> <img src="img/13/fox-co-covid-cases.jpg" alt="FOX Colorado affiliate graph with COVID-19 cases" title="FOX Colorado affiliate graph with COVID-19 cases" width="55%"> <figcaption>FOX affiliate in Colorado reporting on COVID-19 cases</figcaption> </figure> ] ??? http://freerangestats.info/blog/2020/04/06/crazy-fox-y-axis --- # Keep axis scales consistent .center[ <figure> <img src="img/13/08fig21.jpg" alt="Good and bad treatment of missing values in x-axis" title="Good and bad treatment of missing values in x-axis" width="80%"> </figure> ] ??? Alberto Cairo, *The Truthful Art*, chapter 8, figure 8.21 --- # Don’t impute across categories .pull-left[ <img src="13-slides_files/figure-html/likert-imputation-bad-1.png" width="100%" style="display: block; margin: auto;" /> ] -- .pull-right[ <img src="13-slides_files/figure-html/likert-good-1.png" width="100%" style="display: block; margin: auto;" /> ] --- layout: false name: visualizing-time class: center middle section-title section-title-3 animated fadeIn # Visualizing time --- layout: true class: title title-3 --- # Showing changes over time .box-inv-3[Time is just a variable that can be mapped to an aesthetic] -- .box-inv-3[Can be used as `x`, `y`, `color`, `fill`, `facet`, and even animation] -- .box-inv-3.sp-after[Can use all sorts of `geom` s:<br>lines, columns, points, heatmaps, densities, maps, etc.] -- .box-3[In general, follow reading conventions to show time progression:] .box-3.medium[→ & ↓] --- # Time on x-axis + `geom_line/col()` .pull-left[ <img src="13-slides_files/figure-html/covid-unemp-claims-1.png" width="100%" style="display: block; margin: auto;" /> ] .pull-right.center[ <figure> <img src="img/13/nyt_2020-05-09.jpg" alt="Front page of the NYT, May 9, 2020" title="Front page of the NYT, May 9, 2020" width="50%"> <figcaption><a href="https://static01.nyt.com/images/2020/05/09/nytfrontpage/scan.pdf" target="_blank">Front page of the New York Times</a>, May 9, 2020</figcaption> </figure> ] ??? Monthly change in jobs since end of WWII The New York Times front page, May 9, 2020 https://www.nytimes.com/issue/todayspaper/2020/05/09/todays-new-york-times https://static01.nyt.com/images/2020/05/09/nytfrontpage/scan.pdf --- # Time on x-axis + `geom_tile()` .center[ <figure> <img src="img/13/08fig28.jpg" alt="Heat map by Jorge Camões" title="Heat map by Jorge Camões" title="Heat map by Jorge Camões" title="Heat map by Jorge Camões" width="65%"> <figcaption>Figure 8.28 in Alberto Cairo's <i>The Truthful Art</i>: Heat map by Jorge Camões</figcaption> </figure> ] ??? Alberto Cairo, *The Truthful Art*, chapter 8, figure 8.28 --- # Time on y-axis + `geom_density()` <img src="13-slides_files/figure-html/density-ridges-1.png" width="80%" style="display: block; margin: auto;" /> --- # Time in animation + `geom_point()` .center[ <figure> <img src="img/03/rosling-tedx.jpg" alt="Hans Rosling" title="Hans Rosling" width="65%"> </figure> ] ??? Source: [New York Times](https://www.nytimes.com/2017/02/09/world/europe/hans-rosling-dead-statistician.html) --- # Time in maps .center[ <figure> <img src="img/13/08fig30.jpg" alt="Map by Jorge Camões" title="Map by Jorge Camões" width="50%"> <figcaption>Figure 8.30 in Alberto Cairo's <i>The Truthful Art</i>: Map of the spread of Walmart by Jorge Camões</figcaption> </figure> ] ??? Alberto Cairo, *The Truthful Art*, chapter 8, figure 8.30 --- # Time in `geom_col()` + small multiples .center[ <figure> <img src="img/13/us-cities-kitchen-counter-cropped.png" alt="ZZZ" title="ZZZ" width="100%"> <figcaption>Kieran Healy, <a href="https://kieranhealy.org/blog/archives/2020/05/21/the-kitchen-counter-observatory/" target="_blank">“The Kitchen Counter Observatory”</a></figcaption> </figure> ] ??? https://kieranhealy.org/blog/archives/2020/05/21/the-kitchen-counter-observatory/ --- # Don't go wild with time mapping! .center[ <figure> <img src="img/13/covid-conversation-spiral.png" alt="Change in COVID death rates" title="Change in COVID death rates" width="65%"> <figcaption><a href="https://theconversation.com/three-graphs-that-show-a-global-slowdown-in-covid-19-deaths-135756" target="_blank">Tornado plot</a>: When a curve crosses the left of the central axis, the number of deaths per day falls</figcaption> </figure> ] ??? https://theconversation.com/three-graphs-that-show-a-global-slowdown-in-covid-19-deaths-135756 --- # Interpreting tornado plots <img src="13-slides_files/figure-html/tornado-1.png" width="100%" style="display: block; margin: auto;" /> ??? http://www.bewitched.com/demo/tornado/tornado.html http://www.dannydorling.org/books/SLOWDOWN/Illustrations.html --- # Better with multiple plots .pull-left[ <img src="13-slides_files/figure-html/unemp-inflation-path-1.png" width="100%" style="display: block; margin: auto;" /> ] -- .pull-right[ <img src="13-slides_files/figure-html/unemp-inflation-good-1.png" width="100%" style="display: block; margin: auto;" /> ] --- layout: false name: decomposing class: center middle section-title section-title-1 animated fadeIn # Starting, ending,<br>and decomposing time --- layout: true class: title title-1 --- # ∞ .box-inv-1.medium[You always have to choose<br>a start and end point] .box-inv-1[Start and end at reasonable times that<br>help maintain the context of the story] --- # Measles vaccine was pretty effective! <img src="13-slides_files/figure-html/measles-partial-1.png" width="60%" style="display: block; margin: auto;" /> ??? Data sources listed here: https://commons.m.wikimedia.org/wiki/File:Measles_US_1938-2019.png I used [this big PDF table from the CDC](https://web.archive.org/web/20190120205018/https://www.cdc.gov/vaccines/pubs/pinkbook/downloads/appendices/e/reported-cases.pdf), used some random online PDF → CSV converter, and cleaned up the data by hand in Excel: --- # Measles vaccine was *incredible*! <img src="13-slides_files/figure-html/measles-full-1.png" width="70%" style="display: block; margin: auto;" /> --- # Seasonality .box-inv-1[Don't mistake seasonality for actual trends] .pull-left[ <img src="13-slides_files/figure-html/seasonality-zoomed-in-1.png" width="100%" style="display: block; margin: auto;" /> ] -- .pull-right[ <img src="13-slides_files/figure-html/seasonality-zoomed-out-1.png" width="100%" style="display: block; margin: auto;" /> ] --- # Decomposition <img src="13-slides_files/figure-html/retail-decomposition-1.png" width="60%" style="display: block; margin: auto;" /> --- # Birthday decomposition .center[ <figure> <img src="img/13/bda_cover.png" alt="Bayesian Data Analysis cover" title="Bayesian Data Analysis cover" width="45%"> <figcaption>Cover of Andrew Gelman, et al., <i>Bayesian Data Analysis</i></figcaption> </figure> ] ??? http://www.stat.columbia.edu/~gelman/book/