1

I am working on a phylogenetic tree with R package ggtree and want to highlight nodes.

My tree is stored in p, and the node I want to highlight is in G10.

p <- ggtree(tree, right=T, layout="circular")
G10 <- findMRCA(tree, c("genome1","genome2","genome3","genome4"), type=c("node")) 

I highlight the node like this:

p + geom_hilight(node=G10, fill="forestgreen", extendto = 0.6, alpha=1)

I would like to use alpha=1 to get a nice, strong colour, but this colours over/hides the tips in the tree so you can't see them (see image). Is there a way of plotting this so the highlight is behind the tree, so that I can still see the tips?

This is what it looks like now

EDIT: I haven't found a good solution but I came up with a temporary fix that works for now:

Create two plots: a transparent plot of the tree p + theme_transparent(), and the tree with the highlights p + geom_hilight(node=G10, fill="forestgreen", extendto = 0.6, alpha=1) and overlay the transparent plot on the highlighted plot in powerpoint and save.

Hkam
  • 11
  • 2
  • Hi there, it might be easier for me and others to help out if you post a fully working (minimal) example. Currently, there is no code for creating `tree` or the node of interest. Is there a call to `rtree` that would create a tree with which one could reproduce this problem? – winni2k Oct 07 '20 at 19:29

1 Answers1

0

You can ajust the order of tree layer and high light layer. ggtree inherits the feature of ggplot2. You can use ggtree(tr) or ggplot(tr) + geom_tree() to plot your tree. So you can refer the following code.

library(ggtree)
library(ggplot2)

set.seed(1024)

tr <- rtree(20)

p <- ggplot(tr) +
     geom_hilight(node=24,alpha=1,fill="forestgreen") +
     geom_tree(layout="roundrect") +
     geom_tiplab(size=4, hjust=0)
p

enter image description here