I just discovered in using pheatmap that if I give a list of color assignments via the argument annotation_colors, and there are extra colors, these colors are given in the annotation legend regardless of whether drop_levels=TRUE or FALSE.
If I don't give colors to pheatmap, it acts as I expect; namely, it only shows in the annotation legend the colors that are actually used in the data, including if I subset to a portion of the data (with drop_levels=TRUE by default):
However, if I give the annotation_colors as my object colorLegend above (which gives colors to values that are not one of the factors in my colAnnotation), it shows all of the colors in my colorLegend, regardless of the values of drop_levels:
I'm not sure if this is intended or a bug, but it is particularly annoying in practice because if you want to subset your data, like in my example above, it's quite annoying to subset the more complicated list structure that is given to annotation_colors. You have to figure out what (if any) levels have been lost by the subsetting for each of the columns of annotation_col and then remove them from each element of the list. Moreover, it seems like that is the purpose of drop_levels, so for me it seems like a bug
Edited to add specs of my computer etc:
R version 4.0.0 (2020-04-24)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS High Sierra 10.13.6
....
I just discovered in using
pheatmap
that if I give a list of color assignments via the argumentannotation_colors
, and there are extra colors, these colors are given in the annotation legend regardless of whetherdrop_levels=TRUE
orFALSE
.Here's an example setup:
If I don't give colors to
pheatmap
, it acts as I expect; namely, it only shows in the annotation legend the colors that are actually used in the data, including if I subset to a portion of the data (withdrop_levels=TRUE
by default):However, if I give the
annotation_colors
as my objectcolorLegend
above (which gives colors to values that are not one of the factors in mycolAnnotation
), it shows all of the colors in mycolorLegend
, regardless of the values ofdrop_levels
:I'm not sure if this is intended or a bug, but it is particularly annoying in practice because if you want to subset your data, like in my example above, it's quite annoying to subset the more complicated list structure that is given to
annotation_colors
. You have to figure out what (if any) levels have been lost by the subsetting for each of the columns ofannotation_col
and then remove them from each element of the list. Moreover, it seems like that is the purpose ofdrop_levels
, so for me it seems like a bugEdited to add specs of my computer etc:
And package version: