ggtree icon indicating copy to clipboard operation
ggtree copied to clipboard

Is it possible to add spaces or separation between the squares using gheatmap?

Open kevinlopezreyes opened this issue 1 year ago • 0 comments
trafficstars

Dear Dr. Guangchuang Yu,

I have a question, and I hope you can help me. Thank you.

I am trying to plot a heatmap on a phylogeny, but I want the squares representing my traits to be separated, not connected.

Here is an reproducible example

Load the libraries

library(ggtreeExtra) library(ggplot2) library(ggtree)

random data

set.seed(123) tr <- rtree(5)

tip_ranges <- data.frame(row.names = tr$tip.label, Attribute1 = c("A", "B", "C", "A", "B"), Attribute2 = c("High", "Low", "Medium", "High", "Medium"))

plot the tree

Fig_1 <- ggtree(tr) + geom_tiplab()

Fig_1 <- gheatmap(Fig_1, tip_ranges, offset = 0.5, width = 0.5, font.size = 3, colnames_angle = 0, hjust = 0.5, color = "black", colnames_position = "top") + scale_fill_manual(values = c("A" = "blue", "B" = "red", "C" = "green", "High" = "gold", "Medium" = "lightgreen", "Low" = "gray")) + theme(legend.position = "none")

print(Fig_1) fig_1 fig_1_mod

kevinlopezreyes avatar Sep 25 '24 10:09 kevinlopezreyes