本文介绍了forceNetwork不显示,没有返回代码错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我创建一个networkD3 forceNetwork(),但在我清除我的env vars在RStudio网络将不会显示在我的浏览器,当我第二次运行代码。任何想法为什么?无代码错误。 Var输出低于 库(networkD3)库\\Users\\King\\Desktop\\SNA_Rcode) csv df< -data.frame(csv $ stat.deaths,csv [,4],csv $ stat.mob)#damage delt死亡,暴徒杀死(是颜色)#2模式。交互模型#g1< - simpleNetwork(df); htmltools :: html_print(g1,viewer = utils :: browseURL)#DISPLAYS CORRECTLY df< - df [!duplicate(df [,2]),] df [,2] paste(,df [,2],sep =) #setup g links< data.frame(get.edgelist(g))#set名称到数字,以便正确计算链接 links $ V1&-11.numeric(as.character(links $ V1)) links $ V2& -as.numeric(as.character(links $ V2)) colnames(links)< -c(source,target) link_list< ;-( links-1) ####################### DOESNT WORK LIKE EXPECTED ......用2而不是999替换NA color_groups color_groups ifelse(as.numeric(color_groups)> = 30, 2)) color_groups [is.na(color_groups)]< -999 #replace NA with 999 names< -0:(length(color_groups)-1) node_list profanity< -forceNetwork(Links = link_list,Nodes = node_list,Source =source,Target =target =name,Group =group,opacity = 0.8,colourScale =d3.scale.category10(),charge = -100) htmltools :: html_print(profanity,viewer = utils :: browseURL) 运行所有上述代码后(使用clear env): > head(link_list,20)源目标 1 6 1169 2 1 839 3 1 2594 4 7 5409 5 11 2719 6 5 1719 7 7 179 8 2 1989 9 4 3444 10 0 2249 11 1 1964 12 0 3344 13 6 4479 14 6 2224 15 7 3869 16 5 2459 17 3 1704 18 -1 2479 19 5 3494 20 4 1869 > head(node_list,20)名称组 1 0 2 2 1 1 3 2 2 4 3 3 5 4 1 6 5 2 7 6 1 8 7 2 9 8 2 10 9 2 11 10 1 12 11 2 13 12 2 14 13 2 15 14 2 16 15 2 17 16 2 18 17 2 19 18 2 20 19 2 解决方案我需要设置顶点的名称使用: V(g)$ name pre> 初始化图形(g) I am creating a networkD3 forceNetwork(), but after I cleared my env vars in RStudio the network would not display in my browser when I ran the code a second time. Any idea why? No code errors. Var output is below.library(networkD3)library(igraph)setwd("C:\\Users\\King\\Desktop\\SNA_Rcode")csv<-read.csv("C:\\Users\\King\\Desktop\\Analysis\\mc_with_0_and_MI.csv")df<-data.frame(csv$stat.deaths,csv[,4],csv$stat.mob)#damage delt on deaths, mob kills (is color)#2 mode. interactive model#g1 <- simpleNetwork(df) ; htmltools::html_print(g1, viewer = utils::browseURL)#DISPLAYS CORRECTLYdf <- df[!duplicated(df[,2]),]df[,2] <- paste("", df[,2], sep="")#setupg <- graph.data.frame(df,directed=F)links<-as.data.frame(get.edgelist(g)) #set name to number so calculate link correctlylinks$V1<-as.numeric(as.character(links$V1))links$V2<-as.numeric(as.character(links$V2))colnames(links)<-c("source","target")link_list<-(links-1)#######################DOESNT WORK LIKE EXPECTED......replaces NA with 2 instead of 999color_groups<-df[,3]# color based on mob killscolor_groups <- ifelse(as.numeric(color_groups) < 10, 1, ifelse(as.numeric(color_groups) >= 30, 3, 2))color_groups[is.na(color_groups)]<-999 #replace NA with 999names<-0:(length(color_groups)-1)node_list <- data.frame(name=names, group=color_groups)profanity<-forceNetwork(Links = link_list, Nodes = node_list,Source = "source", Target = "target", NodeID = "name",Group = "group", opacity = 0.8, colourScale = "d3.scale.category10()",charge=-100)htmltools::html_print(profanity, viewer = utils::browseURL)After running all the above code (with a clear env): > head(link_list,20) source target 1 6 1169 2 1 839 3 1 2594 4 7 5409 5 11 2719 6 5 1719 7 7 179 8 2 1989 9 4 3444 10 0 2249 11 1 1964 12 0 3344 13 6 4479 14 6 2224 15 7 3869 16 5 2459 17 3 1704 18 -1 2479 19 5 3494 20 4 1869> head(node_list,20) name group1 0 22 1 13 2 24 3 35 4 16 5 27 6 18 7 29 8 210 9 211 10 112 11 213 12 214 13 215 14 216 15 217 16 218 17 219 18 220 19 2 解决方案 I needed to set the names for the vertices using:V(g)$name<-1:104after I initialized the graph (g) 这篇关于forceNetwork不显示,没有返回代码错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-09 08:45