Aan de slagGa gratis aan de slag

Comparing lots of distributions

Let's revisit the faceted plot we made before, but now with our handy new techniques. Can we get a better handle on the relationships with our new plot types?

The supplied code makes the same visualization you did in the last lesson. Change the code to use violin plots to display the density instead of jitter plots to draw the individual data. Like in the last exercise, shrink the boxplot width so they mostly sit within the violin plots. Last, don't forget to add a subtitle to the plot telling the viewer the width of your violin plot kernels!

Deze oefening maakt deel uit van de cursus

Visualization Best Practices in R

Cursus bekijken

Oefeninstructies

  • Replace geom_jitter() with geom_violin().
  • Set fill = 'steelblue' and kernel standard deviation of 2.5 for the violin geometry.
  • Shrink geom_boxplot() width by setting it to 0.3.
  • Add the subtitle Gaussian kernel width: 2.5'.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

md_speeding %>% 
    ggplot(aes(x = gender, y = speed)) + 
    # replace with violin plot with kernel width of 2.5, change color argument to fill 
    geom_jitter(alpha = 0.3, color = 'steelblue') +
    # reduce width to 0.3
    geom_boxplot(alpha = 0) +
    facet_wrap(~vehicle_color) +
    labs(
        title = 'Speed of different car colors, separated by gender of driver'
        # add a subtitle w/ kernel width

    )
Code bewerken en uitvoeren