正如标题所说,我想将每个群集保存在pdf文件的单独页面上。
示例数据:
structure(list(P1 = c("ATCG00490", "AT5G17710", "AT2G42910",
"AT4G23600", "AT3G61540", "AT2G05990"), P2 = c("AT5G38420", "AT5G20070",
"AT5G04230", "AT1G08200", "AT4G30910", "AT5G52100"), clique = structure(list(
`930` = integer(0), `2090` = integer(0), `3120` = c(2L, 3L,
231L), `3663` = integer(0), `3704` = integer(0), `4156` = c(19L,
27L)), .Names = c("930", "2090", "3120", "3663", "3704",
"4156"), class = "AsIs")), .Names = c("P1", "P2", "clique"), row.names = c(930L,
2090L, 3120L, 3663L, 3704L, 4156L), class = "data.frame")
有些行属于许多群集,有些行只属于单个群集。当然,必须考虑所有可能的变体。
如果可能,我只想保留至少有两个成员的集群。
如果每行都属于单个集群,那就是我使用的函数:
pdf("clusters.pdf", , width=12, height=18)
lapply(split(data_cluster, data_cluster$cluster), function(d) {
grid::grid.newpage()
gridExtra::grid.table(d)
}
)
dev.off()
也许它会帮助别人找到答案。
编辑:
我在准备示例数据时犯了一个错误...请查看我的原始数据,而不是你会发现那不是那么简单(至少在我看来)。
structure(list(P1 = c("ATCG00490", "AT5G17710", "AT2G42910",
"AT4G23600", "AT3G61540", "AT2G05990"), P2 = c("AT5G38420", "AT5G20070",
"AT5G04230", "AT1G08200", "AT4G30910", "AT5G52100"), clique = structure(list(
`930` = integer(0), `2090` = integer(0), `3120` = c(2L, 3L,
231L), `3663` = integer(0), `3704` = integer(0), `4156` = c(19L,
27L)), .Names = c("930", "2090", "3120", "3663", "3704",
"4156"), class = "AsIs")), .Names = c("P1", "P2", "clique"), row.names = c(930L,
2090L, 3120L, 3663L, 3704L, 4156L), class = "data.frame")