การแสดงข้อมูลด้วย Facets

การสื่อสารด้วยข้อมูลใน 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

Scatter plot แบบ Facet

การสื่อสารด้วยข้อมูลใน Tidyverse

การปรับสไตล์กราฟแบบ Facet

strip.background
strip.text
...

การสื่อสารด้วยข้อมูลใน Tidyverse

การสร้างฟังก์ชัน Theme ของตัวเอง

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...