1 year ago

#272891

test-img

marie

scale_color_gradient2 in gheatmap

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!

r

ggplot2

ggtree

0 Answers

Your Answer

Accepted video resources