1. Learn
  2. /
  3. Courses
  4. /
  5. Helsinki Open Data Science

Connected

Exercise

So many plots

I imagine you're curious to find out how the distributions of some of the other variables in the data look like. Well, why don't we visualize all of them!

You'll also meet another new tidyverse toy, the pipe-operator: %>%.

The pipe (%>%) takes the result produced on it's left side and uses it as the first argument in the function on it's right side. Since the first argument of the tidyverse functions is usually data, this allows for some cool chaining of commands.

We'll look at %>% more closely in the next exercise. But now, let's draw some plots.

Instructions

100 XP
  • Access the tidyverse libraries tidyr, dplyr and ggplot2
  • Take a glimpse at the alc data
  • Apply the gather() function on alc and then take a glimpse at the resulting data directly after, utilizing the pipe (%>%). What does gather do?
  • Draw a plot of each variable in the alc data by first gathering the values into key-value pairs and then visualizing them with ggplot. Define the plots as bar plots by adding the element geom_bar(), (using +).