Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color intersections matrix and bars by degree #204

Open
lemoles opened this issue Aug 22, 2024 · 0 comments
Open

Color intersections matrix and bars by degree #204

lemoles opened this issue Aug 22, 2024 · 0 comments
Labels
help-request User requested help with the package

Comments

@lemoles
Copy link

lemoles commented Aug 22, 2024

Objective
Looking for an easy/simple way to colour intersections matrix and bars by degree. I have tried some approaches from previous issues, and could only manage to get intersections coloured. However, still struggling to have the bars coloured and ordered. I am providing a piece of my data set, and what I could achieve. Thank you in advance.

Code

query_by_degree = function(data, groups, params_by_degree, ...) {
  intersections = unique(upset_data(data, groups)$plot_intersections_subset)
  lapply(
    intersections,
    FUN=function(x) {
      members = strsplit(x, "-", fixed=TRUE)[[1]]
      args = c(
        list(intersect=members, ...),
        params_by_degree[[length(members)]]
      )
      do.call(upset_query, args)
    }
  )
}






gesta_data <- data %>% 
  select(gesta_aro, gesta_avafetal, 
         gesta_bcardiofetais, gesta_auterina, gesta_fouranc, gesta_twelve) 

sets_gesta <- c("gesta_aro","gesta_avafetal","gesta_bcardiofetais","gesta_auterina","gesta_fouranc","gesta_twelve")


upset(gesta_data,
      sets_gesta,
      name = "",
      width_ratio=0.1,
      min_size = 1, # minimum intersection size
      min_degree = 1,
      sort_intersections_by = c("degree","cardinality"),
      sort_intersections= "descending",
      labeller = as_labeller(c("gesta_aro" = "Evaluation of obstetric risk",
                               "gesta_avafetal" = "Evaluation of fetal presentation",
                               "gesta_bcardiofetais" = "Evaluation of fetal heart rate",
                               "gesta_auterina" = "Evaluation of uterine height",
                               "gesta_fouranc" = "Completed at least four antenatal care visits",
                               "gesta_twelve" = "First antenatal care within 12 weeks")),
      
      themes = upset_modify_themes(list( "intersections_matrix" = theme(text=element_text(size = 17,
                                                                                          color = "black")),
                                         "overall_sizes" = theme(text = element_text(size = 17,
                                                                                     color = "black")))),
      queries = query_by_degree(gesta_data, 
                                sets_gesta,
                                params_by_degree=list(
                                  "1"=list(color="red", fill="red"),
                                  "2"=list(color="red", fill="red"),
                                  "3"=list(color="red", fill="red"),
                                  "4"=list(color="yellow", fill="yellow"),
                                  "5"=list(color="darkgreen", fill="darkgreen"),
                                  "6"=list(color="darkgreen", fill="darkgreen")),
                                only_components=c("intersections_matrix", "Intersection size")),
      base_annotations = list("Intersection ratio" = 
                                intersection_ratio(text = list(size = 3.75),
                                                   bar_number_threshold = 1,
                                                   text_colors =c(on_background="black", on_bar="white"),
                                                   text_mapping=aes(label=!!upset_text_percentage(digits = 1))) +
                                ylab("Percent") +
                                theme(axis.text.y = element_text(color="black", 
                                                                 size = 13),
                                      axis.title.y = element_text(color="black",
                                                                  size = 13)) +
                                scale_y_continuous(labels=scales::percent_format(),
                                                   limits = c(0, 0.9),
                                                   breaks=seq(from = 0,
                                                              to = 1,
                                                              by = 0.15))),
      
      set_sizes = FALSE)

Screenshot or illustration
Screenshot 2024-08-22 110051

gesta_data.xlsx

Context (required)

ComplexUpset version: 1.3.3

R version details
4.3.3 
R session information
R version 4.3.3 (2024-02-29 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22631)
@lemoles lemoles added the help-request User requested help with the package label Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help-request User requested help with the package
Projects
None yet
Development

No branches or pull requests

1 participant