1

I am drawing phylogenetic tree and added heatmap with gheatmap(). I would like to change color scale bar using low, mid, and high point. I thought scale_color_gradient2() made that possible, but it doesn't work.

p <- ggtree(tree.c$scenario.1, layout='fan',branch.length = "none", 
     options(ignore.negative.edge=TRUE))    
plot(p)

group <- as.matrix(fit0[,7])
rownames(group)<-tree.c$scenario.1$tip.label
colnames(group)<-c("Temperature")

library(ggnewscale)
p2 <- p + new_scale_fill()
gheatmap(p2, group, offset=1, width=.2,
         colnames= F, colnames_offset_y = .2) +
  scale_color_gradient2( low = "blue", mid = "white",  high = "red") +
  theme(legend.key.size = unit(5, 'cm'),
      legend.text=element_text(size=20),
      plot.title = element_text(size=100, hjust = 0.5, vjust = 1.5))

But it showed the error "scale for 'y' is already present. adding another scale for 'y', which will replace the existing scale. heatmap" And low, mid (midpoint = 0), and high color were not applied. How is it fixed or how do I set the color gradient with midpoint?

Thanks in advance!

marie
  • 315
  • 1
  • 9
  • 2
    It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. This said, the error you mention is just a warning. Also in case of a heat map I would guess that the `fill` aes is used instead of `color`. Hence, you could try with `scale_fill_gradient2`. – stefan Mar 10 '22 at 07:15
  • 1
    Thank you very much!! "scale_fill_gradient2" completely solved this problem! – marie Mar 10 '22 at 11:21

0 Answers0