Bune practici: diagrame cu bare

Vizualizare intermediară a datelor cu ggplot2

Rick Scavetta

Founder, Scavetta Academy

În acest capitol

  • Capcane frecvente în vizualizarea datelor
  • Cea mai bună reprezentare a datelor
    • Pentru grafice explicative (comunicare) eficiente și
    • Pentru grafice exploratorii (investigare) eficiente
Vizualizare intermediară a datelor cu ggplot2

Diagrame cu bare

  • Două tipuri
    • Valori absolute
    • Distribuții
Vizualizare intermediară a datelor cu ggplot2

Somnul mamiferelor

Observations: 76
Variables: 3
$ vore  <chr> "carni", "omni", "herbi", "omni", "herbi", "herbi", "carni", …
$ total <dbl> 12.1, 17.0, 14.4, 14.9, 4.0, 14.4, 8.7, 10.1, 3.0, 5.3, 9.4, …
$ rem   <dbl> NA, 1.8, 2.4, 2.3, 0.7, 2.2, 1.4, 2.9, NA, 0.6, 0.8, 0.7, 1.5…
Vizualizare intermediară a datelor cu ggplot2

Grafic dinamită

d <- ggplot(sleep, aes(vore, total)) +
 # ...

d + 
  stat_summary(fun = mean,
               geom = "bar",
               fill = "grey50") +
  stat_summary(fun.data = mean_sdl,
               fun.args = list(mult = 1),
               geom = "errorbar", 
               width = 0.2)

Vizualizare intermediară a datelor cu ggplot2

Puncte de date individuale

# position
posn_j <- position_jitter(width = 0.2)

# plot
d +
  geom_point(alpha = 0.6, 
             position = posn_j)

Vizualizare intermediară a datelor cu ggplot2

geom_errorbar()

d +
  geom_point(...) +
  stat_summary(fun = mean, 
               geom = "point", 
               fill = "red") +
  stat_summary(fun.data = mean_sdl, 
               fun.args = list(mult = 1), 
               geom = "errorbar", 
               width = 0.2, 
               color = "red")

Vizualizare intermediară a datelor cu ggplot2

geom_pointrange()

d +
  geom_point(...) +
  stat_summary(fun.data = mean_sdl, 
               mult = 1, 
               width = 0.2, 
               color = "red")

Vizualizare intermediară a datelor cu ggplot2

Fără puncte de date

d +
  stat_summary(fun = mean, 
               geom = "point") +
  stat_summary(fun.data = mean_sdl, 
               fun.args = list(mult = 1), 
               geom = "errorbar", 
               width = 0.2)

Vizualizare intermediară a datelor cu ggplot2

Barele nu sunt necesare

Vizualizare intermediară a datelor cu ggplot2

Pregătit pentru exerciții!

Vizualizare intermediară a datelor cu ggplot2

Preparing Video For Download...