Lecture 05
Cornell University
INFO 3312/5312 - Fall 2026
September 8, 2026
Source: /u/XanderDorn
stat_*() functions from {ggplot2}# A tibble: 174 × 8
iso2c country year gdp_per_cap female_labor_pct life_exp pop income_level
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <fct>
1 AF Afghanistan 2023 414. 6.85 66.0 41454761 Low income
2 AO Angola 2023 2916. 49.4 64.6 36749906 Lower middle inc…
3 AL Albania 2023 9731. 46.4 79.6 2414095 Upper middle inc…
4 AE United Arab Emirates 2023 49851. 22.3 82.9 10483751 High income
5 AR Argentina 2023 14262. 43.2 77.4 45538401 Upper middle inc…
6 AM Armenia 2023 8159. 47.2 77.5 2964300 Upper middle inc…
7 AU Australia 2023 65058. 47.4 83.1 26659922 High income
8 AT Austria 2023 56580. 46.9 81.5 9131761 High income
9 AZ Azerbaijan 2023 7133. 49.9 74.4 10153958 Upper middle inc…
10 BI Burundi 2023 251. 51.6 63.7 13689450 Low income
# ℹ 164 more rows
stat |
geom |
|---|---|
stat_bin() |
geom_bar(), geom_freqpoly(), geom_histogram() |
stat_bin2d() |
geom_bin2d() |
stat_bindot() |
geom_dotplot() |
stat_binhex() |
geom_hex() |
stat_boxplot() |
geom_boxplot() |
stat_contour() |
geom_contour() |
stat_quantile() |
geom_quantile() |
stat_smooth() |
geom_smooth() |
stat_sum() |
geom_count() |
stat_boxplot()Each scale is a function from a region in data space (the domain of the scale) to a region in aesthetic space (the range of the scale)
The axis or legend (also known as a guide) is the inverse function: it allows you to convert visual properties back to data
Scales should be designed in a manner that makes it easy for the viewer to interpret the data
Every aesthetic in your plot is associated with exactly one scale:

scale_<aes>_<type>()
scale<aes>: Name of the primary aesthetic (e.g., color, shape, x)<type>: Name of the scale (e.g., continuous, discrete, brewer)When working with continuous data, the default is to map linearly from the data space onto the aesthetic space, but this scale can be transformed








| Name | Function \(f(x)\) | Inverse \(f^{-1}(y)\) |
|---|---|---|
| asn | \(\tanh^{-1}(x)\) | \(\tanh(y)\) |
| exp | \(e ^ x\) | \(\log(y)\) |
| identity | \(x\) | \(y\) |
| log | \(\log(x)\) | \(e ^ y\) |
| log10 | \(\log_{10}(x)\) | \(10 ^ y\) |
| log2 | \(\log_2(x)\) | \(2 ^ y\) |
| logit | \(\log(\frac{x}{1 - x})\) | \(\frac{1}{1 + e(y)}\) |
| pow10 | \(10^x\) | \(\log_{10}(y)\) |
| probit | \(\Phi(x)\) | \(\Phi^{-1}(y)\) |
| reciprocal | \(x^{-1}\) | \(y^{-1}\) |
| reverse | \(-x\) | \(-y\) |
| sqrt | \(x^{1/2}\) | \(y ^ 2\) |
04:00
What will the x-axis label of the following plot say?
Scale for x is already present.
Adding another scale for x, which will replace the existing scale.

Source: Spurious Correlations
Source: Spurious Correlations
02:00
Guides are axes and legends
Source: ggplot2-book Chp 14.
Why do 50 and 90 not appear on the \(y\)-axis?
ggplot(world_bank, aes(x = gdp_per_cap, y = life_exp)) +
geom_point(alpha = 0.5) +
scale_y_continuous(
name = "Life expectancy at birth",
breaks = seq(from = 50, to = 90, by = 10),
limits = c(50, 90)
) +
scale_x_continuous(
name = "GDP per capita",
breaks = c(0, 5e04, 1e05),
labels = c("$0", "$50,000", "$100,000")
)
ggplot(world_bank, aes(x = gdp_per_cap, y = life_exp)) +
geom_point(alpha = 0.5) +
scale_y_continuous(
name = "Life expectancy at birth",
breaks = seq(from = 50, to = 90, by = 10),
limits = c(50, 90)
) +
scale_x_continuous(
name = "GDP per capita",
labels = label_currency(scale_cut = cut_short_scale())
)
| Scale type | Default guide type | Function |
|---|---|---|
| Continuous scales for color/fill aesthetics | colorbar | guide_colorbar() |
| Binned scales for color/fill aesthetics | colorsteps | guide_colorsteps() |
| Position scales (continuous, binned and discrete) | axis | guide_axis() |
| Discrete scales (except position scales) | legend | guide_legend() |
| Binned scales (except position/color/fill scales) | bins | guide_bins() |
Instructions
Identify improvements to the scales and guides for the following plot. Explain why they would improve the interpretability of the chart.
10:00
guide_*() functions to customize the appearance of guides