- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我可以在图中的节点处放置图像,但图像未显示在确切位置。在这里,我附上了演示代码,该代码在精确节点显示图像时有问题。即使背后的逻辑是正确的,图像也会交换它们的位置。请改进代码,以便我可以进一步工作
注意:节点数量较少时,代码工作正常 .
################ R Code To implement dynamic image fetching #######################
library(jpeg)
library(igraph)
demo_adj <- data.frame(from=c(1,2,'B','X','Y',1,1,'A'),to=c('A','B','A','Y',1,'B','X',2))
rasters <- as.list(c(imgType1='',imgType2='',imgType3='',imgType4='',imgType5=''))
rasters$imgType1 <- readJPEG("path/Images/imgType1.jpg",native=TRUE)
rasters$imgType2 <- readJPEG("path/Images/imgType2.jpg",native=TRUE)
rasters$imgType3 <- readJPEG("path/Images/imgType3.jpg",native=TRUE)
rasters$imgType4 <- readJPEG("path/Images/imgType4.jpg",native=TRUE)
rasters$imgType5 <- readJPEG("path/Images/imgType5.jpg",native=TRUE)
lkp_mat <- data.frame(from=c(1,2,'A','B','X','Y'),type=c('imgType1','imgType2','imgType3','imgType4','imgType1','imgType3'))
## create the graph
gg <- graph.data.frame(demo_adj)
## set raster attribute
for(i in V(gg)$name){
imgtype <- lkp_mat$type[lkp_mat["from"]==i]
V(gg)[name==i]$raster <- rasters[imgtype]
}
plot(gg, layout=layout.star, vertex.shape="raster",
vertex.label=V(gg)$name, margin=.2,
vertex.size=50, vertex.size2=50,
vertex.label.dist=2, vertex.label.degree=0)
###################### End of Above Code Segment ###########################################
###### Alternate Code To implement the above without jpeg images #######
library(jpeg)
library(igraph)
demo_adj <- data.frame(from=c(1,2,3,4,5,'F','G','H','I','J','J'),to=c('A','B','C','D','E',1,2,3,4,3,5))
rasters <- as.list(c(imgType1='',imgType2='',imgType3='',imgType4='',imgType5='',imgType6='',imgType7='',imgType8='',imgType9='',imgType10='',imgType11='',imgType12='',imgType13='',imgType14='',imgType15=''))
image1 <- as.raster(matrix(0:1, ncol=1, nrow=2))
image2 <- as.raster(matrix(0:1, ncol=2, nrow=4))
image3 <- as.raster(matrix(0:1, ncol=1, nrow=4))
image4 <- as.raster(matrix(0:1, ncol=4, nrow=4))
image5 <- as.raster(matrix(0:1, ncol=4, nrow=10))
image6 <- as.raster(matrix(0:1, ncol=2, nrow=2))
image7 <- as.raster(matrix(0:1, ncol=2, nrow=3))
image8 <- as.raster(matrix(0:1, ncol=2, nrow=4))
image9 <- as.raster(matrix(0:1, ncol=2, nrow=5))
image10 <- as.raster(matrix(0:1, ncol=2, nrow=6))
image11 <- as.raster(matrix(0:1, ncol=3, nrow=2))
image12 <- as.raster(matrix(0:1, ncol=4, nrow=8))
image13 <- as.raster(matrix(0:1, ncol=3, nrow=4))
image14 <- as.raster(matrix(0:1, ncol=4, nrow=2))
image15 <- as.raster(matrix(0:1, ncol=4, nrow=10))
rasters$imgType1 <- image1
rasters$imgType2 <- image2
rasters$imgType3 <- image3
rasters$imgType4 <- image4
rasters$imgType5 <- image5
rasters$imgType6 <- image6
rasters$imgType7 <- image7
rasters$imgType8 <- image8
rasters$imgType9 <- image9
rasters$imgType10 <- image10
rasters$imgType11 <- image11
rasters$imgType12 <- image12
rasters$imgType13 <- image13
rasters$imgType14 <- image14
rasters$imgType15 <- image15
lkp_mat <- data.frame(from=c(1,2,3,4,5,'A','B','C','D','E','F','G','H','I','J'),type=c('imgType1','imgType2','imgType3','imgType4','imgType5','imgType6','imgType7','imgType8','imgType9','imgType10','imgType11','imgType12','imgType13','imgType14','imgType15'))
#lkp_mat <- data.frame(from=c(1,2,3,4,5,'A','B','C','D','E','F','G','H','I','J'),type=c('imgType1','imgType2','imgType3','imgType4','imgType5','imgType2','imgType1','imgType2','imgType1','imgType2','imgType1','imgType2','imgType1','imgType2','imgType15'))
## create the graph
gg <- graph.data.frame(demo_adj)
## set raster attribute
for(i in V(gg)$name){
imgtype <- lkp_mat$type[lkp_mat["from"]==i]
V(gg)[name==i]$raster <- rasters[imgtype]
}
plot(gg, layout=layout.star, vertex.shape="raster",
vertex.label=V(gg)$name, margin=.2,
vertex.size=10, vertex.size2=20,
vertex.label.dist=2, vertex.label.degree=0)
最佳答案
这与 igraph 没有太大关系,但它是一个致命的 R 捕获,在 R inferno 中有特色。 , 第 8.2.6 节,不要用因子下标。
从您的代码中查看此部分,并添加了一些调试:
for(i in V(gg)$name){
imgtype <- lkp_mat$type[lkp_mat["from"]==i]
V(gg)[name==i]$raster <- rasters[imgtype]
if (i=="J") {
print(rasters[imgtype]) ;
print(rasters[as.character(imgtype)])
}
}
vertices
,整个事情可能会简单得多。
graph.data.frame()
的论据,例如像这样:
gg2 <- graph.data.frame(demo_adj, vertices=lkp_mat)
V(gg2)$raster <- rasters[V(gg2)$type]
plot(gg2, layout=layout.star, vertex.shape="raster",
vertex.label=V(gg2)$name, margin=.2,
vertex.size=10, vertex.size2=20,
vertex.label.dist=2, vertex.label.degree=0)
关于R : Display Image at Exact Node in Igraph,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16932442/
我有一个 N x 2 的整数表,称为 games[ , ]。节点/边表转换为图形: net edges g ecount(g) 7 > degree(g, 103, mode="out") 4
我开始评估 igraph 库及其功能。 我需要计算 igraph_de_bruijn() 函数生成的图的哈密顿路径。 igraph 库中是否有任何现成的功能?我不想从头开始实现它。 C中的一个例子将是
我正在尝试像这样深度复制我的 igraph 对象: copy.deepcopy(graph) 其中 graph 是 igraph 对象,一个只有几个顶点的完整图。但是我得到这个错误: Fi
我有一个需要过滤的大图。过滤(子图)后,我最终得到一个子图列表。我需要再次将所有这些子图组合成一个图。我不知道如何组合大列表(近百万个子图) > require(igraph) > graph V(
我有一个简单的问题,函数 community.to.membership 在 igraph 1.0 中是否被弃用了?我可以找到 membership 函数,但它不包括选项 merges、steps 等
我正在使用 R 中的 igraph。我知道我们可以用选定的顶点创建一个子图,但如果这些节点没有直接连接,那么新子图中将不会有边。如果有其他节点(不是顶点列表的一部分)间接连接这两个节点,有没有办法制作
我正在使用 R 中的 igraph。我知道我们可以用选定的顶点创建一个子图,但如果这些节点没有直接连接,那么新子图中将不会有边。如果有其他节点(不是顶点列表的一部分)间接连接这两个节点,有没有办法制作
是否有与此 igraph 等效的 R function在 Python igraph 中? graph_from_data_frame(d, directed = TRUE, vertices = N
a=g.vs(Name_eq="A") b=g.vs(Name_eq="B") 我想在 a 和 b 之间添加一条边,我该怎么做? 最佳答案 好的,我们这里好像有两个问题。一个在问题标题中:“如果我们有
我有一个大型无向加权图,其中包含约 375,000 个节点和约 3,400,000 个边,表示为邻接表(字典的字典)。 例如 A --> (B,2), (C,4) B --> (A,2) C -->
igraph here 中对可用的社区检测算法进行了很好的比较。 .但是,在可以应用于加权边的算法中使用权重存在一些歧义。 通常,边缘权重将被定向,以便更高的权重表明将节点保持在一起(例如友谊的强度)
我在 igraph 中使用了 fastgreedy 算法在加权无向图中进行社区检测。后来我想看看模块化性,不同的方法我得到了不同的值,我想知道为什么。我提供了一个简短的示例,它演示了我的问题: lib
我正在使用 igraph g <- graph_from_adjacency_matrix(adj2, mode = "directed") plot.igraph(g, vertex.size =
我想知道如果 igraph-R 包中没有实现基于模块化聚类的算法,由 Newman 于 2004 年发布:“Fast algorithm for detection community structu
我有一个类似的问题:Reading adjacency lists with isolated nodes using igraph 我想绘制一些没有关系的节点。但是由于某种原因,上面线程中提到的解决
我有一个交互网络,我使用以下代码制作邻接矩阵,随后计算网络节点之间的相异性,然后将它们聚类以形成模块: ADJ1=abs(adjacent-mat)^6 dissADJ1% as.dist %
我想使用 igraph 来探索一些网络数据。我的数据具有以下结构: a <- c(13, 32, NA, NA) b <- c(32, NA, NA, NA) c <- c(34, 13, 32, N
我使用 igraph graph_from_data_frame 函数从数据框构建了一个图。我的前两列代表边缘列表,我还有另一列名为“权重”。还有其他几个属性列。 然后我尝试使用 cluster_fa
我的问题如下: 考虑一个具有 10000 个节点和 4800 条边的无向图。 给定这个图和这个图的一个节点(例如,节点 1),我需要 igraph (R) 中的一个命令来获取这个节点 1 和图中最远节
我已指导 igraph 并想获取所有周期。 girth 函数有效,但只返回最小的周期。 R 中有没有办法在长度大于 3 的图中获取所有循环(没有顶点指向自身和循环) 最佳答案 它不是 igraph 中
我是一名优秀的程序员,十分优秀!