Created
September 12, 2022 17:50
-
-
Save andrewheiss/a01092503b01438bb0a2d82af3aec738 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## ---- packages -------- | |
library(ggplot2) | |
library(dplyr) | |
library(ggtext) | |
## ---- createdata -------- | |
status_labels <- c("Healthy male, receiving Ω<sub>2</sub> treatment", | |
"Immunocompromised male, not receiving Ω<sub>2</sub> treatment", | |
"Healthy female: No \u2764 problems", | |
"Everyone else who doesn't fit into the other categories.") | |
set.seed(1234) | |
N = 100 #sample size | |
# made-up data | |
df <- data.frame(BMI = runif(N,15,50), | |
STATUS = as.factor(rbinom(N,3,prob=0.4)), | |
Y = rnorm(N,100,10) ) %>% | |
mutate(status_nice = factor(STATUS, labels = status_labels)) | |
ggplot(df) + geom_boxplot(aes(x = status_nice, y = Y)) + | |
geom_point(aes(x = status_nice, y = Y,color = BMI)) + | |
# str_wrap() doesn't play nicely with element_markdown() since it could | |
# potenitally add a line break in the middle of one of these HTML tags, so | |
# manually add <br> tags here | |
labs(x = "Patient status according to Ω<sub>2</sub> treatment,<br>\u2764-condition and other factors") + | |
labs(y = "Response after 21<sup>2</sup> days excluding<br>those days on which it didn't rain.") + | |
theme(axis.title.x = element_markdown(), | |
axis.title.y = element_markdown()) | |
# label_wrap() doesn't work with with element_markdown() things | |
ggplot(df) + geom_boxplot(aes(x = status_nice, y = Y)) + | |
geom_point(aes(x = status_nice, y = Y,color = BMI)) + | |
labs(x = "Patient status according to Ω<sub>2</sub> treatment,<br>\u2764-condition and other factors") + | |
labs(y = "Response after 21<sup>2</sup> days excluding<br>those days on which it didn't rain.") + | |
scale_x_discrete(labels = label_wrap(10)) + | |
theme(axis.title.x = element_markdown(), | |
axis.title.y = element_markdown()) | |
# so we have to add the <br>s manually in the variable labels | |
status_labels <- c("Healthy male,<br>receiving Ω<sub>2</sub><br>treatment", | |
"Immunocompromised<br>male, not receiving<br>Ω<sub>2</sub> treatment", | |
"Healthy female:<br>No \u2764<br>problems", | |
"Everyone<br>else who<br>doesn't fit<br>into the other<br>categories.") | |
df <- df %>% | |
mutate(status_nice = factor(STATUS, labels = status_labels)) | |
ggplot(df) + geom_boxplot(aes(x = status_nice, y = Y)) + | |
geom_point(aes(x = status_nice, y = Y,color = BMI)) + | |
labs(x = "Patient status according to Ω<sub>2</sub> treatment,<br>\u2764-condition and other factors") + | |
labs(y = "Response after 21<sup>2</sup> days excluding<br>those days on which it didn't rain.") + | |
theme(axis.title.x = element_markdown(), | |
axis.title.y = element_markdown(), | |
axis.text.x = element_markdown()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment