Focus your Story
Features
Common Exploratory Questions
View() in PositronFeatures
Common Exploratory 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.
titlesubtitlecolorfillsizeshapelabs()An alternative method uses a separate layer for each label.
ggtitle()xlab()ylab(). . . I recommend you just use
labs().
Compares 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
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()ggplot themes can be stored inside packages.
ggthemes::theme_economist()
ggthemes::theme_fivethirtyeight()
ggthemes::theme_solarized()
ggthemes::theme_excel()
Write the ggplot2 code that has generated the following plot.
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(axis.text.x = element_text(angle = 270, hjust = 0, : 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")


