R Programming: ggforce package - Use geom_mark_hull to mark an area in geom_point
#rstats on Twitter has a lot of smart folks around. If you haven’t already, do follow @rfunctionaday. I’ve just started and you do come across ideas that catch your attention. One of them was the ggforce package that has a function called geom_mark_hull. Essentially, this creates a boundary around a group of points to drive attention.
In this example, let’s try to use this package for Google Analytics data containing device category. The part of the drill is the same with the API call via googleAnalyticsR. We have deviceCategory and month as dimensions and sessions, pageviewsPerSession as the metrics.
In the below chart, there are two visualizations, p and h.
p is a regular ggplot (geom_point scatter plot) where x = sessions, y = pageviewsPerSession and fill = deviceCategory. There are a few adjustments where I put a ylim to 3, removed the minor gridlines from the chart and removed alpha from the legend. Helped by: http://www.cookbook-r.com/Graphs/Axes_(ggplot2)/
With the ‘h’ plot, it’s the same plot with a hull around the points. In this example, I chose to mark it around the Desktop traffic. Hence, the code has filter=deviceCategory=='desktop'
in the code. There are a lot of options included in the documentation that you can use to specify the hull.