Exercise

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.

Instructions 1/4

undefined XP
    1
    2
    3
    4

Draw a bar plot with geom_bar().

  • Using mtcars_by_cyl, plot mean_wt versus cyl.
  • Add a bar layer, with stat set to "identity" an fill-color "skyblue".