Using ggplot2 to group x-axis discrete values into subgroups (CC133)

preview_player
Показать описание
When we group sets of variables into subgroups on the x-axis we signal to our audience that they need to compare the values within the grouping. But how do we do this with ggplot2? In this episode of Code Club, Pat will show how you can great four (!) layers of subgroups by using the ggplot2 facet_wrap function. At the end, we'll revisit our code and see how we can make it more DRY.

You can also find complete tutorials for learning R with the tidyverse using...

0:00 Introduction
1:58 Box and whisker plot
8:11 Changing order of training and testing data
9:10 Transition to point range plot
11:07 Creating multiple layers to x-axis labels with facet_wrap
16:53 Modifying y-axis range and label
17:34 Changing colors and legend labels
18:41 Add dashed horizontal line to indicate AUC for FIT alone
20:10 DRY: Replace repeated code with map_dfr
24:40 Recap
Рекомендации по теме
Комментарии
Автор

What other questions do you have about using facet_wrap?

Riffomonas
Автор

Thank you again, and it is a gem for students to have lectures like this from a Master.

niceday
Автор

I love your detailed tutorials. Maybe one day you'll have me as your Postdoc ;)
Id like to point out that in 6:25 you could rename your columns from the select function (which is not trivial since it's defined as selective, not operative), so the %>% rename is unnecessary...

djangoworldwide
Автор

Thank u for this Pat
Got an idea how to combine progress bars with list.files?

I got some directories on onedrive which have large and many files that take ages to read in as it automatically download them

ahmedJaber
Автор

Pat,
Again a very nice sequence of related videos. One thing I noticed in the weather data I used was there were were years that had few daily measurements. After some thinking about this I decided to figure out how to find the years with most missing days. I thought it might be helpful to others to share this so here is the code:

my_weather %>%
count(year = year(date)) %>%
ggplot(aes(x = year, y = n - 365)) +
geom_line()

And I found some "bad" years. Next I decide to extract those years with the day counts.

my_weather %>%
count(year = year(date)) %>%
arrange(n)

I had nine years with measurements less than 360. The most obvious were the terminal year (start and finish) which is not surprising. So what do we do? Toss those years? Or do set a mark of say no more than 20% missing? A better approach might be to do an running window functions such as those found in the slider packge and aggregate 2-3 days. Just a thought.

haraldurkarlsson
Автор

How the hell did you learn all of those details? :D

GaboEntropy
Автор

What about Rainbow parentheses @ pat ? :D
Again thank you wonderful inside of your process!

svenr
Автор

Lets say I have a 13 week trial split into a one-week run in phase and a 6 week supplement phase and a 6 week post supplement phase, is it possible to add additional titles on the x axis to indicate this

peterjackson
Автор

Hi Pat, will it be possible to label the x-axis labels with two different colors, say genus as grey and genus+fit as dodgerblue? I tried using element_text. However it seems element_text has some issues as its returns this error message, Vectorized "Warning message: input to `element_text()` is not officially supported. Results may be unexpected or may change in future versions of ggplot2".
Is there a way to circumvent this problem? I even tried the element markdown option. It also doesn't help much. Many thanks for your help.

KN-txsd
welcome to shbcf.ru