用分面視覺化資料面向

在 Tidyverse 中以資料溝通

Timo Grossenbacher

Data Journalist

facet_grid() 函式

ilo_data <- ilo_data %>%
  filter(year == "1996" | year == "2006") 
ilo_plot <- ggplot(ilo_data) +
  geom_histogram(aes(
    x = working_hours)) +
  labs(x = "Working hours per week",
       y = "Number of countries")

ilo_plot +
  facet_grid(cols = vars(year))
ilo_plot +
  facet_grid(rows = vars(year))

在 Tidyverse 中以資料溝通

facet_grid() 函式

ilo_data <- ilo_data %>%
  filter(year == "1996" | year == "2006")
ggplot(ilo_data) +
  geom_histogram(aes(x = working_hours)) +
  labs(x = "Working hours per week",
       y = "Number of countries") +
  facet_grid(cols = vars(year))

ggplot(ilo_data) +
  geom_histogram(aes(x = working_hours)) +
  labs(x = "Working hours per week",
       y = "Number of countries") +
  facet_wrap(facets = vars(year))

在 Tidyverse 中以資料溝通

分面散佈圖

在 Tidyverse 中以資料溝通

分面圖樣式設計

strip.background
strip.text
...

在 Tidyverse 中以資料溝通

自訂主題函式

theme_green <- function(){
  theme(
    plot.background = 
      element_rect(fill = "green"),
    panel.background = 
      element_rect(fill = 
        "lightgreen")
  )}
ggplot(ilo_data) +
  geom_histogram(aes(
    x = working_hours)) +
  labs(x = "Working hours per week",
       y = "Number of countries") +

theme_green()

在 Tidyverse 中以資料溝通

一起來練習吧!

在 Tidyverse 中以資料溝通

Preparing Video For Download...