Prostory vykreslování faset

Intermediate Data Visualization with ggplot2

Rick Scavetta

Founder, Scavetta Academy

Fasety a prostory vykreslování proměnných

Důvody pro nekonzistentní prostory vykreslování:

Typ proměnné Podmnožiny obsahují
Spojité Výrazně odlišné rozsahy
Kategorické Různé skupiny
Intermediate Data Visualization with ggplot2

Úprava prostoru vykreslování...

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

Intermediate Data Visualization with ggplot2

... ale ne s pevnými osami

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
Intermediate Data Visualization with ggplot2

Úprava prostoru vykreslování

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") 

Intermediate Data Visualization with ggplot2

Úprava prostoru vykreslování

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") 

Intermediate Data Visualization with ggplot2

Úprava prostoru vykreslování

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

Intermediate Data Visualization with ggplot2

Úprava prostoru vykreslování

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

Intermediate Data Visualization with ggplot2

Úprava prostoru vykreslování

ggplot(msleep2, aes(x = bodywt_log, 
                    y = name)) +
  geom_point() +
  # Free the y scales and space
  facet_grid(rows = vars(vore), 
             scales = "free_y")

Intermediate Data Visualization with ggplot2

Úprava prostoru vykreslování

ggplot(msleep2, aes(x = bodywt_log, 
                    y = name)) +
  geom_point() +
  # Free the y scales and space
  facet_grid(rows = vars(vore),
             scales = "free_y", 
             space = "free_y")

Intermediate Data Visualization with ggplot2

Závěrečné úpravy

msleep2 <- msleep2 %>% 
  # Arrange from lo to hi weight
  arrange(-bodywt_log) %>% 
  # Redefine factor levels in order
  mutate(name = as_factor(name)) 

# New order is reflected in y axis
ggplot(msleep2, aes(x = bodywt_log,
                    y = name)) +
  geom_point() +
  # Free the y scales and space
  facet_grid(rows = vars(vore),
             scales = "free_y", 
             space = "free_y")

Intermediate Data Visualization with ggplot2

Lass uns üben!

Intermediate Data Visualization with ggplot2

Preparing Video For Download...