# A tibble: 8 × 4
# Groups: state [4]
state event_type n within_state
<chr> <chr> <int> <dbl>
1 California High Wind 583 0.487
2 California Excessive Heat 186 0.156
3 Florida Thunderstorm Wind 475 0.626
4 Florida Flash Flood 188 0.248
5 Pennsylvania Thunderstorm Wind 971 0.594
6 Pennsylvania Hail 209 0.128
7 Texas Hail 1588 0.312
8 Texas Thunderstorm Wind 988 0.194
Stacked bar charts—a bar chart of spine charts
Code
state_type |>ggplot(aes(state, n, fill = event_type)) +geom_col() +labs(title ="Totals and composition are visible together", x =NULL, y ="Event records", fill ="Event type")
The total bar height shows the marginal distribution of state. Segments show the joint counts, but only the bottom segment has a common baseline.
Stacked bar charts with conditional proportions
Code
state_type |>ggplot(aes(state, n, fill = event_type)) +geom_col(position ="fill") +scale_y_continuous(labels = percent) +labs(title ="Now each bar answers: within this state, what is the mix?", x =NULL, y ="Within-state share", fill ="Event type")
Side-by-side bar charts
Code
state_type |>ggplot(aes(event_type, n, fill = state)) +geom_col(position =position_dodge(preserve ="single")) +coord_flip() +labs(title ="A common baseline helps compare states within an event type", x =NULL, y ="Event records", fill ="State")
state_type |>complete(state, event_type, fill =list(n =0)) |>arrange(state, event_type) |>slice_head(n =12)
# A tibble: 12 × 3
state event_type n
<chr> <chr> <int>
1 California Drought 0
2 California Excessive Heat 186
3 California Flash Flood 101
4 California Hail 21
5 California Heat 106
6 California High Wind 583
7 California Thunderstorm Wind 73
8 California Winter Weather 126
9 Florida Drought 10
10 Florida Excessive Heat 0
11 Florida Flash Flood 188
12 Florida Hail 75
An absent row and a true zero are not automatically the same. Complete the grid only after deciding what a missing combination means.
Visualize independence tests with mosaic plots
Checkpoint 1 · Name the denominator
You are comparing Pennsylvania with Texas. Write one question that needs counts and one that needs within-state percentages. What misleading conclusion could arise from using the wrong denominator?
A chi-square test compares observed and expected counts
The null hypothesis says the two categorical variables are independent.
The empirical cumulative distribution function at value \(x\) is
\[
\widehat{F}(x) = \frac{\#\{X_i \le x\}}{n}.
\]
Read it as: the share of observations at or below \(x\).
Unlike a histogram, an ECDF has no bins to choose.
The jump at $0 is a feature, not a nuisance
What about comparing to theoretical distributions?
A one-sample Kolmogorov–Smirnov statistic measures the largest vertical distance between an empirical cumulative distribution and a specified theoretical CDF:
\[
D_n = \sup_x |F_n(x)-F_0(x)|.
\]
The test is about a fully specified distribution, not merely whether a histogram looks roughly bell-shaped.
Checkpoint 2 · Predict the shape
Before plotting, sketch the distribution of non-missing property damage. What feature should appear at $0? Where will the mean fall relative to the median? What will adding one and taking a log reveal?
Histograms display 1D continuous distributions
Why transform?
A \(\log_{10}(\text{damage}+1)\) transform keeps zero visible while making multiplicative differences readable:
0 represents $0,
3 is approximately $1,000,
6 is approximately $1,000,000,
9 is approximately $1,000,000,000.
The transform changes the visual scale, not the archived values. Missing damage remains missing rather than being recoded to zero.
Checkpoint 3 · Write the caption
Write a two-sentence caption for the histogram: one sentence describing the main pattern and one sentence explaining how zero and missing values were handled. Avoid saying the data are “normal.”
Recap and next steps
Percentages require a named denominator.
A test detects association; residuals help locate it.
A quantitative summary is not a distribution.
Cleaning and scale choices are part of the claim.
Next: choosing and tuning distribution displays, then comparing distributions across groups.