Skip to content

Commit

Permalink
keynote mostly done
Browse files Browse the repository at this point in the history
  • Loading branch information
clauswilke committed Jun 23, 2024
1 parent 8131452 commit 594a2e5
Show file tree
Hide file tree
Showing 26 changed files with 4,457 additions and 1,507 deletions.
436 changes: 347 additions & 89 deletions docs/materials/2024-06-24.Rmd

Large diffs are not rendered by default.

281 changes: 213 additions & 68 deletions docs/materials/2024-06-24.html

Large diffs are not rendered by default.

166 changes: 85 additions & 81 deletions docs/materials/2024-06-24_files/figure-html/freq-waffle-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
162 changes: 81 additions & 81 deletions docs/materials/2024-06-24_files/figure-html/freq-waffle2-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
110 changes: 55 additions & 55 deletions docs/materials/2024-06-24_files/figure-html/freq-waffle3-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
110 changes: 55 additions & 55 deletions docs/materials/2024-06-24_files/figure-html/freq-waffle4-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
166 changes: 83 additions & 83 deletions docs/materials/2024-06-24_files/figure-html/freq-waffle5-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
475 changes: 263 additions & 212 deletions docs/materials/2024-06-24_files/figure-html/hpi-detrended-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
586 changes: 586 additions & 0 deletions docs/materials/2024-06-24_files/figure-html/hpi-detrended2-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
395 changes: 285 additions & 110 deletions docs/materials/2024-06-24_files/figure-html/hpi-no-trendline-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
403 changes: 289 additions & 114 deletions docs/materials/2024-06-24_files/figure-html/hpi-trends-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
243 changes: 243 additions & 0 deletions docs/materials/2024-06-24_files/figure-html/hpi-trends-CA-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
609 changes: 609 additions & 0 deletions docs/materials/2024-06-24_files/figure-html/hpi-trends-linear-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
128 changes: 106 additions & 22 deletions docs/materials/2024-06-27.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ Topics to cover:

- uncertainty visualizations

## Running Code
## Required packages

Install required packages
Install the required packages:

```{r}
# run this only once
#| eval = FALSE
# Run this command to install the required packages.
# You need to do this only once.
install.packages(
c(
"tidyverse", "broom", "ggdist", "distributional", "gapminder",
Expand All @@ -30,25 +33,11 @@ install.packages(
)
```

Required libraries

```{r}
library(tidyverse)
library(broom)
#library(mgcv)
#library(gratia)
#library(gganimate)
library(ggdist)
library(distributional)
library(gapminder)
# also needed but don't have to be loaded:
# gifski
```

## 1. Error bars and other uncertainty visualizations

```{r}
#| message = FALSE
library(tidyverse)
library(broom) # for extracting regression parameters
library(gapminder) # for dataset
Expand Down Expand Up @@ -197,8 +186,8 @@ ggplot(lm_data_1952, aes(x = estimate, y = continent)) +
)),
point_size = 4,
fill = "skyblue",
#.width = c(.66, .95, .99), # 1, 2, 3 SD
.width = .66 # 1 SD only
#.width = c(.68, .95, .997), # 1, 2, 3 SD
.width = .68 # 1 SD only
)
```

Expand All @@ -222,6 +211,8 @@ ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
Step 1: Extract samples from fitted model.

```{r}
#| message = FALSE
library(mgcv) # to fit generalized additive models with gam()
library(gratia) # to generate samples from fitted model
Expand Down Expand Up @@ -304,6 +295,8 @@ anim_obj
In practice we may want to customize how exactly the animation is rendered, such as the exact width/height, number of frames, frames per seconds shown, etc.

```{r}
#| eval = FALSE
animate(
anim_obj,
fps = 5, # frames per second
Expand All @@ -316,6 +309,8 @@ animate(
We can save as gif or mp4 with `anim_save()`.

```{r}
#| eval = FALSE
anim_save(
"blue-jays-HOP.gif",
anim_obj,
Expand All @@ -339,4 +334,93 @@ ggplot(mtcars, aes(x = disp, y = mpg)) +
# your code here
```

## 3. Trendlines and detrending
## 3. Trendlines and de-trending

The first example will be trends in the US housing market by state.

```{r}
# Freddie Mac House Price Index data
# from: https://www.freddiemac.com/research/indices/house-price-index
fmhpi <- read_csv(
"https://wilkelab.org/dataviz_shortcourse/datasets/fmhpi.csv",
show_col_types = FALSE
) |>
filter(year >= 1980) # trends are weird before 1980
# plot house price index (HPI) for a few states
fmhpi |>
filter(state %in% c("California", "Nevada", "West Virginia", "Texas")) |>
ggplot(aes(date_dec, hpi)) +
geom_line() +
xlab("Year") +
scale_y_log10(name = "House Price Index") +
facet_wrap(~state)
```

As housing prices are growing exponentially, we need to fit a trend line in log space. Let's do this and plot.

```{r}
# we fit trendlines separately for all states
fmhpi_trends <- fmhpi |>
nest(data = -state) |>
mutate(
# fit in log space (never fit exponentials in linear space!)
fit_log = map(data, ~lm(log(hpi) ~ date_dec, data = .x)),
# predict long-term trend from fitted model
hpi_trend_log = map2(fit_log, data, ~exp(predict(.x, .y)))
) |>
select(-fit_log) |>
unnest(cols = c(data, hpi_trend_log))
fmhpi_trends |>
filter(state %in% c("California", "Nevada", "West Virginia", "Texas")) |>
ggplot(aes(date_dec, hpi)) +
geom_line(aes(color = "Raw HPI")) +
geom_line(aes(y = hpi_trend_log, color = "trendline")) +
xlab("Year") +
scale_y_log10(name = "House Price Index (HPI)") +
scale_color_manual(
name = NULL,
values = c("Raw HPI" = "#0072B2", trendline = "#D55E00")
) +
facet_wrap(~state) +
theme(legend.position = "bottom")
```

Now we can de-trend by dividing the raw value by the trendline.

```{r}
fmhpi_trends |>
filter(state %in% c("California", "Nevada", "West Virginia", "Texas")) |>
ggplot(aes(date_dec, hpi/hpi_trend_log)) +
geom_line(color = "#0072B2") +
xlab("Year") +
scale_y_log10( # important, still need to use log scale
name = "HPI de-trended",
limits = c(0.5, 2)
) +
facet_wrap(~state)
```

### Exercises

Exercises for the HPI data:

- Make plots of raw and de-trended HPI data for other US states. Can you find interesting patterns?

- Perform a linear (as opposed to logarithmic) de-trending and see how the results differ.

```{r}
# your code here
```

Exercises for seasonal decomposition:

- ***Exercise 1***

- ***Exercise 2***

```{r}
# your code here
```
8 changes: 4 additions & 4 deletions docs/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
"description": "A bootcamp-style course on data visualization",
"author": [],
"contents": "\nThis is the home page for a dataviz shortcourse by Claus O. Wilke. The course is an abbreviated version of a semester-long course taught at The University of Texas at Austin. Many of the materials presented are taken from the book Fundamentals of Data Visualization.\n\nReuse\nText and figures are licensed under Creative Commons Attribution CC BY 4.0. Any computer code (R, HTML, CSS, etc.) in slides and worksheets, including in slide and worksheet sources, is also licensed under MIT. Note that figures in slides may be pulled in from external sources and may be licensed under different terms. For such images, image credits are available in the slide notes, accessible via pressing the letter ‘p’.\n\n\n\n",
"last_modified": "2024-06-23T13:40:44-05:00"
"last_modified": "2024-06-23T18:52:00-05:00"
},
{
"path": "lessons.html",
"title": "Lessons",
"description": "",
"author": [],
"contents": "\n\nContents\nEffective Visual Communication\nFrom Data to Visualisation 1\nFrom Data to Visualisation 2\nPrinciples of Figure Design\nReuse\n\nEffective Visual Communication\nThis lecture covers three core concepts of visual communication. First, I will discuss how to engage your audience by telling a story. Second, I will provide high-level guidance for designing visualizations that make a clear point. Third, I will describe key design principles that ensure your figures will be readable by people with vision impairments, and specifically impairments of color perception.\n\nMaterials:\n\nSlides\nFrom Data to Visualisation 1\nVisualizing amounts; visualizing distributions; visualizing associations and trends\n\nMaterials:\n\nSlides\nFrom Data to Visualisation 2\nVisualizing uncertainty; visualizing geospatial data\n\nMaterials:\n\nSlides\nPrinciples of Figure Design\nColors; compound figures; infographics\n\nMaterials:\n\nSlides\nReuse\nText and figures are licensed under Creative Commons Attribution CC BY 4.0. Any computer code (R, HTML, CSS, etc.) in slides and worksheets, including in slide and worksheet sources, is also licensed under MIT. Note that figures in slides may be pulled in from external sources and may be licensed under different terms. For such images, image credits are available in the slide notes, accessible via pressing the letter ‘p’.\n\n\n\n",
"last_modified": "2024-06-23T13:40:44-05:00"
"last_modified": "2024-06-23T18:52:01-05:00"
},
{
"path": "workshops.html",
"title": "Workshops",
"description": "",
"author": [],
"contents": "\n\nContents\nPast and present workshops\nReuse\n\nPast and present workshops\nMaterials for past and present workshops. The specific slide sets may differ from the four main lessons. All materials are primarily based on material from my semester-long data visualization course at UT Austin.\n2024-06-20\nWorkshop in support of Ukraine. To work through all the examples provided, you will need the following R packages: tidyverse, cowplot, ggiraph, sf, patchwork\nSlides Part 1\nSlides Part 2\nSlides Part 2, without interactivity (Some browsers crash when there are too many interactive examples in one slide set.)\n2024-05-28\nSlides Part 1 (telling a story, making a point, making figures accessible)\nSlides Part 2 (figure composition and context, text annotations, overplotting)\nReuse\nText and figures are licensed under Creative Commons Attribution CC BY 4.0. Any computer code (R, HTML, CSS, etc.) in slides and worksheets, including in slide and worksheet sources, is also licensed under MIT. Note that figures in slides may be pulled in from external sources and may be licensed under different terms. For such images, image credits are available in the slide notes, accessible via pressing the letter ‘p’.\n\n\n\n",
"last_modified": "2024-06-23T13:40:45-05:00"
"contents": "\n\nContents\nPast and present workshops\nReuse\n\nPast and present workshops\nMaterials for past and present workshops. The specific slide sets may differ from the four main lessons. All materials are primarily based on material from my semester-long data visualization course at UT Austin.\nVisualizing Uncertainty and Trends\nKeynote, June 24 2024: slides\nWorkshop, June 27 2024: coming soon\n2024-06-20\nWorkshop in support of Ukraine. To work through all the examples provided, you will need the following R packages: tidyverse, cowplot, ggiraph, sf, patchwork\nSlides Part 1\nSlides Part 2\nSlides Part 2, without interactivity (Some browsers crash when there are too many interactive examples in one slide set.)\n2024-05-28\nSlides Part 1 (telling a story, making a point, making figures accessible)\nSlides Part 2 (figure composition and context, text annotations, overplotting)\nReuse\nText and figures are licensed under Creative Commons Attribution CC BY 4.0. Any computer code (R, HTML, CSS, etc.) in slides and worksheets, including in slide and worksheet sources, is also licensed under MIT. Note that figures in slides may be pulled in from external sources and may be licensed under different terms. For such images, image credits are available in the slide notes, accessible via pressing the letter ‘p’.\n\n\n\n",
"last_modified": "2024-06-23T18:52:01-05:00"
}
],
"collections": []
Expand Down
5 changes: 5 additions & 0 deletions docs/workshops.html
Original file line number Diff line number Diff line change
Expand Up @@ -2491,6 +2491,11 @@ <h3>Contents</h3>
</div>
<h2 id="past-and-present-workshops">Past and present workshops</h2>
<p>Materials for past and present workshops. The specific slide sets may differ from the four main lessons. All materials are primarily based on material from my semester-long <a href="https://wilkelab.org/SDS375/">data visualization course at UT Austin.</a></p>
<p><strong class="nospace">Visualizing Uncertainty and Trends</strong></p>
<ul>
<li>Keynote, June 24 2024: <a href="materials/2024-06-24.html">slides</a></li>
<li>Workshop, June 27 2024: coming soon</li>
</ul>
<p><strong class="nospace">2024-06-20</strong></p>
<p>Workshop in <a href="https://sites.google.com/view/dariia-mykhailyshyna/main/r-workshops-for-ukraine#h.95gc1ocexdze">support of Ukraine.</a> To work through all the examples provided, you will need the following R packages: tidyverse, cowplot, ggiraph, sf, patchwork</p>
<ul>
Expand Down
Loading

0 comments on commit 594a2e5

Please sign in to comment.