DingWB / PyComplexHeatmap

PyComplexHeatmap: A Python package to plot complex heatmap (clustermap)
https://dingwb.github.io/PyComplexHeatmap/
MIT License
279 stars 30 forks source link

Reordering annotation on clustermap #30

Closed sruthi-hub closed 1 year ago

sruthi-hub commented 1 year ago

Discussed in https://github.com/DingWB/PyComplexHeatmap/discussions/29

Originally posted by **sruthi-hub** April 25, 2023 First, thanks for making the complexheatmap package for python users. I am using the DotClustermapPlotter to make a dotplot with annotations for rows and columns. I want to specify the order for teh annotation of the columns. I see that class(AnnotationBase) has a [reorder](https://dingwb.github.io/PyComplexHeatmap/build/html/PyComplexHeatmap.annotations.html#PyComplexHeatmap.annotations.AnnotationBase.reorder) function. It would be nice to see an example to reorder the values in column annotation. For example ([provided here](https://dingwb.github.io/PyComplexHeatmap/build/html/notebooks/dotHeatmap.html#Visualize-up-to-five-dimension-data-using-DotClustermapPlotter)), if I want to change the order of the column such that I want Dataset 2 and then Dataset 1, how do I do that? Seems like this should be straight forward to do. Would appreciate your help. ----------------------- ``` row_ha = HeatmapAnnotation( Category=anno_simple(df_row.Category,cmap='Set1', add_text=False,legend=False), label=anno_label(df_row.Category, merge=True,rotation=0), axis=0,verbose=0,label_kws={'rotation':45,'horizontalalignment':'left'}) col_ha = HeatmapAnnotation( Dataset=anno_simple(df_col.Dataset,cmap='Set1',legend=False,add_text=True), Correlation=anno_simple(df_col.Correlation,cmap='Dark2',legend=False,add_text=True), verbose=0,label_side='left',label_kws={'horizontalalignment':'right'}) plt.figure(figsize=(5, 8)) cm = DotClustermapPlotter(data=data, x='ID',y='Term',value='-log10(Pval)',c='-log10(Pval)',s='odds_ratio', hue='EnrichType', row_cluster=False,col_cluster=False, cmap={'Enrich':'RdYlGn_r','Depletion':'coolwarm_r'}, colors={'Enrich':'red','Depletion':'blue'}, #marker={'Enrich':'^','Depletion':'v'}, top_annotation=col_ha,right_annotation=row_ha, col_split=df_col.Dataset,row_split=df_row.Category, col_split_gap=0.5,row_split_gap=1, show_rownames=True,show_colnames=False,row_dendrogram=False, verbose=0,legend_gap=7,alpha=0.8) #plt.savefig("dotHeatmap1.pdf",bbox_inches='tight') plt.show() ``` --------------------
DingWB commented 1 year ago

It was answered in this discussion