1. Learn
  2. /
  3. Courses
  4. /
  5. Visualization Best Practices in R

Exercise

Making it rain (data points)

The increased bi-modality we see early in the week could be compelling, but we should draw individual points below the densities in order to get a sense of what the KDE is doing in terms of interpolation before calling it a day.

Added to the previous exercises' code is a point geometry to do just this. You will notice it doesn't look very good. To make it better we will do a few things…

First, lower the point alphas slightly to visualize overlap. Second, switch the point shape to the geom_rug() style vertical lines ('|').

At this stage, if you run the code you will see the points awkwardly clip the density shapes. We need to 'nudge' the tick marks down the y-axis a tiny bit. To do this we can use the position argument and the helper function position_nudge().

Instructions

100 XP
  • Lower alpha of the points to 0.2 to show overlap.
  • Change the line shape to '|' for more efficient space utilization.
  • Push points down so they don't overlap the density shape with position = position_nudge(y = -0.05).