转换UpSet图为ggplot对象

我在2018年4月份的一条推特文,https://twitter.com/guangchuangyu/status/988672880551518210,可以把UpSetR变成ggplot然后可以各种玩,比较我在推特文中所展示的,图上嵌入venn图、使用cowplot拼图等。然而过了大半年,我的pull request并没有被作者接收,也就是说这功能还不存在于官方的版本中。

如果有兴趣的话,应该安装我fork的版本。

devtools::install_github("GuangchuangYu/UpSetR")

Continue reading

听说你想打水印?

正如我在《用R画meme ;)》里说的,meme包就可以拿来画,当然这个包是设计来画meme的,所以文本只会打在中间,如果你想在右下角之类的,不好意思,我没提供选项让你调文本位置,氮素,meme依然是你的好帮手,怎么说呢,meme不单能帮你读图片,还能用grid画出来,这意味着你可以用grid.text随便加个文本就OK了。

实例演示一发:

library(meme)
u <- system.file("angry8.jpg", package="meme")
x <- meme(u)
print(x)
grid.text("biobabble", x=.9, y=.05, 
	gp=gpar(col='white', cex=1.2))

Continue reading

After the release of meme package, I received several feedbacks from users.

The most usefule one is the comment on my blog post:

Greetings Mr. Yu,

I am very happy that this package exists. Thank you for making it! I would like to request a feature, to ensure the package is able to compete with professional meme-creation tools like memegenerator and paint.net. Since memes often use the font Impact, in white and with black outline, I believe the package would be more powerful if it also did that automatically.

Regards,

The words, ‘compete with professional meme-creation tools’, stimulated me to develop text plotting with background outline effect.

Now this feature is available in meme v>=0.0.7, which can be downloaded from CRAN.

Continue reading

Sercan Kahveci

Greetings Mr. Yu,

I am very happy that this package exists. Thank you for making it! I would like to request a feature, to ensure the package is able to compete with professional meme-creation tools like memegenerator and paint.net. Since memes often use the font Impact, in white and with black outline, I believe the package would be more powerful if it also did that automatically.

Regards,

Sercan Kahveci, MSc

Content creator at Questionable Research Memes on Facebook https://www.facebook.com/QResearchMemes/

上次一篇《用R画meme ;)》把脸书在做MEME的人都给炸出来了,专业人士给出专业建议,要用Impact字体,并且要让字体出现阴影效果,这真是厉害了,感觉有点神奇,但他一句,这样就可以和专业工具PK了,着实太刺激了,我决定试一试能不能搞个阴影效果。结果还真让我搞成了,文本有一种浮在上面的错觉。

我们知道meme包是grid写的,我的输出是grob对象,当我半夜调试到2点,带着兴奋入睡之后,一点都睡不安稳,早上早早就迷迷糊糊在床上想着,既然我造出了文本阴影效果的grob对象,我应该封装成geom图层,送给ggplot2用户。

Continue reading

create meme in R

I developed a tiny toy package, meme, which is now on CRAN. As it’s name indicated, it was designed to create memes, which are captioned photos that are intended to be funny, riduculous.

meme()

The package is quite simple. You can use meme() function to add meme captions, and this is all the package supposed to do:

library(meme)
u <- "http://www.happyfamilyneeds.com/wp-content/uploads/2017/08/angry8.jpg"
meme(u, "code", "all the things!")

Continue reading

最近公众号「生信媛」和「生信宝典」的小伙伴在说ggplot2无法一次性设置所有字体,theme只能设置axis text, title这些,而搞不了geom_textgeom_text必须要手工输入family=XXX来设置,因为不能使用theme来更换,也就是说没办法通过后处理来设定,比较麻烦。

这显然是不对的,后处理必须可以的,一次性满足所有愿望也只是因为没人写个神奇的函数而已。于是我就动手写了个set_font的函数。

假设我们有下图:

library(ggplot2)
d <- data.frame(x=rnorm(10), y=rnorm(10), lab=LETTERS[1:10])
p <- ggplot(d, aes(x, y)) + 
    geom_text(aes(label=lab, color=lab), size=10) + 
	geom_text(aes(y, x, label=lab), size=3)

Continue reading

Author's picture

Guangchuang Yu

Bioinformatics Professor @ SMU

Bioinformatics Professor

Guangzhou