Em casos especiais, é possível não apenas obter distribuições normais de variáveis individuais, mas também distribuições normais bivariadas. Isso permite visualizar se a distribuição de ambas as variáveis também é aproximadamente normal, ou não. Para isso, usamos a função geom_bin2d()
:
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()`).
As distribuições normais bivariadas também podem ser representadas pela densidade usando a função stat_density_2d()
:
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()`).