demographic_venn <- tibble:: tibble (
column_name = c ("Age" , "Sex" ,
"Hypertension" , "Dyslipidemia" , "Family Hx CAD" , "Diabetes" ,
"Smoke Current" , "Smoke Past" ,
"Have Chest Pain" , "Chest Pain Character" ,
"Dyspnea" ,
"BMI" , "Height" , "Weight" ,
"HDL" , "Total Cholesterol" ,
"Triglyceride" , "LDL" ),
` Cohort A ` = c (1 , 1 ,
1 , 1 , 1 , 1 ,
1 , 1 ,
1 , 1 ,
1 ,
1 , 1 , 1 ,
0 , 0 ,
0 , 0 ),
` Cohort B ` = c (1 , 1 ,
1 , 1 , 1 , 1 ,
1 , 1 ,
1 , 1 ,
1 ,
0 , 0 , 0 ,
1 , 1 ,
1 , 1 ),
` Cohort C ` = c (1 , 1 ,
1 , 1 , 1 , 1 ,
1 , 1 ,
1 , 1 ,
1 ,
1 , 1 , 1 ,
1 , 1 ,
1 , 1 ),
` Cohort D ` = c (1 , 1 ,
1 , 1 , 1 , 1 ,
1 , 1 ,
1 , 1 ,
0 ,
1 , 0 , 0 ,
1 , 1 ,
1 , 1 ),
` Cohort E ` = c (1 , 1 ,
1 , 1 , 1 , 1 ,
1 , 1 ,
1 , 1 ,
0 ,
1 , 1 , 1 ,
1 , 1 ,
0 , 0 ),
` Cohort F ` = c (1 , 1 ,
1 , 1 , 1 , 1 ,
1 , 1 ,
1 , 1 ,
0 ,
1 , 1 , 1 ,
0 , 0 ,
0 , 0 ),
)
cohort_a_upset_col_name <- "Cohort A \n (n=1000)"
cohort_b_upset_col_name <- "Cohort B \n (n=2000)"
cohort_c_upset_col_name <- "Cohort C \n (n=1500)"
cohort_d_upset_col_name <- "Cohort D \n (n=500)"
cohort_e_upset_col_name <- "Cohort E \n (n=1000)"
cohort_f_upset_col_name <- "Cohort F \n (n=2500)"
demographic_upset_data <- demographic_venn |>
dplyr:: rename (
!! cohort_a_upset_col_name := "Cohort A" ,
!! cohort_b_upset_col_name := "Cohort B" ,
!! cohort_c_upset_col_name := "Cohort C" ,
!! cohort_d_upset_col_name := "Cohort D" ,
!! cohort_e_upset_col_name := "Cohort E" ,
!! cohort_f_upset_col_name := "Cohort F"
)
upset_plot <- ComplexUpset:: upset (
demographic_upset_data,
c (cohort_a_upset_col_name,
cohort_b_upset_col_name,
cohort_c_upset_col_name,
cohort_d_upset_col_name,
cohort_e_upset_col_name,
cohort_f_upset_col_name),
base_annotations = list (
` Intersection size ` =
ComplexUpset:: intersection_size (
text = list (size = 9 , nudge_y = 0.5 ),
text_colors = c (on_background= 'black' ,
on_bar= 'white' )
) +
ggplot2:: annotate (
size = 5.5 ,
geom = 'text' ,
x = Inf ,
y = Inf ,
label = paste ('Total:' , nrow (demographic_venn)),
vjust = 1 ,
hjust = 1
) +
ggplot2:: theme (
axis.title.y = ggplot2:: element_text (angle = 0 , size = 20 ),
axis.title.x = ggplot2:: element_text (angle = 0 , size = 20 ),
text = element_text (size = 20 )
) +
ggplot2:: labs (y = "" ,
title = "Intersection size" )
),
set_sizes = (
ComplexUpset:: upset_set_size () +
ggplot2:: geom_text (
size = 5.5 ,
mapping = ggplot2:: aes (label= ggplot2:: after_stat (.data[["count" ]])),
hjust = 1.5 ,
stat = 'count' ) +
ggplot2:: expand_limits (y = 30 ) +
ggplot2:: theme (
axis.title.y = ggplot2:: element_text (angle = 0 , size = 15 ),
axis.title.x = ggplot2:: element_text (angle = 0 , size = 15 ),
text = element_text (size = 15 )
) +
ggplot2:: labs (y = "Number of variables" )
),
sort_intersections_by = "degree" ,
sort_sets = FALSE ,
name = "" ,
width_ratio = 0.25 ,
themes = ComplexUpset:: upset_default_themes (text = element_text (size = 15 ))
)