Visuals With R: Multiple Plots

Previously we produced a single plot based off an individual GPS export. In the majority of environments a single plot isn’t of huge value as we could be dealing with over 100 athletes in some environments. The goal of this post will be to outline how we can use facets to produce multiple plots in a quick and efficient manor. This is the plot as we currently know it:

Screenshot 2018-11-06 at 02.46.28

A single plot of a minute by minute breakdown from a game. We have covered analysing multiple raw data GPS exports previously using this script.

In the scenario where we have a low number of athletes to deal with using a basic facet approach where we add facet_grid with the id variable to discriminate between athletes to our plot script will work.

  • ggplot(Min_by_min, aes(factor(one_Min), TotalDist_Min, fill=TotalDist_Min))+
    geom_bar(stat = 'identity')+
    scale_y_continuous(breaks=seq(0,220,20))+
    scale_fill_gradient2(low='blue', mid='green', high='red', midpoint = 100, name='Meters Per Min')+
    labs(y = "Distance Covered Per Min (M/min)", x = "Match Minute")+
    ggtitle("Minute by Minute Breakdown of Distance Covered")+
    geom_text(aes(label=ifelse(TotalDist_Min>100, round(TotalDist_Min,0),'')))+
    theme_minimal()+
    facet_grid(id~.)+
    theme(
    axis.text.x = element_text(angle=90),
    plot.title = element_text(size=20, family = 'Garamond'),
    )
  • facet_grid(id~.)is saying to create a different plot facets using id to separate between plots, as it comes before the ~  (known as tilde), id will form the different rows of the facet. If it was after the ~, it would plot in columns. The . is saying we don’t want anything forming columns in the facets. We also have the option of having a variable after and before the ~ which would use one to create row and the other to create columns.
Screenshot 2018-11-06 at 13.39.15.png

As you can see, producing five separate plots from a raw data export is just as easy as creating a single plot, only a small line separates the two. Working with larger number of athletes can be slightly trickier as using facets can lead to very cramped plots but a similar result can be achieved through a combination of RMarkdown, LaTeX and ggplus, however this will be covered in the next few blogs as it will involve a number of topics.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Up ↑

%d bloggers like this: