Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I implemented a function, subview, in ggtree that make it easy to embed a subplot in ggplot.

An example is shown below:

?View Code RSPLUS
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21  library(ggplot2) library(ggtree)   dd <- data.frame(x=LETTERS[1:3], y=1:3) pie <- ggplot(dd, aes(x=1, y, fill=x)) + geom_bar(stat="identity", width=1) + coord_polar(theta="y") + theme_tree() + xlab(NULL) + ylab(NULL) + theme_transparent()   x <- sample(2:9) y <- sample(2:9) width <- sample(seq(0.05, 0.15, length.out=length(x))) height <- width   p <- ggplot(data=data.frame(x=c(0, 10), y=c(0, 10)), aes(x, y))+geom_blank() print(p) for (i in seq_along(x)) { p %<>% subview(pie, x[i], y[i], width[i], height[i]) print(p) }

With this function, we can plot a specific clade and add a subplot of the whole topology; we can also add relative statistic graph above the tree or to a specific node. It’s not specific to phylogenetic tree, it works with all ggplot objects as demonstrated in the example.

PS: ggtree is now presented in CRAN Task View: Phylogenetics.

AND get its first citation.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.23831097781658173, "perplexity": 9405.489731969185}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2021-49/segments/1637964358774.44/warc/CC-MAIN-20211129134323-20211129164323-00630.warc.gz"}