Created
April 5, 2021 17:10
-
-
Save IndrajeetPatil/7acbc7bc2f579027d12468d38185a506 to your computer and use it in GitHub Desktop.
code for tweet about counts and percentages: https://twitter.com/patilindrajeets/status/1379114056590708736?s=20
This file contains 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
# code for this tweet: | |
# https://twitter.com/patilindrajeets/status/1379114056590708736?s=20 | |
library(ggstatsplot) | |
library(gginnards) | |
df <- | |
data.frame( | |
"time-1" = c("Disease", "Disease", "No Disease", "Disease", "Disease"), | |
"time-2" = c("Disease", "Disease", "No Disease", "No Disease", "No Disease") | |
) %>% | |
tidyr::gather(key = "measurement", value = "status") | |
p1 <- ggbarstats(df, | |
status, | |
measurement, | |
results.subtitle = FALSE, | |
ggtheme = hrbrthemes::theme_ipsum_tw(), | |
proportion.test = FALSE, | |
subtitle = "what looks like a big change in terms of percentage..." | |
) | |
p1 <- delete_layers(p1, "GeomText") | |
p2 <- ggbarstats(df, | |
status, | |
measurement, | |
results.subtitle = FALSE, | |
proportion.test = FALSE, | |
ggtheme = hrbrthemes::theme_ipsum_tw(), | |
label = "both", | |
subtitle = "might not be so if you also look at raw counts" | |
) | |
p2 <- delete_layers(p2, "GeomText") | |
library(patchwork) | |
library(ggplot2) | |
p <- p1 + p2 + plot_layout(guides = "collect") & theme(legend.position = "bottom") | |
ggsave("n_perc.png", p, | |
width = 8, | |
height = 5 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment