Aan de slagGa gratis aan de slag

Position in bar and col plots

Let's see how the position argument changes geom_bar().

We have three position options:

  • stack: The default
  • dodge: Preferred
  • fill: To show proportions

While we will be using geom_bar() here, note that the function geom_col() is just geom_bar() where both the position and stat arguments are set to "identity". It is used when we want the heights of the bars to represent the exact values in the data.

In this exercise, you'll draw the total count of cars having a given number of cylinders (fcyl), according to manual or automatic transmission type (fam).

Deze oefening maakt deel uit van de cursus

Introduction to Data Visualization with ggplot2

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Plot fcyl, filled by fam
___ +
  # Add a bar layer
  ___
Code bewerken en uitvoeren