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

Cannot add manual legend to heatmap annotation #1184

Open
katimbach opened this issue May 23, 2024 · 0 comments
Open

Cannot add manual legend to heatmap annotation #1184

katimbach opened this issue May 23, 2024 · 0 comments

Comments

@katimbach
Copy link

Please provide example datasets and the code you use. It will help me to understand your problem and help you!

I have made a HeatmapAnnotation with the following code, that I show below:
hm<- HeatmapAnnotation(Patient= anno_simple(info_tbl$PATIENT, pch=info_tbl$SLICE_TYPE_SYMBOL, col = patient_cols), Location= info_tbl$LOCATION_SIMPLE, Tissue= info_tbl$TYPE_OF_TISSUE, BRCAstatus= anno_simple(info_tbl$BRCA_STATUS_SIMPLE, pch= info_tbl$HRD_TEST_SYMBOL, col= brca_col), Timepoint= anno_simple(info_tbl$CLINICAL_TIMEPOINT_SPEC, pch = info_tbl$FIRST_PT_STATUS_SYMBOL, col= tmpt_col), col= list(Location= loc_cols, Tissue = tiss_cols) )
hm

Because I have three anno_simple with symbols, I need to add those legends manually, both for the colors and the meanings of the symbols itself (similar to the reference 3.2 with the p value colors & pch legend). However, it seems because this is a HeatmapAnnotation, and not a heatmap, I cannot manually add the legend for some reason. For example, if I make a legend just for Patient colors:

pat_leg<- Legend(title= "Patient", legend_gp = gpar(fill =patient_cols), at= names(patient_cols))

It looks fine using draw(pat_leg), but I am unable to do the following:

draw(hm, annotation_legend_list = list(pat_leg))

Error in (function (x = unit(0.5, "npc"), y = unit(0.5, "npc"), width = unit(1,  : 
  unused argument (annotation_legend_list = list(new("Legends", name = NULL, grob = list("GRID.legend.2441", NULL, list(0.5, 0.5, 17.8023055555555, 40.5329444444444, c(0.5, 0.5), list(), FALSE, c(0, 1), c(0, 1), 0, NULL, NULL, NULL, c(0.5, 0.5), NULL, NULL, "GRID.VP.645", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, TRUE, NULL), list(list("Patient", 0, 1, c("left", "top"), NULL, NULL, 0, FALSE, "GRID.text.2442", list(10, 2, 0.9), NULL), list("GRID.legend_body.2439", NULL, 
    list(0, 0, 17.8023055555555, 36, c(0, 0), list(), FALSE, c(0, 1), c(0, 1), 0, NULL, NULL, NULL, c(0, 0), NULL, NULL, "GRID.VP.644", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, TRUE, NULL), list(list(c("Patient1", "Patient2", "Patient3", "Patient4", "Patient5", "Patient6", "Patient7", "Patient8", "Patient9"), 5, c(34, 30, 26, 22, 18, 14, 10, 6, 2), "left", NULL, NULL, 0, FALSE, "GRID.text.2437", list(10, 0.9), NULL), list(c(0, 0,

I also tried to add the legend to the HeatmapAnnotation function itself, with annotation_legend_param, but I get an error for that as well, though the names clearly match:

hm<- HeatmapAnnotation(Patient= anno_simple(info_tbl$PATIENT, 
                                            pch=info_tbl$SLICE_TYPE_SYMBOL, col = patient_cols),
                       Location= info_tbl$LOCATION_SIMPLE,
                       Tissue= info_tbl$TYPE_OF_TISSUE,
                       BRCAstatus= anno_simple(info_tbl$BRCA_STATUS_SIMPLE, 
                                               pch= info_tbl$HRD_TEST_SYMBOL, col= brca_col), 
                       Timepoint= anno_simple(info_tbl$CLINICAL_TIMEPOINT_SPEC, 
                                              pch = info_tbl$FIRST_PT_STATUS_SYMBOL, col= tmpt_col),
     col= list(Location= loc_cols, Tissue = tiss_cols),
     annotation_legend_param = list(Patient= list(
       title= "Patient", legend_gp = gpar(fill =patient_cols), at= names(patient_cols)
     )
     )
     )

Error: Some names in 'annotation_legend_param' are not in names of simple annotations.

How might I be able to add manual legends to the HeatmapAnnotation in this case? I haven't seen anything in the documentation about this being done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant