DingWB / PyComplexHeatmap

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

Boxplot orientation for `left_annotation` #70

Closed Jieran-S closed 4 months ago

Jieran-S commented 5 months ago

Is your feature request related to a problem? Please describe.

When plotting left boxplot annotation, even if I set the variable as suggested in the tutorial, the boxplot annotation on the left is still oriented to the right (meaning 0 at left and 1 at right), see image below for better demonstration.

My code for the left_annotation is

row_ha = HeatmapAnnotation(sample=anno_label(row_split, merge=True, rotation=0), 
                           domains=anno_simple(row_anno.domains), 
                           samples=anno_simple(row_anno.samples),
                           all_method_result=box, #anno_boxplot(results, cmap="cividis", height=20, legend=False),
                           axis=0, orientation='left')

And I call this annotation in ClusterMapPlotter by

cm = ClusterMapPlotter(data=results, 
top_annotation=col_ha, 
right_annotation=row_ha,
col_split = col_anno.method, 
col_cluster = False, 
row_split=row_split, 
row_cluster=False, 
col_split_gap = 1, 
...)

Describe the solution you'd like

Checking the source code, we only call vert=False when we select axis=0 and that automatically changes the boxplot into a horizontal but right-facing orientation. I was wondering if we can add something like

if orientation == "left":
     self.ax = self.ax.invert_yaxis()

or something similar to change the orientation of the boxplot?


This is the boxplot orientation I am talking about: if the annotation is on the left, 0 should be on the right and 1 should be on the right Screenshot 2024-04-15 at 14 38 48

DingWB commented 5 months ago

What do you mean by "0 should be on the right and 1 should be on the right"? Did you follow this documentation?

If you want to change the side of the ticks from left to right, you can try the parameter label_side (see here), if you set label_side to the right (or bottom), then the ticks will be put on the left (or top), and vice versa.

DingWB commented 5 months ago

I checked again. I didn't find any problem, could you please look into the documentation and confirm? @Jieran-S

Jieran-S commented 5 months ago

Hey DingWB thanks for the quick response! ☺️ Let me explain my question a bit more clearly.

Say I have a heatmap as below, with the left annotation containing the boxplot. The boxplot dataframe is essentially the heatmap dataframe, I am projecting the heatmap row-wise to generate a boxplot.

Since the annotation is a left annotation, I would assume the boxplot to be orientated towards left, meaning the y-axis should be projecting towards left. (i.e. the minimal value of y-axis should be on the right, and the maximum y-axis value should be on the left). Whereas in this heatmap, the minimal y-axis value (0) is on the left and the max (1) is on the right, making the boxplot facing not left but right.

image

Here is how I coded the left annotation:

box = anno_boxplot(results, cmap="cividis", height=30, legend=False)
row_ha = HeatmapAnnotation(sample=anno_label(row_split, merge=True, rotation=0), 
                           domains=anno_simple(row_anno.domains), 
                           samples=anno_simple(row_anno.samples),
                           all_method_result=box, 
                           axis=0, orientation='left')

Could you help me check a bit which might be the problem? I tried almost everything but it just dosen't work...

DingWB commented 5 months ago

Hi @Jieran-S ,

Thanks for your explanation. Is there any problem if you run this example code? If not, something might be wrong with your code or data. Could you please tell me which version you are using? If it is not the latest version, please upgrade to the newest version and try again.

If you are still facing the same issue with the latest version, please upload your data and paste your code, and I will debug it.