2012-07-23 119 views
3

給定一個分數向量(在域[0:1]上),我想繪製剛剛部分填充的頂點。 也就是說如果分數是1/2,則相應的頂點應該是半填充的(半球) 即,如果分數是1/4對應的頂點僅在四分之一(四分之一球體) 等等...R igraph部分填充頂點

library('igraph') 
N <- 10 
g <- graph.full(N) 
values <- runif(N,0,1) # vector of fractions 
V(g)$shape <-'circle' 

plot.igraph(g,...) 

例如: http://www.google.ch/imgres?q=three+quarter-filled+circle&um=1&hl=de&sa=N&biw=1024&bih=751&tbm=isch&tbnid=fCz7FZ6JG38DzM:&imgrefurl=http://www.clipartstation.com/clipart_indexer4/index/search%3Fkeywords%3DART&docid=UPphGFugM1pYGM&imgurl=http://www.clipartstation.com/clipart/resized/Math/Transformations/__100x100//three%252520quarters%252520blue%252520circle.gif&w=100&h=99&ei=ETsNUNDeHbCL4gTT5rjACg&zoom=1&iact=rc&dur=331&sig=101088608959992434501&page=1&tbnh=79&tbnw=80&start=0&ndsp=24&ved=1t:429,r:8,s:0,i:97&tx=49&ty=38

+0

例如:http://www.google.ch/imgres?q=three+quarter-filled+circle&um=1&hl=de&sa=N&biw=1024&bih=751&tbm=isch&tbnid=fCz7FZ6JG38DzM:&imgrefurl=http://www.clipartstation的.com/clipart_indexer4 /索引/搜索%3Fkeywords%3DART&的docID = UPphGFugM1pYGM&imgUrl的HTTP =://www.clipartstation.com/clipart/resized/Math/Transformations/__100x100//three%252520quarters%252520blue%252520circle.gif&w=100&h=99&ei= ETsNUNDeHbCL4gTT5rjACg&zoom = 1&iact = rc&dur = 331&sig = 101088608959992434501&page = 1&tbnh = 79&tbnw = 80&start = 0&ndsp = 24&ved = 1t:429,r:8,s:0,i:97&tx = 49&ty = 38 – 2012-07-23 11:53:21

回答

3

如果你有igraph包版本0.6,你應該能夠使用pie頂點plot(),在這種情況下,你的代碼是:

library(igraph) 
N <- 10 
g <- graph.full(N) 

values <- runif(N,0,1) # vector of fractions 
plot(g, vertex.shape="pie", vertex.pie=values, vertex.frame.color="white", 
    vertex.pie.color=list(heat.colors(5))) 

如果你沒有這方面的工作(我沒有),您可以找到代碼here,您可以運行該代碼,然後使用pie作爲頂點。

+1

不應將'values'向量,例如'values < - lapply(runif(N,0,1),function(u)c(u,1-u))'? – 2012-07-23 14:28:10

+0

@DiscreteCircle:你的解決方案也不適用於我的igraph版本。但是,您從Gabor Csardi發佈的帖子的超鏈接很好 - 完美的作品! THX – 2012-07-25 08:39:54

+0

@Vincent Zoonekynd:你說得對。如果派不應該只是一種顏色。 – 2012-07-25 08:42:42