knitr::opts_chunk$set(echo = TRUE, warning = F)
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.5 v dplyr 1.0.7
## v tidyr 1.1.4 v stringr 1.4.0
## v readr 2.0.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(ggalluvial)
## Warning: package 'ggalluvial' was built under R version 4.1.2
Check out this package from some neat ideas: https://jokergoo.github.io/ComplexHeatmap-reference/book/
set.seed(1)
data <- data.frame(
protein = sample(c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"), 10, replace = TRUE),
a = sample(c("yes", "no"), 10, replace = TRUE),
b = sample(c("yes", "no"), 10, replace = TRUE)
)
#plot both
data %>%
mutate(alignment = if_else(a == b, "same", "different")) %>%
pivot_longer(a:b,
names_to = "test",
values_to = "value") %>%
ggplot(aes(x=protein, y=test)) +
geom_tile(aes(fill=value))
#alluvial plot
data %>%
group_by(a, b) %>%
summarise(count = n()) %>%
ggplot(aes(axis1 = a, axis2 = b,
y = count)) +
scale_x_discrete(limits = c("test a", "test b"), expand = c(.2, .05)) +
xlab("Test") +
geom_alluvium(fill = "red") +
geom_stratum() +
geom_text(stat = "stratum", aes(label = after_stat(stratum))) +
theme_minimal() +
ggtitle("Results by Test")
## `summarise()` has grouped output by 'a'. You can override using the `.groups` argument.