Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geom_edge_link(aes(width = weight)) doesn't change width #144

Closed
rdrr1990 opened this issue Jun 17, 2018 · 7 comments
Closed

geom_edge_link(aes(width = weight)) doesn't change width #144

rdrr1990 opened this issue Jun 17, 2018 · 7 comments

Comments

@rdrr1990
Copy link

rdrr1990 commented Jun 17, 2018

Hi,
New user to ggraph, which seems great! However, when I call geom_edge_link(aes(width = weight)), the edge widths don't change and a scale/legend does not appear on the right. I ran into this issue on my own data but here is a minimal reproducible example of the error adapted from Jesse Sadler's demo.

library(tidyverse)
library(tidygraph)
library(ggraph)

letters <- read_csv("https://raw.githubusercontent.com/jessesadler/intro-to-r/master/data/correspondence-data-1585.csv")

sources <- letters %>%
  distinct(source) %>%
  rename(label = source)

destinations <- letters %>%
  distinct(destination) %>%
  rename(label = destination)

nodes <- full_join(sources, destinations, by = "label")
nodes <- nodes %>% rowid_to_column("id")

per_route <- letters %>%  
  group_by(source, destination) %>%
  summarise(weight = n()) %>% 
  ungroup()

edges <- per_route %>% 
  left_join(nodes, by = c("source" = "label")) %>% 
  rename(from = id)
edges <- edges %>% 
  left_join(nodes, by = c("destination" = "label")) %>% 
  rename(to = id)
edges <- select(edges, from, to, weight)

routes_tidy <- tbl_graph(nodes = nodes, edges = edges, directed = TRUE)
routes_tidy <- routes_tidy %>% 
  activate(edges) %>% 
  arrange(desc(weight))

ggraph(routes_tidy, layout = "graphopt") + 
  geom_node_point() +
  geom_edge_link(aes(width = weight), alpha = 0.8) + 
  scale_edge_width(range = c(0.2, 2)) +
  geom_node_text(aes(label = label), repel = TRUE) +
  labs(edge_width = "Letters") +
  theme_graph()

Without error, warning, or message that code produces:
image

But the look I'm after is:
image

(aes() is finding the variable called weight as, for example, changing the key line to geom_edge_link(aes(width = weight123), alpha = 0.8) produces Error in FUN(X[[i]], ...) : object 'weight123' not found.)

Any thoughts as to what might be going on or possible workarounds? Many thanks in advance! Here are some package details...

─ Session info ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.5.0 (2018-04-23)
 os       macOS Sierra 10.12.6        
 system   x86_64, darwin15.6.0        
 ui       RStudio                     
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       America/Los_Angeles         
 date     2018-06-17                  

─ Packages ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version date       source        
 assertthat    0.2.0   2017-04-11 CRAN (R 3.5.0)
 bindr         0.1.1   2018-03-13 CRAN (R 3.5.0)
 bindrcpp    * 0.2.2   2018-03-29 CRAN (R 3.5.0)
 broom         0.4.4   2018-03-29 CRAN (R 3.5.0)
 cellranger    1.1.0   2016-07-27 CRAN (R 3.5.0)
 cli           1.0.0   2017-11-05 CRAN (R 3.5.0)
 clisymbols    1.2.0   2017-05-21 CRAN (R 3.5.0)
 colorspace    1.3-2   2016-12-14 CRAN (R 3.5.0)
 crayon        1.3.4   2017-09-16 CRAN (R 3.5.0)
 curl          3.2     2018-03-28 CRAN (R 3.5.0)
 digest        0.6.15  2018-01-28 CRAN (R 3.5.0)
 dplyr       * 0.7.5   2018-05-19 CRAN (R 3.5.0)
 forcats     * 0.3.0   2018-02-19 CRAN (R 3.5.0)
 foreign       0.8-70  2017-11-28 CRAN (R 3.5.0)
 ggforce       0.1.2   2018-05-27 CRAN (R 3.5.0)
 ggplot2     * 2.2.1   2016-12-30 CRAN (R 3.5.0)
 ggraph      * 1.0.1   2018-01-29 CRAN (R 3.5.0)
 ggrepel       0.8.0   2018-05-09 CRAN (R 3.5.0)
 glue          1.2.0   2017-10-29 CRAN (R 3.5.0)
 gridExtra     2.3     2017-09-09 CRAN (R 3.5.0)
 gtable        0.2.0   2016-02-26 CRAN (R 3.5.0)
 haven         1.1.1   2018-01-18 CRAN (R 3.5.0)
 hms           0.4.2   2018-03-10 CRAN (R 3.5.0)
 httr          1.3.1   2017-08-20 CRAN (R 3.5.0)
 igraph        1.2.1   2018-03-10 CRAN (R 3.5.0)
 jsonlite      1.5     2017-06-01 CRAN (R 3.5.0)
 labeling      0.3     2014-08-23 CRAN (R 3.5.0)
 lattice       0.20-35 2017-03-25 CRAN (R 3.5.0)
 lazyeval      0.2.1   2017-10-29 CRAN (R 3.5.0)
 lubridate     1.7.4   2018-04-11 CRAN (R 3.5.0)
 magrittr      1.5     2014-11-22 CRAN (R 3.5.0)
 MASS          7.3-49  2018-02-23 CRAN (R 3.5.0)
 mnormt        1.5-5   2016-10-15 CRAN (R 3.5.0)
 modelr        0.1.2   2018-05-11 CRAN (R 3.5.0)
 munsell       0.4.3   2016-02-13 CRAN (R 3.5.0)
 nlme          3.1-137 2018-04-07 CRAN (R 3.5.0)
 pillar        1.2.3   2018-05-25 CRAN (R 3.5.0)
 pkgconfig     2.0.1   2017-03-21 CRAN (R 3.5.0)
 plyr          1.8.4   2016-06-08 CRAN (R 3.5.0)
 psych         1.8.4   2018-05-06 CRAN (R 3.5.0)
 purrr       * 0.2.5   2018-05-29 CRAN (R 3.5.0)
 R6            2.2.2   2017-06-17 CRAN (R 3.5.0)
 Rcpp          0.12.17 2018-05-18 CRAN (R 3.5.0)
 readr       * 1.1.1   2017-05-16 CRAN (R 3.5.0)
 readxl        1.1.0   2018-04-20 CRAN (R 3.5.0)
 reshape2      1.4.3   2017-12-11 CRAN (R 3.5.0)
 rlang         0.2.1   2018-05-30 CRAN (R 3.5.0)
 rstudioapi    0.7     2017-09-07 CRAN (R 3.5.0)
 rvest         0.3.2   2016-06-17 CRAN (R 3.5.0)
 scales        0.5.0   2017-08-24 CRAN (R 3.5.0)
 sessioninfo   1.0.0   2017-06-21 CRAN (R 3.5.0)
 stringi       1.2.2   2018-05-02 CRAN (R 3.5.0)
 stringr     * 1.3.1   2018-05-10 CRAN (R 3.5.0)
 tibble      * 1.4.2   2018-01-22 CRAN (R 3.5.0)
 tidygraph   * 1.1.0   2018-02-10 CRAN (R 3.5.0)
 tidyr       * 0.8.1   2018-05-18 CRAN (R 3.5.0)
 tidyselect    0.2.4   2018-02-26 CRAN (R 3.5.0)
 tidyverse   * 1.2.1   2017-11-14 CRAN (R 3.5.0)
 tweenr        0.1.5   2016-10-10 CRAN (R 3.5.0)
 units         0.6-0   2018-06-09 CRAN (R 3.5.0)
 viridis       0.5.1   2018-03-29 CRAN (R 3.5.0)
 viridisLite   0.3.0   2018-02-01 CRAN (R 3.5.0)
 withr         2.1.2   2018-03-15 CRAN (R 3.5.0)
 xml2          1.2.0   2018-01-24 CRAN (R 3.5.0)
 yaml          2.1.19  2018-05-01 CRAN (R 3.5.0)
@thomasp85
Copy link
Owner

Probably related to #142

This is something super weird that has began happening - I begin to think that it might be something in R v3.5 and how scales are found in ggplot2

@rdrr1990
Copy link
Author

can confirm--code works as intended using fresh installs of all packages required above on another laptop that still has R 3.3.3. thx!

@thomasp85
Copy link
Owner

This turned out to be a regression in the latest ggforce release... Installing ggforce from GitHub will solve it (I'll work on making a hotfix for the cran version as well, as the next proper ggforce release is some time away)

@acpguedes
Copy link

I'm still getting exactly the same issue even with the most recent version of ggforce, ggraph, and ggplot an R itself.

R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.5 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] graphlayouts_0.7.0   ggforce_0.3.2.9000   ggraph_2.0.2.9000    tidygraph_1.2.0.9000 igraph_1.2.5        
 [6] forcats_0.5.0        stringr_1.4.0        dplyr_1.0.2.9000     purrr_0.3.4          readr_1.3.1         
[11] tidyr_1.1.2.9000     tibble_3.0.3         ggplot2_3.3.2.9000   tidyverse_1.3.0.9000

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.0  haven_2.3.1       colorspace_1.4-1  vctrs_0.3.4       generics_0.0.2    viridisLite_0.3.0
 [7] blob_1.2.1        rlang_0.4.7       pillar_1.4.6      glue_1.4.2        withr_2.3.0       DBI_1.1.0        
[13] tweenr_1.0.1      dbplyr_1.4.4      modelr_0.1.8      readxl_1.3.1      lifecycle_0.2.0   munsell_0.5.0    
[19] gtable_0.3.0      cellranger_1.1.0  rvest_0.3.6       labeling_0.3      fansi_0.4.1       broom_0.7.0      
[25] Rcpp_1.0.5        scales_1.1.1      backports_1.1.10  jsonlite_1.7.0    farver_2.0.3      fs_1.4.2         
[31] gridExtra_2.3     hms_0.5.3         digest_0.6.25     stringi_1.4.6     ggrepel_0.8.2     polyclip_1.10-0  
[37] grid_4.0.2        cli_2.0.2         tools_4.0.2       magrittr_1.5      crayon_1.3.4      pkgconfig_2.0.3  
[43] ellipsis_0.3.1    MASS_7.3-53       xml2_1.3.2        reprex_0.3.0      lubridate_1.7.9   viridis_0.5.1    
[49] assertthat_0.2.1  httr_1.4.2        rstudioapi_0.11   R6_2.4.1          compiler_4.0.2

@mnakaya5
Copy link

@acpguedes Did you solve this issue? I am facing the same. Would it be possible for you to share how to solve it?

@acpguedes
Copy link

Hi @mnakaya5,

I reinstalled ggraph from github devtools::install_github("thomasp85/ggraph") and it worked fine.

library(igraph)
#> 
#> Attaching package: 'igraph'
#> The following objects are masked from 'package:stats':
#> 
#>     decompose, spectrum
#> The following object is masked from 'package:base':
#> 
#>     union
library(ggraph)
#> Loading required package: ggplot2

g <- erdos.renyi.game(n = 20, p.or.m=0.5)
E(g)$w <- runif(length(E(g)))*20

ggraph(g, layout="stress") + 
  geom_edge_link(aes(width=w)) +
  scale_edge_width(c(0.2, 2)) +
  theme_graph()

Created on 2021-03-17 by the reprex package (v0.3.0)

But I think the scale_edge_width needs to refine because changes in the code don't change the appearance of the links.

E(g)$w <- runif(length(E(g))) * 1000

ggraph(g, layout="stress") + 
  geom_node_point() +
  geom_edge_link(aes(width=w)) +
  scale_edge_width(c(0.2, 1000)) +
  theme_graph()

@mnakaya5
Copy link

mnakaya5 commented Mar 18, 2021

Hello, @acpguedes
Thank you for sharing your practice, however, unfortunately, it didn't work after reinstalled from Github. Maybe is it because of widows? I have no idea right now and try to get other information more. If any additional idea of the cause of this issue, it would be very helpful. Many thanks.

sessionInfo()
R version 4.0.4 (2021-02-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
system code page: 932

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] ggforce_0.3.3 ggplot2_3.3.3

loaded via a namespace (and not attached):
[1] tinytex_0.30 tidyselect_1.1.0 xfun_0.22 remotes_2.2.0
[5] purrr_0.3.4 colorspace_2.0-0 vctrs_0.3.6 generics_0.1.0
[9] testthat_3.0.2 usethis_2.0.1 utf8_1.2.1 rlang_0.4.10
[13] pkgbuild_1.2.0 pillar_1.5.1 glue_1.4.2 withr_2.4.1
[17] DBI_1.1.1 tweenr_1.0.1 RColorBrewer_1.1-2 sessioninfo_1.1.1
[21] lifecycle_1.0.0 munsell_0.5.0 gtable_0.3.0 devtools_2.3.2
[25] memoise_2.0.0 callr_3.5.1 fastmap_1.1.0 ps_1.6.0
[29] curl_4.3 fansi_0.4.2 Rcpp_1.0.6 scales_1.1.1
[33] cachem_1.0.4 desc_1.3.0 pkgload_1.2.0 farver_2.1.0
[37] fs_1.5.0 processx_3.4.5 dplyr_1.0.5 polyclip_1.10-0
[41] rprojroot_2.0.2 grid_4.0.4 cli_2.3.1 tools_4.0.4
[45] magrittr_2.0.1 tibble_3.1.0 crayon_1.4.1 pkgconfig_2.0.3
[49] ellipsis_0.3.1 MASS_7.3-53 prettyunits_1.1.1 assertthat_0.2.1
[53] rstudioapi_0.13 R6_2.5.0 igraph_1.2.6 compiler_4.0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants