Teman från grunden

Introduktion till datavisualisering med ggplot2

Rick Scavetta

Founder, Scavetta Academy

Temanivån

  • All icke-databläck
  • Visuella element som inte ingår i datan
Introduktion till datavisualisering med ggplot2

Temanivån

  • All icke-databläck
  • Visuella element som inte ingår i datan

Tre typer

typ
text
line
rectangle
Introduktion till datavisualisering med ggplot2

Temanivån

  • All icke-databläck
  • Visuella element som inte ingår i datan

Tre typer

typ ändras med
text element_text()
line element_line()
rectangle element_rect()
Introduktion till datavisualisering med ggplot2

En startplot...

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

Introduktion till datavisualisering med ggplot2

Textelementen


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
Introduktion till datavisualisering med ggplot2

Textelementen

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)
Introduktion till datavisualisering med ggplot2

Justera temaelement

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

Introduktion till datavisualisering med ggplot2

En startplot...

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

Introduktion till datavisualisering med ggplot2

Linjeelement

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)
Introduktion till datavisualisering med ggplot2

En startplot...

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

Introduktion till datavisualisering med ggplot2

Rektangelelement

theme(
rect,
  legend.background, 
  legend.key,
  legend.box.background, 
  panel.background,
  panel.border,
  plot.background, 
  strip.background, 
    strip.background.x, 
    strip.background.y)
Introduktion till datavisualisering med ggplot2

Hierarkisk namngivning speglar arvsreglerna

t.ex. Text

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 

t.ex. Linjer

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
Introduktion till datavisualisering med 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())

Introduktion till datavisualisering med ggplot2

Nu kör vi en övning!

Introduktion till datavisualisering med ggplot2

Preparing Video For Download...