R,igraph,是否可以用图案填充顶点 [英] R, igraph, is it possible to fill vertex with pattern

查看:124
本文介绍了R,igraph,是否可以用图案填充顶点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用R和igraph绘制图形,我使用颜色标记顶点类型.请参阅下面的代码.是否可以用图案而不是颜色填充顶点,以便在用彩色和黑白查看时可以区分节点类型? 我需要4种独特的颜色/图案. colorbrewer中唯一适合的调色板就是这个调色板: http://colorbrewer2. org/#type = sequential& scheme = OrRd& n = 4 但是,对于我的稀疏图,仍然很难区分颜色.另外,我是色盲,这无济于事.我想知道是否可以在条纹上填充条纹,条纹,圆点或其他颜色.

Drawing a graph with R and igraph, I'm using color to label vertex type. See code below. Is it possible to fill vertices with a pattern rather than a color so that the node types are distinguishable when viewed in color AND black and white? I need 4 unique colors/patterns. The only palette from colorbrewer that fits is this one: http://colorbrewer2.org/#type=sequential&scheme=OrRd&n=4 However, for my sparse graph, its still difficult to differentiate the colors. Also, I'm color blind, which doesn't help. I wan to know if I can fill the vertices with stripes,hasing, polka-dots, anything other than color.

library(igraph)
library(RColorBrewer)
cols = brewer.pal(4, "Dark2") #looks good in color, not in bw
g <- sample_pa(20)
l <- layout_with_fr(g,niter=300)
plot(g,layout=l,edge.arrow.size=0,vertex.size=8,
     vertex.frame.color="white",vertex.label=NA,vertex.color=cols)

推荐答案

您的图形有20个顶点.

Your graph has 20 vertices.

> length(V(g))
[1] 20

shape参数(请参见?vertex.shape.pie可以采用相对段大小和不同颜色的数值说明形式的变化的饼形图案"(或形状):

The shape argument (see ?vertex.shape.pie can apply a varying pie-"pattern" (or shape) in the form of a numerical specification of the relative segment sizes and varying colors:

values <- lapply(1:20, function(x) sample(1:5)) #segment sizes
colrs <- lapply(1:20, function(x) sample( c(heat.colors(4), "#000000FF"), 5))  # order of colors
plot(g, vertex.shape="pie", vertex.pie=values,
       vertex.pie.color=colrs,
       vertex.size=seq(10,30,length=10), vertex.label=NA)

您可以将这些白色"标记为"#ffffffff",也可以将它们制成不同的灰色阴影.可以对基本图形进行图案化(这是plot.igraph使用的范式,其参数为:

You could make these "white" with "#ffffffff" or make them varying shades of grey. It is possible to pattern base graphics (which is the paradigm used by plot.igraph with arguments like:

rect(.8,.8,1,1, col=grey(.2), density=20, angle=45)

但是,我没有在plot.igraph代码中看到'density'参数的使用.如果要自己检查,则需要查看igraph-命名空间:

However, I don't see the use of the 'density' parameter in the plot.igraph code. If you want to do your own inspection, you will need to look inside the igraph-namespace:

ls( envir= as.environment("package:igraph") )

这篇关于R,igraph,是否可以用图案填充顶点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆