All posts
The HealthyR advent calendar is based on “R for Health Data Science” by Harrison and Pius. Use JKL20 for 20% off, including free worldwide shipping.
The HealthyR Advent Calendar 2022 was a series of 24 Tweets with R tips. They are all listed on this page, as well as categorised on the pages on this site.
Blue - plotting
Green - finalfit
Yellow - Statistics/Modelling
Red - RStudio and RMarkdown
Orange - Varia
More information about HealthyR, including the book and freely available resources can be found at: https://healthyr.surgicalinformatics.org/
🌟Day 01 - Summarising factors with finalfit🌟#HealthyR #rstats: excerpts from our "R for Health Data Science" book!
— Riinu Pius (@_Riinu_) December 1, 2022
Comment: when did you last use summary_factorlist()?
Any questions: @ewenharrison and myself happy to answer here!
Book chapter here: https://t.co/cM4DxhNfMW pic.twitter.com/ANaSYTC8qH
🌟Day 02 - Fitting logistic regression models with finalfit🌟#HealthyR #rstats: excerpts from our "R for Health Data Science" book!
— Riinu Pius (@_Riinu_) December 2, 2022
Comment: when did you last use finalfit()?
Any questions: @ewenharrison and myself happy to answer here!
Freely avail.: https://t.co/J2VRF7CKfb pic.twitter.com/y6sWVrtyZa
🌟Day 03 - Kaplan Meier plot (survival)🌟#HealthyR #rstats: excerpts from our "R for Health Data Science" book!
— Riinu Pius (@_Riinu_) December 3, 2022
What's on your survival plots?
Any questions: @ewenharrison and myself happy to answer here!
Freely available: https://t.co/IWpXceWxcY pic.twitter.com/eBBIJhvqXT
🌟Day 04 - Reading data into R🌟#HealthyR #rstats
— Riinu Pius (@_Riinu_) December 4, 2022
1⃣ New Project – New directory
2⃣ Move data into this new folder
3⃣ Click on file and let the import interface help you
Any questions: @ewenharrison and myself happy to answer here!
Freely available: https://t.co/Eb4XoRAQ2h pic.twitter.com/MB4lrUVbTI
🌟 Day 05 – Plotting continuous (numeric) data🌟
— Riinu Pius (@_Riinu_) December 5, 2022
Can't go wrong with a histogram or box plot. Overlay the latter with actual data points if can!
Any questions happy to answer! @ewenharrison#HealthyR #rstats: "R for Health Data Science" 📖 chapter:https://t.co/oSVOORfGKt pic.twitter.com/LyzMa9OGaU
🌟 Day 06 – Legend position🌟
— Riinu Pius (@_Riinu_) December 6, 2022
You've got options: left, right, top, bottom, or none!
Or use relative coordinates:
legend.position = c(0.85, 0.1)
Any questions happy to answer!@ewenharrison#HealthyR #rstats: "R for Health Data Science" book chapter:https://t.co/At0O9K1kF2 pic.twitter.com/GOuBRZtal7
🌟 Day 07 – Legend columns🌟
— Riinu Pius (@_Riinu_) December 7, 2022
A minor change but can be useful if you're squeezed for space!
Any questions: @ewenharrison and myself happy to answer here!#HealthyR #rstats: "R for Health Data Science" book chapter:https://t.co/At0O9K1kF2 pic.twitter.com/nSh9IUGr38
🌟 Day 08 – Combine plots with patchwork🌟
— Riinu Pius (@_Riinu_) December 8, 2022
1️⃣Save your plots into objects (e.g., p1, p2)
2️⃣library(patchwork): https://t.co/WP2AM2G2uS
3️⃣combine with just +, or try | () / for various layouts#HealthyR #rstats: "R for Health Data Science" book chapter:https://t.co/dssBc63Kzv pic.twitter.com/mlf2bpfdIL
🌟Day 09 – Bar plots: geom_bar() or geom_col()?!?🌟
— Riinu Pius (@_Riinu_) December 9, 2022
📊Use geom_bar to count up (patient-level) data
📊Use geom_col for summarised data - if you have a numeric y
Or if one doesn’t work try the other 😜#HealthyR #rstats "R for Health Data Science":https://t.co/X5ix6Xge1H pic.twitter.com/PkXwhyUEU6
🌟Day 10 – Set a theme for all your plots🌟
— Riinu Pius (@_Riinu_) December 10, 2022
Today’s #HealthyR #rstats tip is short and sweet:
theme_set(theme_bw())
at the top of your script will apply on everything you make!
This and more freely available in “R for Health Data Science” 📖: https://t.co/vaQJC6J7aG pic.twitter.com/msV0bOM60b
🌟Day 11 – fct_reorder() + ggplot() = 💙🌟
— Riinu Pius (@_Riinu_) December 11, 2022
Use fct_reorder() to get Y-axis countries ordered by another variable - cool plot with just a couple of lines of code 🙌📈
“R for Health Data Science” 📖#HealthyR #rstats:https://t.co/18s80BnoLn pic.twitter.com/W5WGNJZkZU
🌟Day 12 – recoding factors 🌟
— Riinu Pius (@_Riinu_) December 12, 2022
Two rules of handling factors:
😻use library(forcats): https://t.co/V2S1cEcl7W
📊always plot before and after to double check
“R for Health Data Science” #HealthyR #rstats 📖:https://t.co/NnV8h0x3Ks pic.twitter.com/XCESIJwH5I
🌟Day 13 – tidyverse MVP: count()🌟
— Riinu Pius (@_Riinu_) December 13, 2022
Frequency table in a tidy format?
That’s what the count() function does. Add sort = TRUE to order the output by n (instead of
factor order or alphabetically)
“R for Health Data Science” #HealthyR #rstats:https://t.co/9JCgLDFK13 pic.twitter.com/47UKCERIed
🌟Day 14 – when R can’t maths🌟
— Riinu Pius (@_Riinu_) December 14, 2022
Computers don't think that 0.10 + 0.05 = 0.15
This can blindside people who usually deal with categorical variables 🙈
General explanation at: https://t.co/XPApo7a1fD
“R for Health Data Science” #HealthyR #rstats📖:https://t.co/9JCgLDFcbv pic.twitter.com/V3gIMJY88O
🌟Day 15 – Understanding linear regression🌟
— Riinu Pius (@_Riinu_) December 15, 2022
Real talk - first step to understanding logistic regression is understanding linear regression. So please have a 👀 and 🧠 even if your data needs log./Cox.#HealthyR #rstats "R for Health Data Science" 📖:https://t.co/bTtHk2WUVZ pic.twitter.com/qWj5upbEG6
🌟Day 16 – Understanding logistic regression🌟
— Riinu Pius (@_Riinu_) December 16, 2022
Dependent (=outcome): adverse event (Yes/No)
Explanatory variables:
cups of ☕ (n); 🚬 (Yes/No)
(made-up data)
Weekend posts will be lighter, promise 🧠#HealthyR #rstats "R for Health Data Science" 📖:https://t.co/yNPlXNAdZ7 pic.twitter.com/Y6gOoz6cuv
🌟Day 17 – Understanding R Markdown🌟
— Riinu Pius (@_Riinu_) December 17, 2022
Header📍
Headings🗂
Text📝
Inline code - code inside text💙
Code chunk💙
Output (in this example it's a plot)📈#HealthyR #rstats "R for Health Data Science" 📖:https://t.co/hUFCXLx7Jf pic.twitter.com/cxUBouEEiM
🌟Day 18 - RStudio interface for R Markdown🌟
— Riinu Pius (@_Riinu_) December 18, 2022
Lots of useful buttons and options 🙈
Here are the most useful ones 💡#HealthyR #rstats "R for Health Data Science" 📖:https://t.co/KKSqQ5sqCK pic.twitter.com/Cx3iuN3INN
🌟Day 19 - Restart R regularly🌟
— Riinu Pius (@_Riinu_) December 19, 2022
Do this now so that old data won't come back to haunt you:
👻Tools -> Global Options
👻👻Uncheck restore
👻👻👻Never save on exit
Then save and load objects consciously!#HealthyR #rstats "R for Health Data Science"📖:https://t.co/LaWufbGb8J pic.twitter.com/31cQCNQghH
🌟Day 20 - We're just trying to find a model that best describes the data🌟
— Riinu Pius (@_Riinu_) December 20, 2022
Same made-up data on each plot:
A univariable
B, C multivariable
Note the R-squared 😉#HealthyR #rstats "R for Health Data Science"📖 chapter:https://t.co/bTtHk2WUVZ pic.twitter.com/jb1RynvE39
🌟Day 21 - confounding🌟
— Riinu Pius (@_Riinu_) December 21, 2022
Same made-up data on both plots.
A - coffee seems to have an effect on blood pressure
B - except that it was completely confounded in heavy coffee drinkers also smoking #HealthyR #rstats "R for Health Data Science"📖 :https://t.co/bTtHk2Fjxp pic.twitter.com/Fg7sMZGGZd
🌟Day 22 - #HealthyR #rstats Season's Greetings, Part 1/3🌟
— Riinu Pius (@_Riinu_) December 22, 2022
That's enough regression for this year!
Execute this code in your head or an IDE, further instalments coming on the remaining days of our Advent Calendar 2022 🎄https://t.co/vNmRmb6QrC pic.twitter.com/tK9S9MBJNj
🌟Day 23 - #HealthyR #rstats Season's Greetings, Part 2/3🌟
— Riinu Pius (@_Riinu_) December 23, 2022
Note the two different ways of creating data - tibble and tribble. This is useful if you need to make a reproducible example!
Anyone want to guess what tomorrow's single additional line is?https://t.co/46h6uHPCvL pic.twitter.com/kOfXIMdy2s
🌟Day 24 - Season's Greetings, Part 3/3🌟
— Riinu Pius (@_Riinu_) December 24, 2022
+ scale_fill_identity()
I use scale_fill_brewer() or scale_fill_manual() more, but this works well here 🎄
That's the #HealthyR #rstats Advent Calendar! Thank you for thinking along and happy holidays!https://t.co/XtbZe0vGI7 pic.twitter.com/aLcaN6iJuj
HealthyR: R for Health Data Science book and resources: https://healthyr.surgicalinformatics.org/