Exercise

Step 2: Historical data

Let's develop the first layer to show the historical data called stat_historical(). Like before, you'll create a stats layer starts by creating a stats object with ggproto(), and then you'll create a function where you'll define a number of layers.

To do this properly, you are going to define a new aesthetic inside ggproto(). This will be called "year", and you can map the variable year from your dataset onto this aesthetic. You'll see in a bit that this a very elegant solution.

Instructions

100xp

Finish the definition of StatHistorical:

The first argument of ggproto() is the 'class name'; set it to "StatHistorical".

The compute_group() function takes three arguments: data, scales and params

The required aesthetics are "x", "y" and "year".

Inside the definition stat_historical:

Set the default geom to "point" in the function definition.

Have the first layer inherit this default geom: geom = geom

Make the default geom for the second layer: geom = "linerange".

In the second layer, use the stat StatHistorical, that you've just defined - quotes are not necessary here!