I've run this code:
#setup
library(tidyverse)
library(skimr)
library(scales)
#import data
tuesdata <- tidytuesdayR::tt_load('2021-05-25')
records <- tuesdata$records
records_tt <- records %>%
mutate(track = factor(track),
type = factor(type))
#let's create a boxplot
records_tt %>%
ggplot(aes(x=record_duration, y=track, fill=type)) +
geom_boxplot(alpha=0.6) +
theme_minimal() +
scale_x_continuous(labels = comma) +
labs(x = "Record duration", y = "") +
theme(
axis.title.x = element_text(
margin = margin(t = 15)),
legend.title = element_blank())
Which gives me this plot:
I have three questions though:
- What is
ggplot
using to decide which level oftype
to place on the top (i.e. why is it currently plottingthree lap
on the top andsingle lap
on the bottom)? - How do I flip the order of the display, without changing the order of the legend keys (as it makes sense that single is listed on top of three)?
- How do I reorder the values of
track
from lowest mean value ofrecord_duration
(independent oftype
) to highest mean value, instead of the default reverse alphabetical which is currently displayed?