2013-10-10 38 views
0

我想在我使用igraph繪製的網絡圖下添加色彩漸變條。出於某種原因,顏色漸變條的軸標籤無法顯示。但是,當我在沒有網絡圖的情況下單獨繪製顏色漸變條時,軸標籤會完美顯示。任何建議?帶色彩梯度條的igraph網絡圖

colorstrip <- function(colors) { 
    count <- length(colors) 
    m <- matrix(1:count, count, 1) 
    par(mai=c(5, 50, 30, 50), cex.axis=2, ann=T, tck=-1) 
    image(m, col=colors, ylab="", axes=FALSE) 
    axis(side=3, at=seq(from=-0.165, to=1.22, by=0.332), 
     labels=letters[1:5]) 
} 

library(igraph) 
g <- graph.ring(10) 

pdf("test_igraph.pdf", width=200, height=200) 
layout(matrix(c(1,2), nrow=2), heights=c(2,0.5)) 
plot(g) 
colorstrip(c("red", "mediumseagreen", "yellow", "blue")) 
dev.off() 

Original code was here

+0

請在下次發佈的代碼中包含代碼,並確保代碼真正有效。如果你擺脫了不必要的細節,使代碼更小,它也會有所幫助。然後人們會更願意幫助你。 –

回答

0

標籤是有的,但他們都非常微小。放大您的PDF查看器,然後你會看到它們。

bad plot

原因他們是微小的是,該地塊本身是巨大的。對於pdf()widthheight以英寸爲單位,所以您在圖中有200個200倍的數字。解決的辦法是使數字更小(或字母更大,但我猜你不希望有一個巨大的身影反正):

colorstrip <- function(colors) { 
    count <- length(colors) 
    m <- matrix(1:count, count, 1) 
    par(mai=c(0.2, 2, 1, 2), cex.axis=2, ann=T, tck=-1) 
    image(m, col=colors, ylab="", axes=FALSE) 
    axis(side=3, at=seq(from=-0.165, to=1.22, by=0.332), 
     labels=letters[1:5]) 
} 

library(igraph) 
g <- graph.ring(10) 

pdf("test_igraph.pdf", width=7, height=7) 
layout(matrix(c(1,2), nrow=2), heights=c(2,0.5)) 
plot(g) 
colorstrip(c("red", "mediumseagreen", "yellow", "blue")) 
dev.off() 

good plot

所以這也沒什麼關係的igraph 。實際上,即使您只是繪製顏色條,也不會看到標籤。

+0

謝謝你。這有幫助。 – user1500136