R的交互与脚本模式

抛出一个话题,R是不是有个大坑,在自动化脚本中(或者在循环中),某些脚本执行会不出结果,特别是作图脚本。ps:分步执行可以出图

其实看我公众号的各位读者们,你们不应该有这个问题,如果有,那么证明我的文章没有好好看!

有两篇很重要的文章《扪心自问,meme几何?》和《树变图,图变树?》,特别是第二篇,和这个问题息息相关。

首先假设我们有一个图:

require(ggplot2)
p = qplot(1:10)

为什么在终端打p可以出图?

因为在R里,所有都是对象,而在终端里你输入一个对象回车,R会去找相应的方法去打印出来,如果是S3对象,会去寻找print方法,而如果是S4会去找show方法。

所以你在终端里打p,其实等同于你打print(p),它其实调用了ggplot2:::print.ggplot

你打plot(p)也可以,如果你看过代码的话,画图这个动作是定义在plot.ggplot方法里的,而print.ggplot <- plot.ggplot

Continue reading

We are happy to announce that ggtree supports interactive tree annotation/manipulation by implementing an identify method. Users can click on a node to highlight a clade, to label or rotate it etc.

Here is an example of highlighting clades using geom_hilight with identify:

Continue reading

Author's picture

Guangchuang Yu

Bioinformatics Professor @ SMU

Bioinformatics Professor

Guangzhou