subsetting data in ggtree

September 23, 2015

(This article was first published on YGC » R, and kindly contributed to R-bloggers)

Subsetting is commonly used in ggtree as we would like to for example separating internal nodes from tips. We may also want to display annotation to specific node(s)/tip(s).

Some software may stored clade information (e.g. bootstrap value) as internal node labels. Indeed we want to manipulate such information and taxa labels separately.

In current ggplot2 (version=1.0.1, access date:2015-09-23), it support subset. For instance:

?View Code RSPLUS

ggtree(tree) + geom_text(aes(label=label), subset=.(!isTip), hjust=-.2)

But this feature was removed in github version of ggplot2 and will not be available in next release.

In github version of ggtree, we implemented geom_text2, geom_point2, and geom_segment2, that works exactly like geom_text, geom_point and geom_segment respectively with subset supported. The syntax is slightly different.

?View Code RSPLUS

ggtree(tree) + geom_text2(aes(label=label, subset=!isTip), hjust=-.2) +
        geom_point2(aes(subset=!isTip), color="red", size=3)

Note: The example was from the discussion of github issue.

Related Posts

To leave a comment for the author, please follow the link and comment on their blog: YGC » R. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)