Error in check.length(gparname) : 'gpar' element 'lwd' must not be length 0
danli349 opened this issue · comments
Dan Li commented
Hello:
I tried the following code in Rstudio:
library(igraph)
library(ggraph)
set.seed(1)
adj <- matrix(rbinom(900, 1, 0.02) * runif(900, -1, 1), 30,
dimnames = list(paste('node', 1:30),
paste('node', 1:30)))
graph <- graph.adjacency(adj, weighted = TRUE)
ggraph(graph, layout = 'linear', circular = TRUE) +
geom_edge_arc(aes(color = weight, size = abs(weight))) +
geom_node_text(aes(label = name, angle = node_angle(x, y)), hjust = -0.5) +
geom_node_point(shape = 21, size = 4, aes(fill = name)) +
theme_graph() +
scale_edge_color_gradientn(colours = c('red4', 'gold', 'green4')) +
coord_fixed(xlim = c(-1.4, 1.4), ylim = c(-1.4, 1.4)) +
guides(fill = guide_none())
but there is an error:
Error in check.length(gparname) :
'gpar' element 'lwd' must not be length 0
can you please let me know what is the problem? Thanks
David Schoch commented
There was a recent update of ggplot2, which underlies ggraph. For me, your code runs, but there is still a warning that probably shouldn't be there
library(igraph)
library(ggraph)
packageVersion("igraph")
#> [1] '1.3.5'
packageVersion("ggraph")
#> [1] '2.1.0'
packageVersion("ggplot2")
#> [1] '3.4.0'
set.seed(1)
adj <- matrix(rbinom(900, 1, 0.02) * runif(900, -1, 1), 30,
dimnames = list(paste('node', 1:30),
paste('node', 1:30)))
graph <- graph.adjacency(adj, weighted = TRUE)
ggraph(graph, layout = 'linear', circular = TRUE) +
geom_edge_arc(aes(color = weight, edge_linewidth = abs(weight))) +
geom_node_text(aes(label = name, angle = node_angle(x, y)), hjust = -0.5) +
geom_node_point(shape = 21, size = 4, aes(fill = name)) +
theme_graph() +
scale_edge_color_gradientn(colours = c('red4', 'gold', 'green4')) +
coord_fixed(xlim = c(-1.4, 1.4), ylim = c(-1.4, 1.4)) +
guides(fill = guide_none())
#> Warning: Using the `size` aesthetic in this geom was deprecated in ggplot2 3.4.0.
#> ℹ Please use `linewidth` in the `default_aes` field and elsewhere instead.
Created on 2023-02-07 with reprex v2.0.2
Dan Li commented
@schochastics Thanks I updated ggraph
now it works.
packageVersion("igraph")
#> [1] '1.3.5'
packageVersion("ggraph")
#> [1] '2.1.0'
packageVersion("ggplot2")
#> [1] '3.4.0'