YuLab-SMU / ggtree

:christmas_tree:Visualization and annotation of phylogenetic trees
https://yulab-smu.top/treedata-book/
821 stars 172 forks source link

Unwanted white lines between tiles in gheatmap layout circular/fan #600

Open ruthvikpsi opened 6 months ago

ruthvikpsi commented 6 months ago

I have been trying to plot a heatmap with the gheatmap function and I wanted the tiles to be seamless i.e. not be separated. I did use the argument "color=NA" in the gheatmap function but this still leads to a thin white line between two tiles when zoomed in on a pdf file for example (see pdf output from code below). Now, my tree has 3000+ tips and the white lines become noticeable as they create unwanted artefacts on the heatmap (see image below). This only happens in the round format trees (circular and fan) and there are no white lines in the rectangular layout. Is there an easy fix to this bug with a function that I am not aware of?

artifacts

Reproducible bug from anoletree data:

library(ggtree)
library(dplyr)
library(phytools)

anole.tree<-read.tree("http://www.phytools.org/eqg2015/data/anole.tre")
svl<-read.csv("http://www.phytools.org/eqg2015/data/svl.csv",
              row.names=1)
svl$svl = pmin(svl$svl, 3)
svl<-as.matrix(svl)[,1]
fit<-fastAnc(anole.tree,svl,vars=TRUE,CI=TRUE)
# Make a dataframe with estimated trait values at the nodes
svl_tip <- data.frame(
  node = nodeid(anole.tree, names(svl)),
  trait = svl
)

# Make a dataframe with estimated trait values at the nodes
svl_node <- data.frame(node = names(fit$ace), trait = fit$ace)

# Combine these with the tree data for plotting with ggtree
d <- rbind(svl_tip, svl_node)
d$node <- as.numeric(d$node)
tree <- full_join(anole.tree, d, by = 'node')

pdf(file="svl_asr.pdf",width=10,height=15)
p <- ggtree(
  tree,
  layout = 'circular')

gheatmap(p, data.frame(svl), width=0.04, colnames = FALSE, 
         legend_title = "SVL", color=NA) +
  scale_y_continuous(expand = c(0, 0)) +
  ggtitle("SVL Test") 
dev.off()

Session Info:

R version 4.3.2 (2023-10-31 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 11 x64 (build 22631)

Matrix products: default

locale: [1] LC_COLLATE=English_United Kingdom.utf8 [2] LC_CTYPE=English_United Kingdom.utf8
[3] LC_MONETARY=English_United Kingdom.utf8 [4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.utf8

time zone: Europe/London tzcode source: internal

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] ggplot2_3.4.4 phytools_2.1-1 maps_3.4.2 ape_5.7-1 dplyr_1.1.4
[6] ggtree_3.10.0 tidytree_0.4.6