2017-09-08 73 views
0

側情節我試圖繪製並排兩個圖側的PDF文件的一個頁面如下:側用的igraph

library(igraph) 
library(ggplot2) 
post <- topicmodels::posterior(ldaOut) 
layout(matrix(1,1 byrow = TRUE)) 
cor_mat <- cor(t(post[["terms"]])) 
cor_mat[ cor_mat < .05 ] <- 0 
diag(cor_mat) <- 0 
graph <- graph.adjacency(cor_mat, weighted=TRUE, mode="lower") 
graph <- delete.edges(graph, E(graph)[ weight < 0.05]) 
E(graph)$edge.width <- E(graph)$weight* 15 
V(graph)$label <- paste("Topic", V(graph)) 
V(graph)$size <- colSums(post[["topics"]]) * 2 
set.seed(110) 
pdf("all.pdf", width=400,height=350,res=72) 
p1 <- plot.igraph(graph, edge.width = E(graph)$edge.width, 
    edge.color = "blue", vertex.color = "green", 
    vertex.frame.color = NA, vertex.label.color = "black") 
clp <- cluster_label_prop(graph) 
class(clp) 
p2 <- plot(clp, graph, edge.width = E(graph)$edge.width, edge.color = "blue",vertex.color = "green") 
pushViewport(viewport(layout = grid.layout(1, 2))) 
print(p1, vp = viewport(layout.pos.row = 1, layout.pos.col = 1)) 
print(p2, vp = viewport(layout.pos.row = 1, layout.pos.col = 2)) 
dev.off() 

但結果表明,有兩個分開的頁面兩個地塊,而不是一個頁面。有關如何解決此問題的任何建議?

+0

後可重現的例子。什麼是'ldaOut','post'? – PoGibas

+0

試着用'par(mfrow = c(1,2))'替換你的'layout'聲明' – G5W

+0

@PoGibas這些是我處理過的數據集,我沒有問題。我從問題的結果出發。 – Sultan

回答

1

所以,這個問題有答案...

的問題是,當你切換到新的圖形設備與您pdf聲明,你失去了你想要的1×2顯示任何跡象圖表。一種解決方案是在您的pdf聲明之後立即添加

par(mfrow=c(1,2)) 

。如果您的陳述放置在那裏,它可能會奏效。