## add layer to specific panel of facet_plot output

This is a question from ggtree google group:

Dear ggtree team,

how can I apply a geom_xxx to only one facet panel? For example if i want to get geom_hline(yintersect=1:30) or a geom_text() in the dot panel? I cant see the facet_grid(. ~ var) function call, so I don’t know which subsetting to use. I have already read http://stackoverflow.com/questions/29873155/geom-text-and-facets-not-working

  tr <- rtree(30)

d1 <- data.frame(id=tr$tip.label, val=rnorm(30, sd=3)) p <- ggtree(tr) p2 <- facet_plot(p, panel="dot", data=d1, geom=geom_point, aes(x=val), color='firebrick') d2 <- data.frame(id=tr$tip.label, value = abs(rnorm(30, mean=100, sd=50)))

p3 <- facet_plot(p2, panel='bar', data=d2, geom=geom_segment, aes(x=0, xend=value, y=y, yend=y), size=3, color='steelblue') + theme_tree2()


Thanks! Andreas

If this can be done, we can create even more comprehensive tree plots.

## xlim_tree: set x axis limits for only Tree panel

A ggtree user recently asked me the following question in google group:

I try to plot long tip labels in ggtree and usually adjust them using xlim(), however when creating a facet_plot xlim affects all plots and minimizes them.

Is it possible to work around this and only affect the tree and it’s tip labels leaving the other plots in facet_plot unaffected?

This is indeed a desire feature, as ggplot2 can’t automatically adjust xlim for text since the units are in two different spaces (data and pixel).

## facet_plot: a general solution to associate data with phylogenetic tree

ggtree provides gheatmap for visualizing heatmap and msaplot for visualizing multiple sequence alignment with phylogenetic tree.

We may have different data types and want to visualize and align them with the tree. For example, dotplot of SNP site (e.g. using geom_point(shape='|')), barplot of trait values (e.g. using geom_barh(stat='identity')) et al.

To make it easy to associate different types of data with phylogenetic tree, I implemented the facet_plot function which accepts a geom function to draw the input data.frame and display it in an additional panel.

## reproducible logo generated by ggtree

ggtree provides many helper functions for manupulating phylogenetic trees and make it easy to explore tree structure visually.

Here, as examples, I used ggtree to draw capital character G and C, which are first letter of my name :-).

To draw a tree in such shape, we need fan layout (circular layout with open angle) and then rotating the tree to let the open space on the correct position. Here are the source codes to produce the G and C shapes of tree. I am thinking about using the G shaped tree as ggtree logo. Have fun with ggtree :-)

## embed images in ggplot2 via subview and annotate a phylogenetic tree with images using inset function

I extended the subview function to support embed image file in a ggplot object.

set.seed(123)
d = data.frame(x=rnorm(10), y=rnorm(10))

imgfile <- tempfile(, fileext=".png")
destfile=imgfile, mode='wb')

p = ggplot(d, aes(x, y))
subview(p, imgfile, x=d$x[1], y=d$y[1]) + geom_point(size=5)


## Font Awesome supported in emojifont

emojifont is available in CRAN, you can use the following command to install it.

install.packages("emojifont")


An example of using emoji font in R plot is showed below:

## use emoji font in R

I have played with emoji in R for a while. My solution of using it is different from what implemented in emoGG.

emoGG is a good attemp to add emoji in ggplot2. It render emoji picture (png) and creat a layer, geom_emoji, to add emoji.

In my opinion, emoji should be treated as ordinary font in user interface, albeit it maynot be true internally.

It would be more flexible if we can use emoji as ordinary font and in this way user don’t need to learn extra stuff.

## draw chinese character Jiong using ggplot2

The Chinese character Jiong (囧) is now widely used for expressing ideas or feelings such as annoyance, shock, embarrassment, awkwardness, scorn.

The function plot of y=1/(x^2-1) looks very similar of this symbol.

I use ggplot2 to draw the symbol of Jiong.

## ggplot2 Version of Figures in <25 Recipes for Getting Started with R>

In order to provide an option to compare graphs produced by basic internal plot function and ggplot2, I have recreated the figures in the book, 25 Recipes for Getting Started with R, with ggplot2.

The code used to create the images is in separate paragraphs, allowing easy comparison. 1.16 Creating a Scatter Plot

plot(cars)


## the batman equation

HardOCP has an image with an equation which apparently draws the Batman logo.