Exercise

Custom Functions

In the video we saw that the only difference between ggplot2::mean_sdl() and Hmisc::smean.sdl() is the naming convention. In order to use the results of a function directly in ggplot2 we need to ensure that the names of the variables match the aesthetics needed for our respective geoms.

Here we'll create two new functions in order to create the plot shown in the viewer. One function will measure the full range of the dataset and the other will measure the interquartile range.

A play vector, xx, has been created for you. Execute

mean_sdl(xx, mult = 1)

in the R Console and consider the format of the output. You'll have to produce functions which return similar outputs.

Instructions

100 XP

First, change the arguments ymin and ymax inside the data.frame() call of gg_range().

ymin should be the minimum of x

ymax should be the maximum of x

Use min() and max(). Watch out, naming is important here. gg_range(xx) should now generate the required output.