如何绘制3d网络图标签

时间:2018-02-21 03:41:05

标签: r networking graph

我正在尝试使用以下代码绘制3D网络图。

rm(list = ls(all=TRUE))    
graphics.off()
library(readxl)
library(igraph)
library(threejs)

NTWVD <- read_excel("C:/Users/Mihan/Dropbox/DataCamp/R/Network_Analysis/NTWVD.xlsx")
NT.mat<-as.matrix(NTWVD)
NT1.mat<-NT.mat[,1:2]

g<-graph.edgelist(NT1.mat, directed=FALSE)

g<-set_vertex_attr(g, "color", value=c("red","blue","green","red","green","red","green","green","green","green","green","yellow","yellow","yellow","yellow","yellow","blue","yellow","red","black","black","black","black","black","black","red","red","blue","blue","blue","blue"))

graphjs(g,vertex.size = 1, showLabels=TRUE)

graphjs(g, main = "", curvature = 0, bg = "white",
        fg = "black", showLabels = TRUE, attraction = 1, repulsion = 1,
        max_iterations = 1500, opacity = 1, stroke = TRUE, width = NULL,
        height = NULL)

我有一个漂亮的互动情节。但我没有在顶点上看到任何标签。我在这个数据中有两列。顶点1和顶点2。 请告知我如何在图中的顶点上显示标签?

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。我找到了解决方案herehere。我理解在你的情况下解决方案是:

graphjs(g, main = "", curvature = 0, bg = "white",
        fg = "black", showLabels = TRUE, attraction = 1, repulsion = 1,
        max_iterations = 1500, opacity = 1, stroke = TRUE, width = NULL,
        height = NULL)%>%points3d(vertices(.), color="red",pch=V(g)$label,size=0.1)