SachaEpskamp / qgraph

Developmental version of qgraph
GNU General Public License v2.0
68 stars 21 forks source link

Centrality plot not generated #6

Closed DevMui closed 5 years ago

DevMui commented 7 years ago

Hello,

I was trying to create a centrality plot by referring your tutorial (http://sachaepskamp.com/files/Cookbook.html) especially for centralityPlot however all of the functions gave me the following error:

Error in combine_vars(data, params$plot_env, cols, drop = params$drop) : 
  At least one layer must contain all variables used for facetting

As I looked into centralityPlot.R, especially for facettinng part, it was using graph and measure as facetting variables. centralityPlot.R

  if (length(unique(Long$graph)) > 1)
  {
    g <- g + facet_grid(graph ~ measure, scales = "free") 
  } else 
  {
    g <- g + facet_grid( ~ measure, scales = "free") 
  }

However, as I looked into it, the centralityTable Long does not seem to have the measure columm.

> names(Long)
[1] "graph"    "type"     "node"     "variable" "value"  

Here's the function definition of melt which does not seem to be accepting variable.name that you specified in centralityTable.

reshape2::melt

melt(data, ..., na.rm = FALSE, value.name = "value")

centralityTable.R

  # LONG FORMAT:
  LongCent <- reshape2::melt(WideCent, variable.name = "measure", id.var = c("graph","type", "node"))

So I changed the measure in the centralityPlot to variable which solved the problem. I opened a merge request - or you may revise it by yourself. I hope this helps.

revised centralityPlot.R

  if (length(unique(Long$graph)) > 1)
  {
    g <- g + facet_grid(graph ~ variable, scales = "free") 
  } else 
  {
    g <- g + facet_grid( ~ variable, scales = "free") 
  }

devmui

SachaEpskamp commented 5 years ago

I think this has been resolved by now? Sorry for the late reply on this. I'll close for now but please let me know if it hasn't been resolved.