How to create Multi-Panel plots in R with facet_wrap() and facet_grid()
ฝัง
- เผยแพร่เมื่อ 8 ก.ค. 2024
- In this video, I will show you how to use facet_wrap or facet_grid to create multi-panel plots in R and ggplot.
Faceting plots can be very helpful to compare your data over different categories.
It can also help you to get a quick overview of your data across multiple variables if you use a special pivot longer trick.
⏱ Time Stamps ⌚
0:00 - Intro
1:20 - gapminder example
5:09 - facet_wrap arguments
9:35 - facet_grid
13:54 - pivot_longer trick
22:02 - ggarrange
External Links:
www.r-bloggers.com/2018/03/di...
www.r-bloggers.acom/2023/02/s...
Great video! Keep going
Great in-depth video, excellent content.
Thanks for watching, liking and commenting :)
I wanted to include as much as possible without being to long or boring. Next video will be about pie charts.
This video is so useful. Thank you so much for sharing :) Appreciate the content and time.
And thank you for taking the time to leave such a nice comment. It is really motivating for me, to see that other people find my content useful :)
scale_x_reordered function seems useful
I have a question. How do u change the order of the desplay. The factet grid follows alphabetical order. But i need and special order. For example the order in min 7:09 its Africa, Americas, Asia, Europe. But what if u want Europe first?
You have to use the factor() function and provide a new order of the levels. For example like this:
gapminder$continent2
Just for transparency: I orginally used "labels" but it has to be "levels" otherwise the Africa data just got re-labeld with Europe instead of ordering the levels new.
I have a dedicated video about reordering factors: th-cam.com/video/ChhJUN1JDLI/w-d-xo.html
14:19 i still fail doing that chart 😅
What error message are you getting? Did you load the tidytext package to have the reorder_within() function available?
thanks for the video:)
btw dplyr::slice_ functions are nice
diamonds %>%
slice_sample(n = 5000)
Thanks for the feedback. Really great to have someone that posts some extra useful functions. I knew the slice() function and remember now using it in the past after arrange to only select the top 3 of something. But wasn't aware that there is slice_sample(). So thanks again :)