Ggraph: Weight must be numeric error

Created on 15 Feb 2020  路  4Comments  路  Source: thomasp85/ggraph

Hi,
I'm having problems using vertex/leaf weights - always returning the error "Weight must be numeric".

Setting up a graph using igraph:

library(ggraph)
library(igraph)
edges <- flare$edges
vertices <- flare$vertices
mygraph <- graph_from_data_frame(edges, vertices=vertices)

The data type of vertices$size is numeric:

> is.numeric(vertices$size)
[1] TRUE

However, attempting to plot the graph using ggraph reports that size is not numeric:

> ggraph(mygraph, layout = 'circlepack', weight = 'size')
Error in tree_to_hierarchy(graph, direction, sort.by, weight) :
  Weight must be numeric

Is this an issue or am I just going about this the wrong way? I'm using R 3.4.4 in the Ubuntu linux subsystem for Windows 10

Most helpful comment

Maybe unquote 'size'? (weight = size). Works for me, sometimes..

All 4 comments

Maybe unquote 'size'? (weight = size). Works for me, sometimes..

Ah, brilliant! That worked, any idea why though?

Many inputs to layouts are tidy evaluated and must given as unquoted expressions. This is given in the documentation

Just ran into this problem today, too. Think this is because we are following the snippet in holtzy's very nice R-graph-gallery (https://www.r-graph-gallery.com/313-basic-circle-packing-with-several-levels.html).

Just opened a pull request against the r-graph-gallery repo, so hopefully no one else will hit this one.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jalapic picture jalapic  路  3Comments

jas1 picture jas1  路  14Comments

Jim89 picture Jim89  路  7Comments

zhuxr11 picture zhuxr11  路  7Comments

jhrcook picture jhrcook  路  3Comments