ggplot2로 하는 중급 데이터 시각화
Rick Scavetta
Founder, Scavetta Academy
일관된 도화 공간을 쓰지 않는 이유:
| 변수 유형 | 하위집합에 포함된 것 |
|---|---|
| 연속형 | 범위가 크게 다름 |
| 범주형 | 그룹이 서로 다름 |
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() +
# y 스케일과 공간을 자유롭게
facet_grid(rows = vars(vore),
scales = "free_y")

ggplot(msleep2, aes(x = bodywt_log,
y = name)) +
geom_point() +
# y 스케일과 공간을 자유롭게
facet_grid(rows = vars(vore),
scales = "free_y",
space = "free_y")

msleep2 <- msleep2 %>%
# 낮은 무게에서 높은 무게로 정렬
arrange(-bodywt_log) %>%
# 순서대로 요인 레벨 재정의
mutate(name = as_factor(name))
# 새 순서가 y축에 반영됨
ggplot(msleep2, aes(x = bodywt_log,
y = name)) +
geom_point() +
# y 스케일과 공간을 자유롭게
facet_grid(rows = vars(vore),
scales = "free_y",
space = "free_y")

ggplot2로 하는 중급 데이터 시각화