LoslegenKostenlos loslegen

Bar plots: dynamite plots

In the video we saw many reasons why "dynamite plots" (bar plots with error bars) are not well suited for their intended purpose of depicting distributions. If you really want error bars on bar plots, you can of course get them, but you'll need to set the positions manually. A point geom will typically serve you much better.

Nonetheless, you should know how to handle these kinds of plots, so let's give it a try.

Diese Übung ist Teil des Kurses

Intermediate Data Visualization with ggplot2

Kurs anzeigen

Anleitung zur Übung

  • Using mtcars,, plot wt versus fcyl.
  • Add a bar summary stat, aggregating the wts by their mean, filling the bars in a skyblue color.
  • Add an errorbar summary stat, aggregating the wts by mean_sdl.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Plot wt vs. fcyl
ggplot(mtcars, aes(x = ___, y = ___)) +
  # Add a bar summary stat of means, colored skyblue
  stat_summary(fun = ___, geom = "___", fill = "___") +
  # Add an errorbar summary stat std deviation limits
  stat_summary(fun.data = ___, fun.args = list(mult = 1), geom = "___", width = 0.1)
Code bearbeiten und ausführen