2025-02-23
Visualize these five values: 1, 3.16, 10, 31.6, 100
A linear scale emphasizes large counties
A log scale shows symmetry around the median
The boxoffice
dataset:
The temperatures
and temps_wide
datasets (long and wide format of the same data):
# long format
temperatures <- read_csv("https://wilkelab.org/SDS366/datasets/tempnormals.csv") |>
mutate(
location = factor(
location, levels = c("Death Valley", "Houston", "San Diego", "Chicago")
)
) |>
select(location, station_id, day_of_year, month, temperature)
# wide format
temps_wide <- temperatures |>
pivot_wider(
id_cols = c("month", "day_of_year"),
names_from = "location", values_from = "temperature"
)
Recall the box-office example from a prior lecture:
Add scale functions (no change in figure so far):
The parameter name
sets the axis title:
Note: We could do the same with xlab()
and ylab()
The parameter limits
sets the scale limits:
Note: We could do the same with xlim()
and ylim()
but I advise against it, as these functions can have unexpected side-effects
The parameter breaks
sets the axis tick positions:
The parameter labels
sets the axis tick labels:
The parameter expand
sets the axis expansion:
Linear y scale:
coord_fixed()
for fixed aspect ratio(Bad, x and y axis show the same values scaled differently)
coord_fixed()
for fixed aspect ratio(Better, x and y axis are now scaled the same)
coord_fixed()
for fixed aspect ratio(Even better, similar axis ticks along both axes)