0

I am making 4 correlation networks representing plant traits under different treatments. Two are now perfect. Evidently the code works. The four underlying matrices have an identical structure (just different numbers). When trying to plot the two final networks I get an error

Error in structure(.External("dotTclObjv", objv, PACKAGE = "tcltk"), class = "tclObj") : [tcl] bad screen distance "NaN(7a2)".

The code used is the same as for the two networks that do plot, so is the structure of the underlying matrix. Just the matrix is different. Everything else is an exact copy, with only a change in matrix-name.

I can't find what this specific error means; not here, not on google. I also don't know what causes it or what a solution might be. I hope you have an idea.

This is the code for a graph that does plot

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)

and here is the code for a graph that returns the error

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)

As said, I only changed the underlying matrix (from Y1W to 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)
The Riddler
  • 51
  • 1
  • 3
  • What happens when you try `plot` rather than `tkplot`? – Vincent Guillemot Aug 06 '14 at 15:49
  • Well, we would need some data to reproduce this. Something is messed up, either in `graphY1H` (probably some attribute value `tkplot` cannot interpret), or in the `tkplot` code. In any case, please share the data with us. (Or some small subset of it that reproduces the issue.) – Gabor Csardi Aug 07 '14 at 04:15
  • 'plot' works for all 4 networks, 'tkplot' for 2. I added the code for graph Y1H, but how to add data? – The Riddler Aug 07 '14 at 06:08
  • And the data added as well. Probably not the way it should be done... – The Riddler Aug 07 '14 at 06:58
  • See the following for how to add the data: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Gabor Csardi Aug 08 '14 at 03:43
  • Ok. Thanks. So, following the examples you provided, now both the code I used and the data should be correctly added in this post. As said before, the problem occurs in the 'tkplot' lines. – The Riddler Aug 08 '14 at 08:44
  • The advice I got here internally is that this is a highly package-specific problem; a bug. Is it really? – The Riddler Aug 11 '14 at 07:23

1 Answers1

0

The cause of the problem here turns out to be in the underlying matrices. They are identical, but in both 'heating matrices' correlations below |*.500| appear. Both taking such values out and adding some lines to the code defining what to do with such values allows tkplot to function properly. Apparently tkplot needs such definitions, where plot doesn't.

The Riddler
  • 51
  • 1
  • 3