
To make this work, I initialise the reactiveVal() to a vector of FALSEs, then use brushedPoints() and | to add any points under the brush to the selection. Here I display the selection using different colours, but you could imagine many other applications. I want to use a brush to progressively add points to a selection. To find the correct range I did a little interactive experimentation, but you can work out the exact details if needed (see the exercises at the end of the chapter). I set the limits to scale_size_area() to ensure that sizes are comparable across clicks.I think it’s good practice to put related variables together in a data frame before visualising it. I add the distances to the data frame before plotting.There are two important ggplot2 techniques to note here:


Here I show the results of clicking on a point on the far left See live at. Figure 7.4: This app uses a reactiveVal() to store the distance to the point that was last clicked, which is then mapped to point size.
