In special cases, it is possible to not only output normal distributions of individual variables but also bivariate normal distributions. This allows us to visualize whether the distribution of both variables is also approximately normally distributed or not. To do this, we use the geom_bin2d()
function:
ggplot(
pss,
aes(
trstplt,
trstlgl
)
) +
geom_bin2d(binwidth = 1) +
scale_fill_continuous(
low = "lavenderblush",
high = "red"
)
## Warning: Removed 23 rows containing non-finite outside the scale range
## (`stat_bin2d()`).
Bivariate normal distributions can also be represented through density using the stat_density_2d()
function:
ggplot(
pss,
aes(
trstplt,
trstlgl
)
) +
stat_density_2d(
aes(fill = ..level..),
geom = "polygon"
) +
scale_fill_continuous(
low = "lavenderblush",
high = "red"
)
## Warning: The dot-dot notation (`..level..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(level)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: Removed 23 rows containing non-finite outside the scale range
## (`stat_density2d()`).