Y叔的新包base2grob

测试了一下Y叔的新包base2grob。这个包提供了base2grob函数,可以把base plot转换成grob对象。对于我来说最大的方便就是可以把一些igraph画出的网络图通过cowplot和其他ggplot做出的图自由组合。

library(base2grob)
library(igraph)
## 
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
## 
##     decompose, spectrum
## The following object is masked from 'package:base':
## 
##     union
library(cowplot)
## Loading required package: ggplot2
## 
## Attaching package: 'cowplot'
## The following object is masked from 'package:ggplot2':
## 
##     ggsave
g1 <- erdos.renyi.game(10, 0.2)
g2 <- erdos.renyi.game(10, 0.5)

E(g1)$width <- E(g2)$width <- 5
E(g1)$label.cex <- E(g2)$label.cex <- 1e-16 ## 这个我承认有点傻,但是没有找到更好的方法
V(g1)$color <- 'cyan'
V(g2)$color <- 'green'

p1 <- base2grob(~plot(g1))
p2 <- base2grob(~plot(g2))

plot_grid(p1, p2, labels=LETTERS[1:2])

Related

comments powered by Disqus