테마 처음부터 만들기

ggplot2로 시작하는 데이터 시각화

Rick Scavetta

Founder, Scavetta Academy

테마 레이어

  • 모든 비데이터 잉크
  • 시각적 요소는 데이터의 일부가 아님
ggplot2로 시작하는 데이터 시각화

테마 레이어

  • 모든 비데이터 잉크
  • 시각적 요소는 데이터의 일부가 아님

세 가지 유형

유형
text
line
rectangle
ggplot2로 시작하는 데이터 시각화

테마 레이어

  • 모든 비데이터 잉크
  • 시각적 요소는 데이터의 일부가 아님

세 가지 유형

유형 사용 방법
text element_text()
line element_line()
rectangle element_rect()
ggplot2로 시작하는 데이터 시각화

시작 그래프...

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + 
  geom_jitter(alpha = 0.6)

ggplot2로 시작하는 데이터 시각화

텍스트 요소


text
  axis.title 
    axis.title.x
      axis.title.x.top
      axis.title.x.bottom 
    axis.title.y
      axis.title.y.left
      axis.title.y.right 
  title 
    legend.title 
    plot.title
    plot.subtitle 
    plot.caption 
    plot.tag
  axis.text 
    axis.text.x 
      axis.text.x.top
      axis.text.x.bottom 
    axis.text.y
      axis.text.y.left
      axis.text.y.right
  legend.text
  strip.text
    strip.text.x
    strip.text.y
ggplot2로 시작하는 데이터 시각화

텍스트 요소

theme(
text, 
  axis.title, 
    axis.title.x,
      axis.title.x.top, 
      axis.title.x.bottom, 
    axis.title.y, 
      axis.title.y.left,
      axis.title.y.right, 
  title, 
    legend.title, 
    plot.title,
    plot.subtitle, 
    plot.caption, 
    plot.tag, 
  axis.text, 
    axis.text.x, 
      axis.text.x.top,
      axis.text.x.bottom, 
    axis.text.y, 
      axis.text.y.left, 
      axis.text.y.right,
  legend.text,
  strip.text, 
    strip.text.x, 
    strip.text.y)
ggplot2로 시작하는 데이터 시각화

테마 요소 조정

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + 
  geom_jitter(alpha = 0.6) +
  theme(axis.title = element_text(color = "blue"))

ggplot2로 시작하는 데이터 시각화

시작 그래프...

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + 
  geom_jitter(alpha = 0.6)

ggplot2로 시작하는 데이터 시각화

선 요소

theme(
line,
  axis.ticks,
    axis.ticks.x, 
      axis.ticks.x.top,
      axis.ticks.x.bottom,
    axis.ticks.y,
      axis.ticks.y.left, 
      axis.ticks.y.right,
    axis.line,
      axis.line.x, 
        axis.line.x.top,
        axis.line.x.bottom, 
      axis.line.y,
        axis.line.y.left, 
        axis.line.y.right, 
  panel.grid,
    panel.grid.major, 
      panel.grid.major.x, 
      panel.grid.major.y, 
    panel.grid.minor,
      panel.grid.minor.x,
      panel.grid.minor.y)
ggplot2로 시작하는 데이터 시각화

시작 그래프...

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + 
  geom_jitter(alpha = 0.6)

ggplot2로 시작하는 데이터 시각화

사각형 요소

theme(
rect,
  legend.background, 
  legend.key,
  legend.box.background, 
  panel.background,
  panel.border,
  plot.background, 
  strip.background, 
    strip.background.x, 
    strip.background.y)
ggplot2로 시작하는 데이터 시각화

계층적 이름 지정은 상속 규칙을 반영한다

예: 텍스트

text
  axis.title 
    axis.title.x
      axis.title.x.top
      axis.title.x.bottom 
    axis.title.y
      axis.title.y.left
      axis.title.y.right 

예: 선

line
  axis.ticks
    axis.ticks.x 
      axis.ticks.x.top
      axis.ticks.x.bottom
    axis.ticks.y
      axis.ticks.y.left,
      axis.ticks.y.right
    axis.line
      axis.line.x 
        axis.line.x.top
        axis.line.x.bottom
      axis.line.y
        axis.line.y.left 
        axis.line.y.right
ggplot2로 시작하는 데이터 시각화

element_blank()

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + 
  geom_jitter(alpha = 0.6) + 
  theme(line = element_blank(),
        rect = element_blank(),
        text = element_blank())

ggplot2로 시작하는 데이터 시각화

연습해 봅시다!

ggplot2로 시작하는 데이터 시각화

Preparing Video For Download...