CommencerCommencer gratuitement

Bar plots: Using aggregated data

If it is appropriate to use bar plots (see the video!), then it nice to give an impression of the number of values in each group.

stat_summary() doesn't keep track of the count. stat_sum() does (that's the whole point), but it's difficult to access. It's more straightforward to calculate exactly what we want to plot ourselves.

Here, we've created a summary data frame called mtcars_by_cyl which contains the average (mean_wt), standard deviations (sd_wt) and count (n_wt) of car weights, for each cylinder group, cyl. It also contains the proportion (prop) of each cylinder represented in the entire dataset. Use the console to familiarize yourself with the mtcars_by_cyl data frame.

Cet exercice fait partie du cours

Intermediate Data Visualization with ggplot2

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Using mtcars_cyl, plot mean_wt vs. cyl
___ +
  # Add a bar layer with identity stat, filled skyblue
  ___
Modifier et exécuter le code