briatte / ggnetwork

Geoms to plot networks with ggplot2
https://briatte.github.io/ggnetwork/
146 stars 28 forks source link

'Stat' not found if ggnetwork not loaded #14

Closed trinker closed 4 years ago

trinker commented 7 years ago

Great package! Thanks for the work.

I want to use ggnetwork in a package meaning it is not loaded explicitly. When I try to use the functions I get the message:

Error in eval(expr, envir, enclos) : object 'Stat' not found

I can make everything work if I load ggplot2 interactively but that's not a real fix because the package doesn't load ggplot, just imports it and ggnetwork. I suspect you need to explicitly import Stat from ggplot2...something like importFrom ggplot2 layer GeomPoint Stat but this is unconfirmed

MWE

idat <- structure(list(x = structure(c(0.71018852180629, 0.8605306826431, 
0.924209068560679, 0.285775361017905, 0.664863156729071, 0.487145768921997, 
1, 0.832231634124478, 0.422308506307687, 0.762751881472008, 0.0938322873057752, 
0.0261833664908076, 0.298901171980893, 0.701456761564214, 0, 
0.165534692152668, 0.705929523042674, 0.47582084015162, 0.904864637947938, 
0.266173069467932, 0.0938322873057752, 0.285775361017905, 0.285775361017905, 
0.487145768921997, 0.487145768921997, 0.664863156729071, 0.664863156729071, 
0.71018852180629, 0.71018852180629, 0.71018852180629, 0.71018852180629, 
0.71018852180629, 0.71018852180629, 0.832231634124478, 0.8605306826431, 
0.8605306826431, 0.8605306826431, 0.8605306826431, 0.924209068560679, 
0.924209068560679, 1), .Dim = c(41L, 1L), .Dimnames = list(NULL, 
    NULL)), y = structure(c(0.334645431217957, 0.432671829817682, 
0.353342528130734, 0.140553264183392, 0.144474680809364, 0.199584374433029, 
0.510873652408072, 0.510678506104081, 0.0134895225339282, 0, 
0.78879924632742, 0.528252398565063, 0.272329523655057, 0.524789125711111, 
0.32914964854835, 0.67428118095733, 0.990339597882693, 1, 0.869509897438751, 
0.949736961865797, 0.78879924632742, 0.140553264183392, 0.140553264183392, 
0.199584374433029, 0.199584374433029, 0.144474680809364, 0.144474680809364, 
0.334645431217957, 0.334645431217957, 0.334645431217957, 0.334645431217957, 
0.334645431217957, 0.334645431217957, 0.510678506104081, 0.432671829817682, 
0.432671829817682, 0.432671829817682, 0.432671829817682, 0.353342528130734, 
0.353342528130734, 0.510873652408072), .Dim = c(41L, 1L), .Dimnames = list(
    NULL, NULL)), na.x = c(FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
), vertex.names = structure(c(3L, 8L, 9L, 4L, 10L, 13L, 16L, 
14L, 6L, 18L, 20L, 5L, 12L, 1L, 7L, 2L, 19L, 17L, 11L, 15L, 20L, 
4L, 4L, 13L, 13L, 10L, 10L, 3L, 3L, 3L, 3L, 3L, 3L, 14L, 8L, 
8L, 8L, 8L, 9L, 9L, 16L), .Label = c("also", "four", "going", 
"governor", "jobs", "just", "know", "make", "people", "president", 
"right", "romney", "said", "sure", "think", "want", "well", "will", 
"world", "years"), class = "factor"), xend = structure(c(0.71018852180629, 
0.8605306826431, 0.924209068560679, 0.285775361017905, 0.664863156729071, 
0.487145768921997, 1, 0.832231634124478, 0.422308506307687, 0.762751881472008, 
0.0938322873057752, 0.0261833664908076, 0.298901171980893, 0.701456761564214, 
0, 0.165534692152668, 0.705929523042674, 0.47582084015162, 0.904864637947938, 
0.266173069467932, 0.165534692152668, 0.487145768921997, 0.298901171980893, 
0.298901171980893, 0.422308506307687, 0.487145768921997, 0.762751881472008, 
0.8605306826431, 0.924209068560679, 0.664863156729071, 0.487145768921997, 
0.832231634124478, 0.701456761564214, 0.701456761564214, 0.924209068560679, 
0.832231634124478, 1, 0.701456761564214, 1, 0.832231634124478, 
0.832231634124478), .Dim = c(41L, 1L), .Dimnames = list(NULL, 
    NULL)), yend = structure(c(0.334645431217957, 0.432671829817682, 
0.353342528130734, 0.140553264183392, 0.144474680809364, 0.199584374433029, 
0.510873652408072, 0.510678506104081, 0.0134895225339282, 0, 
0.78879924632742, 0.528252398565063, 0.272329523655057, 0.524789125711111, 
0.32914964854835, 0.67428118095733, 0.990339597882693, 1, 0.869509897438751, 
0.949736961865797, 0.67428118095733, 0.199584374433029, 0.272329523655057, 
0.272329523655057, 0.0134895225339282, 0.199584374433029, 0, 
0.432671829817682, 0.353342528130734, 0.144474680809364, 0.199584374433029, 
0.510678506104081, 0.524789125711111, 0.524789125711111, 0.353342528130734, 
0.510678506104081, 0.510873652408072, 0.524789125711111, 0.510873652408072, 
0.510678506104081, 0.510678506104081), .Dim = c(41L, 1L), .Dimnames = list(
    NULL, NULL)), na.y = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
), weight = c(25, 19.2796610169492, 16.228813559322, 14.0360169491525, 
16.7055084745763, 12.3199152542373, 15.9427966101695, 12.4152542372881, 
7.36228813559322, 8.02966101694915, 6.40889830508475, 5.64618644067797, 
5.16949152542373, 3.54872881355932, 4.21610169491525, 4.69279661016949, 
2.6906779661017, 2.5, 3.54872881355932, 3.07203389830508, 0.474025974025974, 
0.227272727272727, 0.811688311688312, 0.155844155844156, 0.155844155844156, 
0.214285714285714, 0.155844155844156, 0.324675324675325, 0.253246753246753, 
0.155844155844156, 0.175324675324675, 0.25974025974026, 0.175324675324675, 
0.175324675324675, 0.25974025974026, 1, 0.324675324675325, 0.188311688311688, 
0.155844155844156, 0.175324675324675, 0.246753246753247), width = c(NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, 2.37012987012987, 1.13636363636364, 4.05844155844156, 
0.779220779220779, 0.779220779220779, 1.07142857142857, 0.779220779220779, 
1.62337662337662, 1.26623376623377, 0.779220779220779, 0.876623376623377, 
1.2987012987013, 0.876623376623377, 0.876623376623377, 1.2987012987013, 
5, 1.62337662337662, 0.941558441558442, 0.779220779220779, 0.876623376623377, 
1.23376623376623)), .Names = c("x", "y", "na.x", "vertex.names", 
"xend", "yend", "na.y", "weight", "width"), row.names = c("1", 
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", 
"14", "15", "16", "17", "18", "19", "20", "33", "61", "71", "111", 
"121", "131", "141", "171", "181", "191", "201", "21", "22", 
"24", "25", "26", "27", "28", "30", "31", "32"), class = "data.frame")

ggplot2::ggplot(idat, ggplot2::aes(x = x, y = y, xend = xend, yend = yend)) +
    ggnetwork::geom_edges(color = 'gray80', ggplot2::aes(size = width)) +
    ggnetwork::geom_nodes(color = 'orange', ggplot2::aes(size = weight*5)) +
    ggnetwork::geom_nodetext(ggplot2::aes(label = vertex.names)) 

## Error in eval(expr, envir, enclos) : object 'Stat' not found

Session Info

R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8.1 x64 (build 9600)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

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

loaded via a namespace (and not attached):
 [1] colorspace_1.2-7     scales_0.4.1         assertthat_0.1      
 [4] lazyeval_0.2.0       plyr_1.8.4           sna_2.4             
 [7] tools_3.3.2          gtable_0.2.0         tibble_1.2          
[10] Rcpp_0.12.7          ggrepel_0.6.5        ggplot2_2.2.0       
[13] statnet.common_3.3.0 ggnetwork_0.5.1      grid_3.3.2          
[16] network_1.13.0       munsell_0.4.3       

now loading ggplot2:

library(ggplot2)
ggplot2::ggplot(idat, ggplot2::aes(x = x, y = y, xend = xend, yend = yend)) +
    ggnetwork::geom_edges(color = 'gray80', ggplot2::aes(size = width)) +
    ggnetwork::geom_nodes(color = 'orange', ggplot2::aes(size = weight*5)) +
    ggnetwork::geom_nodetext(ggplot2::aes(label = vertex.names)) 
trinker commented 7 years ago

Any idea on time line with this?

briatte commented 7 years ago

I badly need to fix the package (has not been compiled since ggplot2 2.2.0 got out.

Expected completion: later this week!

trinker commented 7 years ago

I have a few days on my hands. I could try to work this out (I suspect it's straight forward). If you haven't fixed it yet in your local repo I can take a crack and do a PR?

briatte commented 7 years ago

Your help would be very welcome—I have been overwhelmed with tons of late stuff, and am drowning in emails with no hope of getting back to surface before a few days at least… Apologies for the sluggishness!

koheiw commented 6 years ago

Good job @trinker ! @briatte Any plan to update the CRAN version? I am making textplot_network for quanteda based on your package, but not many people use the new function without a CRAN update. Thanks.

briatte commented 4 years ago

Dear @trinker and @koheiw ~

I'm two years late for you both, but ggnetwork has been (heavily) updated.