2014-09-01 55 views
5

我一直在試驗HiveR併成功創建了一個配置單元圖,它代表了我正在使用的數據集之一。原始圖的數據是一個典型的毛球:裁剪蜂巢圖

enter image description here

然而,一個蜂巢圖給出的數據的更簡單,更直觀的查看:

enter image description here

然而,問題是情節只佔據畫布的一小部分。我嘗試了各種技巧來裁剪它,這樣劇情佔據了大部分的框架,但沒有一個成功。最有希望的選擇是將情節寫入pdf或eps文件,然後使用pdfcrop或epstool來修剪空白空間,但他們都沒有在實踐中工作。我懷疑情節有一些看不見邊框的不可見元素。

有沒有人有任何想法可以有效地裁剪這個情節? [我知道我可以手動完成,但是我將不得不生成一些這些圖,我正在尋找一種系統化/編程方式來完成它。]

可以找到配置單元圖的數據結構here

非常感謝, 安德魯。

以下是創建情節代碼:

set.seed(3) 

VERTICES <- 512 

library(igraph) 

big.graph <- barabasi.game(VERTICES, power = 1, 
          out.seq = sort(sample(c(1, 2, 3, 4), VERTICES, replace = TRUE, 
               prob = c(0.1, 0.7, 0.1, 0.1))), 
          directed = FALSE, out.pref = TRUE) 
library(HiveR) 
library(digest) 

V(big.graph)$name <- sapply(1:VERTICES, function(n) {digest(n, algo = "crc32", serialize = TRUE)}) 

big.matrix <- get.adjacency(big.graph, type= "lower", attr=NULL, names=TRUE, sparse=FALSE) 

colnames(big.matrix) <- V(big.graph)$name 
rownames(big.matrix) <- colnames(big.matrix) 

hive <- adj2HPD(big.matrix, axis.cols = "black") 
hive <- mineHPD(hive, option = "rad <- tot.edge.count") 
hive <- mineHPD(hive, option = "axis <- source.man.sink") 

summary = sumHPD(hive, chk.all = TRUE, plot.list = TRUE) 
# 
occluding = subset(summary, n1.ax == n2.ax & n1.rad == n2.rad) 
occluding = unique(c(as.character(occluding$n1.lab), as.character(occluding$n2.lab))) 
# 
hive$nodes$radius = ifelse(hive$nodes$lab %in% occluding, jitter(hive$nodes$radius), hive$nodes$radius) 

library(grid) 

plotHive(hive, bkgnd = "white") 
+1

你也可以發佈你的代碼來創建這個陰謀嗎? – Andrie 2014-09-01 11:05:48

+0

好計劃。完成。 – DataWookie 2014-09-02 10:50:00

回答

0

我會做的是使用pdfcrop。

knitr有一個很好的功能plot_crop,它可以很好地爲你工作。

您可能需要安裝pdfcrop/ImageMagick,但這會讓您以編程方式生成這些圖並刪除空白。

pdf("graph.pdf") 
plotHive(hive, bkgnd = "white") 
dev.off() 

library(knitr) 
plot_crop("graph.pdf")