两个相同的代码,1个图形和1个错误

时间:2014-08-06 15:18:57

标签: r igraph tkplot

我正在制作4个相关网络,代表不同处理下的植物性状。两个现在完美。显然代码有效。四个底层矩阵具有相同的结构(只是不同的数字)。当试图绘制两个最终网络时,我得到一个错误

结构错误(.External(“dotTclObjv”,objv,PACKAGE =“tcltk”),class =“tclObj”):   [tcl]屏幕距离不好“NaN(7a2)”。

使用的代码与绘制的两个网络的代码相同,底层矩阵的结构也是如此。只是矩阵是不同的。其他所有内容都是精确副本,只需更改矩阵名称。

我找不到这个具体错误的含义;不在这里,不在谷歌上。我也不知道是什么导致它或解决方案可能是什么。我希望你有个主意。

这是绘制图表的代码

tkplot(graphY1W,canvas.width=800, canvas.height=800,layout=layout.fruchterman.reingold,  edge.lty=E(graphlty), vertex.color=V(graphY1W)$color,
     vertex.label.color="black", vertex.shape="circle",vertex.size=30, vertex.label.cex=1.3,
     vertex.label.family = "arial", asp=0.5, frame=FALSE)

以下是返回错误

的图表的代码
tkplot(graphY1H,canvas.width=800, canvas.height=800,layout=layout.fruchterman.reingold, edge.lty=E(graphlty), vertex.color=V(graphY1H)$color,
       vertex.label.color="black", vertex.shape="circle",vertex.size=30, vertex.label.cex=1.3,
       vertex.label.family = "arial", asp=0.5, frame=FALSE)

如上所述,我只改变了基础矩阵(从Y1W到Y1H)....

Y1H <-structure(c(1, 1.659121936, 1.683574156, -1.636071881, 1.734576395, 
0, 0, 1.910109335, 1.874007899, 1.82812604, 0, -1.694062621, 
0, 0, -1.593250746, 1.616738344, -2.601817743, 1.659121936, 1, 
1.88073058, -1.917663654, 2.524210889, 3.590160511, 0, 1.445638937, 
1.459362536, 1.78435537, 0, 0, 0, 0, 0, 0, 0, 1.683574156, 1.88073058, 
1, -1.936450937, 1.547794218, 3.661020921, 0, 2.47583749, 2.436913725, 
1.700847971, 0, 0, 0, 0, 0, 0, 0, -1.636071881, -1.917663654, 
-1.936450937, 1, -2.519539383, -3.48562769, 0, -2.445003751, 
-1.432910302, -1.718333159, 0, 0, 0, 0, 0, 0, 0, 1.734576395, 
2.524210889, 1.547794218, -2.519539383, 1, 0, 0, 1.684661311, 
1.716303539, 1.836987732, 0, -1.64143162, 0, 0, -3.640394701, 
1.657415967, -2.421877362, 0, 3.590160511, 3.661020921, -3.48562769, 
0, 1, 0, 0, 0, 1.517975677, 3.504422601, 0, 0, -1.734362255, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1.707442895, 
0, 0, 0, 1.910109335, 1.445638937, 2.47583749, -2.445003751, 
1.684661311, 0, 0, 1, 1.990035081, 3.6916112, 0, -1.766952815, 
-2.504601913, 0, -1.555039314, 1.68010264, -2.590319613, 1.874007899, 
1.459362536, 2.436913725, -1.432910302, 1.716303539, 0, 0, 1.990035081, 
1, 3.718065616, 0, -1.801899401, -2.497498974, 0, -1.5664764, 
1.701880341, -2.563625037, 1.82812604, 1.78435537, 1.700847971, 
-1.718333159, 1.836987732, 1.517975677, 0, 3.6916112, 3.718065616, 
1, 0, -3.541412556, 0, 0, -3.62446497, 1.673455721, 0, 0, 0, 
0, 0, 0, 3.504422601, 0, 0, 0, 0, 1, 3.406858939, 0, -3.621786424, 
1.606578292, 0, 0, -1.694062621, 0, 0, 0, -1.64143162, 0, 0, 
-1.766952815, -1.801899401, -3.541412556, 3.406858939, 1, 1.6832198, 
-1.550641628, 1.85684289, -1.812309146, 2.516258633, 0, 0, 0, 
0, 0, 0, 0, -2.504601913, -2.497498974, 0, 0, 1.6832198, 1, 0, 
1.648655514, -1.55441377, 0, 0, 0, 0, 0, 0, -1.734362255, 1.707442895, 
0, 0, 0, -3.621786424, -1.550641628, 0, 1, 0, 0, 0, -1.593250746, 
0, 0, 0, -3.640394701, 0, 0, -1.555039314, -1.5664764, -3.62446497, 
1.606578292, 1.85684289, 1.648655514, 0, 1, -1.824735792, 2.535308857, 
1.616738344, 0, 0, 0, 1.657415967, 0, 0, 1.68010264, 1.701880341, 
1.673455721, 0, -1.812309146, -1.55441377, 0, -1.824735792, 1, 
-2.444738599, -2.601817743, 0, 0, 0, -2.421877362, 0, 0, -2.590319613, 
-2.563625037, 0, 0, 2.516258633, 0, 0, 2.535308857, -2.444738599, 
1), .Dim = c(17L, 17L), .Dimnames = list(NULL, c("Pn", "gs", 
"Pn_amb.Pn_sat", "WUE", "WP", "TL", "FMDM", "Chl", "Car", "Chlab", 
"MP", "LMF", "SRR", "SLAP", "AP", "NAR", "RGR")))    
graphY1H<-graph.adjacency(Y1H,weighted=TRUE,mode="undirected",diag=FALSE)
    E(graphY1H)[weight > -4.0 & weight < -3.75]$color <- "black" 
    E(graphY1H)[weight >= -3.75 & weight <= -3.5]$color <- "black"
    E(graphY1H)[weight <  4.0 & weight > 3.75]$color <- "grey"
    E(graphY1H)[weight <= 3.75 & weight >= 3.5]$color <- "grey"
    E(graphY1H)[weight > -3.0 & weight < -2.75]$color <- "black" 
    E(graphY1H)[weight >= -2.75 & weight <= -2.5]$color <- "black"
    E(graphY1H)[weight <  3.0 & weight > 2.75]$color <- "grey"
    E(graphY1H)[weight <= 2.75 & weight >= 2.5]$color <- "grey"
    E(graphY1H)[weight > -2.0 & weight < -1.75]$color <- "black" 
    E(graphY1H)[weight >= -1.75 & weight <= -1.5]$color <- "black"
    E(graphY1H)[weight < 2.0 & weight >  1.75]$color <- "grey"
    E(graphY1H)[weight <= 1.75 & weight >= 1.5]$color <- "grey"

    E(graphY1H)[weight > -4.0 & weight < -3.75]$width <- 7
    E(graphY1H)[weight >= -3.75 & weight <= -3.5]$width <- 3
    E(graphY1H)[weight <  4.0 & weight > 3.75]$width <- 7
    E(graphY1H)[weight <= 3.75 & weight >= 3.5]$width <- 3
    E(graphY1H)[weight > -3.0 & weight < -2.75]$width <- 7
    E(graphY1H)[weight >= -2.75 & weight <= -2.5]$width <- 3
    E(graphY1H)[weight <  3.0 & weight > 2.75]$width <- 7
    E(graphY1H)[weight <= 2.75 & weight >= 2.5]$width <- 3
    E(graphY1H)[weight > -2.0 & weight < -1.75]$width <- 7
    E(graphY1H)[weight >= -1.75 & weight <= -1.5]$width <- 3
    E(graphY1H)[weight < 2.0 & weight >  1.75]$width <- 7
    E(graphY1H)[weight <= 1.75 & weight >= 1.5]$width <- 3

    graphlty<-graph.adjacency(Y1H,weighted=TRUE,mode="undirected",diag=FALSE)
    E(graphlty)[weight > -4.0 & weight < -3.75]$lty <- 1
    E(graphlty)[weight >= -3.75 & weight <= -3.5]$lty <- 1
    E(graphlty)[weight <  4.0 & weight > 3.75]$lty <- 1
    E(graphlty)[weight <= 3.75 & weight >= 3.5]$lty <- 1
    E(graphlty)[weight > -3.0 & weight < -2.75]$lty <- 3
    E(graphlty)[weight >= -2.75 & weight <= -2.5]$lty <- 3
    E(graphlty)[weight <  3.0 & weight > 2.75]$lty <- 3
    E(graphlty)[weight <= 2.75 & weight >= 2.5]$lty <- 3
    E(graphlty)[weight > -2.0 & weight < -1.75]$lty <- 4
    E(graphlty)[weight >= -1.75 & weight <= -1.5]$lty <- 4
    E(graphlty)[weight < 2.0 & weight >  1.75]$lty <- 4
    E(graphlty)[weight <= 1.75 & weight >= 1.75]$lty <- 4

    V(graphY1H)$color <-  ifelse(V(graphY1H)$name=="Pn", "grey",
                          ifelse(V(graphY1H)$name=="gs", "grey",
                          ifelse(V(graphY1H)$name=="Pn_a.s", "grey",
                          ifelse(V(graphY1H)$name=="WUE", "grey",
                          ifelse(V(graphY1H)$name=="WP", "grey",
                          ifelse(V(graphY1H)$name=="TL", "grey95",
                          ifelse(V(graphY1H)$name=="FMDM", "grey95",
                          ifelse(V(graphY1H)$name=="Chl", "grey45",
                          ifelse(V(graphY1H)$name=="Chlab", "grey45",
                          ifelse(V(graphY1H)$name=="Car", "grey45",
                          ifelse(V(graphY1H)$name=="Mp", "white",
                          ifelse(V(graphY1H)$name=="LMF", "white",
                          ifelse(V(graphY1H)$name=="SRR", "white",
                          ifelse(V(graphY1H)$name=="SLAp", "grey95",
                          ifelse(V(graphY1H)$name=="Ap", "grey95",
                          ifelse(V(graphY1H)$name=="NAR", "white",
                          ifelse(V(graphY1H)$name=="RGR", "white","white")))))))))))))))))

    tkplot(graphY1H,canvas.width=800, canvas.height=800,layout=layout.fruchterman.reingold, edge.lty=E(graphlty), vertex.color=V(graphY1H)$color,
           vertex.label.color="black", vertex.shape="circle",vertex.size=30, vertex.label.cex=1.3,
           vertex.label.family = "arial", asp=0.5, frame=FALSE)

1 个答案:

答案 0 :(得分:0)

问题的原因在于底层矩阵。它们是相同的,但在两个加热矩阵中都是相同的。相关性如下| * .500 |出现。两者都取出这些值并在代码中添加一些行来定义如何处理这些值,这使得tkplot能够正常运行。显然tkplot需要这样的定义,其中情节没有。