Visualização de Dados Intermediária com ggplot2
Rick Scavetta
Founder, Scavetta Academy
Motivos para não usar espaços consistentes de plotagem:
| Tipo de variável | Subconjuntos contêm |
|---|---|
| Contínua | Faixas muito diferentes |
| Categórica | Grupos diferentes |
ggplot(msleep2, aes(bodywt_log,
brainwt_log)) +
geom_point(alpha = 0.6, shape = 16) +
coord_fixed() +
facet_grid(rows = vars(vore),
cols = vars(conservation))

ggplot(msleep2, aes(bodywt_log,
brainwt_log)) +
geom_point(alpha = 0.6, shape = 16) +
coord_fixed() +
facet_grid(rows = vars(vore),
cols = vars(conservation),
scales = "free_x")
Error: coord_fixed doesn't support free scales
ggplot(msleep2, aes(bodywt_log,
brainwt_log)) +
geom_point(alpha = 0.6, shape = 16) +
facet_grid(rows = vars(vore),
cols = vars(conservation),
scales = "free_x")

ggplot(msleep2, aes(bodywt_log,
brainwt_log)) +
geom_point(alpha = 0.6, shape = 16) +
facet_grid(rows = vars(vore),
cols = vars(conservation),
scales = "free_y")

ggplot(msleep2, aes(bodywt_log,
brainwt_log)) +
geom_point(alpha = 0.6, shape = 16) +
facet_grid(rows = vars(vore),
cols = vars(conservation),
scales = "free")

ggplot(msleep2, aes(x = bodywt_log,
y = name)) +
geom_point() +
facet_grid(rows = vars(vore))

ggplot(msleep2, aes(x = bodywt_log,
y = name)) +
geom_point() +
# Liberar as escalas e o espaço em y
facet_grid(rows = vars(vore),
scales = "free_y")

ggplot(msleep2, aes(x = bodywt_log,
y = name)) +
geom_point() +
# Liberar as escalas e o espaço em y
facet_grid(rows = vars(vore),
scales = "free_y",
space = "free_y")

msleep2 <- msleep2 %>%
# Ordenar do maior para o menor peso
arrange(-bodywt_log) %>%
# Redefinir níveis do fator na ordem
mutate(name = as_factor(name))
# Nova ordem refletida no eixo y
ggplot(msleep2, aes(x = bodywt_log,
y = name)) +
geom_point() +
# Liberar as escalas e o espaço em y
facet_grid(rows = vars(vore),
scales = "free_y",
space = "free_y")

Visualização de Dados Intermediária com ggplot2