ggpubr icon indicating copy to clipboard operation
ggpubr copied to clipboard

stat_compare_means for heatmap

Open pdhrati02 opened this issue 2 years ago • 0 comments

Hi all, I am trying to add significance stars to a heatmap, so essentially involving multiple group comparisons for many variables. I am able to get a overall p value but I am trying for individual p values, any help would be appreciated.

Example code:

colheat <- ggplot(data = col, mapping = aes(x = Group, y = class, fill = abun_log)) + geom_tile() + scale_fill_gradient(name = "Abundance", low = "#87CEFA", high = "#FF0000") + stat_compare_means(ref.group = "no", inherit.aes = F, mapping = aes(x = Group, y= abun_log)) colheat

So basically here I have 3 groups on x axis and several classes on y axis (here a,b,c,d), and I want to get significance values with one group (group no) as reference throughout for each class.
A small reproducible dataset is as follows

Abund Group class abun_log 16.19616799 no a 1.235431679 3903.276485 no b 3.591540565 0 no c 0 0 no d 0 45.05071789 cic a 1.663236405 1689.401921 cic b 3.227989978 5.119399761 cic c 0.786708825 6.143279713 cic d 0.853897656 23.46056192 yuk a 1.38846643 4085.656858 yuk b 3.611368173 2.346056192 yuk c 0.52453323 4.692112383 yuk d 0.755273466

I tried stat_compare_means and it uses the ref.group as no and runs but gives an overall p value between groups neglecting the classes. Is there a way to add grouping variable to stat_compare_means? I tried ading group inside aesthetics but that doesn't work. I also I tried compare_means as that as group.by option, but that gives errors too such as non numeric argument to binary operator (because inherit aes = F doesn't work here) and I tried compare_means separately and it works fine but I am unable to add the results to my heatmap.

Any help would be appreciated. Thank you DP

pdhrati02 avatar Jul 12 '22 09:07 pdhrati02