IniziaInizia gratis

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).

Questo esercizio fa parte del corso

Introduction to Data Visualization with ggplot2

Visualizza il corso

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# Plot fcyl, filled by fam
___ +
  # Add a bar layer
  ___
Modifica ed esegui il codice