Follow your Curiosity, Focus your Story
The Dashboard is a classic exploratory tool Use
View()in Positron
EDA is like an archaeological dig: you never know what you might find and the more you discover, the more you dig.
Questions:
02:30
# A tibble: 51 × 2
State Count
<chr> <dbl>
1 Alabama 13047
2 Alaska 2697
3 Arizona 89798
4 Arkansas 7108
5 California 1256646
6 Colorado 90083
7 Connecticut 31557
8 Delaware 8435
9 District of Columbia 8066
10 Florida 254878
# ℹ 41 more rows
# A tibble: 51 × 2
State Count
<chr> <dbl>
1 Alabama 13047
2 Alaska 2697
3 Arizona 89798
4 Arkansas 7108
5 California 1256646
6 Colorado 90083
7 Connecticut 31557
8 Delaware 8435
9 District of Columbia 8066
10 Florida 254878
# ℹ 41 more rows
Option 1: Total missing counts
# A tibble: 1 × 1
n_missing
<int>
1 0


geom_bar()
Counts up the number of observations in each level of a single variable, then draws bars up to that height.
# A tibble: 344 × 8
species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
<fct> <fct> <dbl> <dbl> <int> <int>
1 Adelie Torgersen 39.1 18.7 181 3750
2 Adelie Torgersen 39.5 17.4 186 3800
3 Adelie Torgersen 40.3 18 195 3250
4 Adelie Torgersen NA NA NA NA
5 Adelie Torgersen 36.7 19.3 193 3450
6 Adelie Torgersen 39.3 20.6 190 3650
7 Adelie Torgersen 38.9 17.8 181 3625
8 Adelie Torgersen 39.2 19.6 195 4675
9 Adelie Torgersen 34.1 18.1 193 3475
10 Adelie Torgersen 42 20.2 190 4250
# ℹ 334 more rows
# ℹ 2 more variables: sex <fct>, year <int>
geom_bar()
Counts up the number of observations in each level of a single variable, then draws bars up to that height.

# A tibble: 3 × 2
island n
<fct> <int>
1 Biscoe 168
2 Dream 124
3 Torgersen 52
geom_col()
Takes one column of categories and draws a bar for each up to the height of a second column of counts.



Features
Common Exploratory Questions
Features
Common Explanatory Questions
labs()The labels on the plot can refer to many different places where text is added to describe what is plotted.
In ggplot2, these are arguments to a labs() layer.
titlesubtitlecolorfillsizeshapeCompares one species to another species.

Compares each species to a baseline of zero.
Pay attention to where the x = 40 and x = 60 lines are…
Emphasize certain comparisons (and occlude others) by altering the limits of the axes to include a relevant baseline and by using non-linear scales.
lims()scale_x_log10()scale_y_log10()scale_ family of layersHow could I make it easiest to understand the relative commonality of the three species?
forcats
Theme
A set of visual design choices for the plot on things like the background, the gridlines, the axes, the tick marks, and the fonts.
Some ggplot2 themes (each one can be added as layer)
theme_gray(): the defaulttheme_bw()theme_minimal()Audience: Residents and decisions makers in all fifty states.
My story: There is considerable variability from state to state in EV registrations.
My strategy: Display the registration counts in a manner that makes it easy to see the counts of each individual state equally well.










ev |>
ggplot(aes(x = State, y = Count)) +
geom_col() +
theme(axis.text.x = element_text(angle = 270,
hjust = 0,
vjust = 0.5),
plot.title = element_text(hjust = 0.5)) +
labs(title = "Electric Vehicle Registrations by State",
x = "",
y = "Registration Count") +
scale_y_sqrt(labels = scales::comma) +
theme_minimal()
ev |>
ggplot(aes(x = State, y = Count)) +
geom_col() +
theme_minimal(axis.text.x = element_text(angle = 270,
hjust = 0,
vjust = 0.5),
plot.title = element_text(hjust = 0.5)) +
labs(title = "Electric Vehicle Registrations by State",
x = "",
y = "Registration Count") +
scale_y_sqrt(labels = scales::comma)Error in `theme_minimal()`:
! unused arguments (axis.text.x = element_text(angle = 270, hjust = 0, vjust = 0.5), plot.title = element_text(hjust = 0.5))
ev |>
ggplot(aes(x = State, y = Count)) +
geom_col() +
theme_minimal() +
theme(axis.text.x = element_text(angle = 270,
hjust = 0,
vjust = 0.5),
plot.title = element_text(hjust = 0.5)) +
labs(title = "Electric Vehicle Registrations by State",
x = "",
y = "Registration Count") +
scale_y_sqrt(labels = scales::comma)
Themes describe a set of visual design choices made for the plot on things like the background, the gridlines, the axes, the tick marks, and the fonts.
Some ggplot2 themes (each one can be added as layer)
theme_gray(): the defaulttheme_bw()theme_minimal()
theme()will change defaults of the exiting theme, so add it last.

ev |>
ggplot(aes(x = State, y = Count)) +
geom_col(color = "blue") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 270,
hjust = 0,
vjust = 0.5),
plot.title = element_text(hjust = 0.5)) +
labs(title = "Electric Vehicle Registrations by State",
x = "",
y = "Registration Count") +
scale_y_sqrt(labels = scales::comma)
ev |>
ggplot(aes(x = State, y = Count)) +
geom_col(fill = "blue") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 270,
hjust = 0,
vjust = 0.5),
plot.title = element_text(hjust = 0.5)) +
labs(title = "Electric Vehicle Registrations by State",
x = "",
y = "Registration Count") +
scale_y_sqrt(labels = scales::comma)
ev |>
ggplot(aes(x = State, y = Count)) +
geom_col(fill = "steelblue") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 270,
hjust = 0,
vjust = 0.5),
plot.title = element_text(hjust = 0.5)) +
labs(title = "Electric Vehicle Registrations by State",
x = "",
y = "Registration Count") +
scale_y_sqrt(labels = scales::comma)
Audience: Residents and decisions makers in all fifty states.
My story: Just a few states account for most of the electrical vehicle registrations
My strategy: Display the registration counts in a manner that draws attention to the discrepancy between the highets and lowest states.
ev |>
ggplot(aes(x = State, y = Count)) +
geom_col(fill = "steelblue") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 270,
hjust = 0,
vjust = 0.5),
plot.title = element_text(hjust = 0.5)) +
labs(title = "Electric Vehicle Registrations by State",
x = "",
y = "Registration Count") +
scale_y_sqrt(labels = scales::comma)ev |>
mutate(State = fct_reorder(State, Count, .desc = TRUE)) |>
ggplot(aes(x = State, y = Count)) +
geom_col(fill = "steelblue") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 270,
hjust = 0,
vjust = 0.5),
plot.title = element_text(hjust = 0.5)) +
labs(title = "Electric Vehicle Registrations by State",
x = "",
y = "Registration Count") +
scale_y_sqrt(labels = scales::comma)ev |>
mutate(State = fct_reorder(State, Count, .desc = TRUE)) |>
ggplot(aes(x = State, y = Count)) +
geom_col(fill = "steelblue") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 270,
hjust = 0,
vjust = 0.5),
plot.title = element_text(hjust = 0.5)) +
labs(title = "Electric Vehicle Registrations by State",
x = "",
y = "Registration Count")


