sctyner / geomnet Goto Github PK
View Code? Open in Web Editor NEWExamples and data for geom_net
Home Page: http://sctyner.github.io/geomnet/
Examples and data for geom_net
Home Page: http://sctyner.github.io/geomnet/
geomnet
looks intuitive and versatile. I love how directly and naturally it merges with existing ggplot2
code. As a new user, I am wondering what the best use cases are for geomnet
versus ggraph
or DiagrammeR
. From my reading so far, I suspect that geomnet
graphs are easier and quicker to create and that the ggraph
and DiagrammeR
have more features. Do you think an assessment and some recommendations would be appropriate for the README?
linewidth argument is not responsive to values but only when mapped using aes()
library(ggplot2)
library(geomnet)
data("bikes")
# merge into a single data.frame()
bikes_merged <- merge(bikes$trips, bikes$stations, by.x="Start.station", by.y="name", all=TRUE)
# create a factor
bikes_merged$nbDocksfac <- as.factor(bikes_merged$nbDocks)
p <- ggplot(data = bikes_merged, aes(from_id = Start.station, to_id = End.station))
p + geom_net(aes(shape = nbDocksfac), colour = "blue", size = 6, linewidth=0.75, directed = TRUE, curvature=0.3) # shapes are OK
p + geom_net(aes(colour = nbDocks), size = 6, directed = TRUE, curvature=0.3) # gradient colored nodes are OK
p + geom_net(aes(colour = nbDocksfac), size = 6, directed = TRUE, curvature=0.3) # categorical colored nodes are OK
p + geom_net(aes(size = nbDocksfac, colour = nbDocksfac), directed = TRUE, curvature=0.3) # diff size & colour are OK
p + geom_net(aes(linetype = nbDocksfac), colour = "blue", size = 6, directed = TRUE, curvature=0.3) # linetypes are OK
p + geom_net(aes(linewidth = 2), colour = "blue", size = 6, directed = TRUE, curvature=0.3) # fixed linewidth inside aes() is OK
p + geom_net(colour = "blue", size = 6, linewidth = 2, directed = TRUE, curvature=0.3) # fixed linewidth is OK
p + geom_net(aes(linewidth = 0.99), colour = "blue", size = 6, directed = TRUE, curvature=0.3) # bug? linewidth not responsive
Store the coordinates as ..x.. ..y.. à la ..density.. so that they can be removed from the internal structure.
I think you could just set hoverinfo="none"
around here:
https://github.com/sctyner/geomnet/blob/master/R/geom2plotly.R#L33
Want to have labels added logically. A vlabel column in data that is TRUE if the vertex should be labeled with its name or FALSE if it shouldn't be labeled. This would replace the current logical vlabel option.
dear geomnet team ,geomnet support for ggolot getwork plotly is indeed a nice thing, but I got an error when I tried to run the example code, and I was looking forward to this package working normally.
library(dplyr)
library(geomnet)
data(theme_elements)
# data step
TEnet <- fortify(as.edgedf(theme_elements$edges[,c("parent", "child")]), theme_elements$vertices)
# create a degree variable for use later
TEnet <- TEnet %>%
group_by(from_id) %>%
mutate(degree = sqrt(10 * n() + 1))
# plot
ggplot(data = TEnet,
aes(from_id = from_id, to_id = to_id)) +
geom_net(layout.alg = "fruchtermanreingold",
aes(fontsize = degree), directed = TRUE,
labelon = TRUE, size = 1, labelcolour = 'black',
ecolour = "grey70", arrowsize = 0.5,
linewidth = 0.5, repel = TRUE) +
theme_net() +
xlim(c(-0.05, 1.05))
###################################################################
###################################################################
Error in `geom_net()`:
! Problem while computing stat.
ℹ Error occurred in the 1st layer.
Caused by error:
! The first two columns of `x` must be of the same type.
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace()
<error/rlang_error>
Error in `geom_net()`:
! Problem while computing stat.
ℹ Error occurred in the 1st layer.
Caused by error:
! The first two columns of `x` must be of the same type.
---
Backtrace:
▆
1. ├─base (local) `<fn>`(x)
2. └─ggplot2:::print.ggplot(x)
3. ├─ggplot2::ggplot_build(x)
4. └─ggplot2:::ggplot_build.ggplot(x)
5. └─ggplot2:::by_layer(...)
6. ├─rlang::try_fetch(...)
7. │ ├─base::tryCatch(...)
8. │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
9. │ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
10. │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
11. │ └─base::withCallingHandlers(...)
12. └─ggplot2 (local) f(l = layers[[i]], d = data[[i]])
13. └─l$compute_statistic(d, layout)
14. └─ggplot2 (local) compute_statistic(..., self = self)
15. └─self$stat$compute_layer(data, self$computed_stat_params, layout)
16. └─geomnet (local) compute_layer(..., self = self)
17. └─self$compute_panel(...)
18. └─geomnet (local) compute_panel(..., self = self)
19. └─self$compute_network(...)
20. └─geomnet (local) compute_network(...)
21. ├─network::as.network(na.omit(edges[, 1:2]), matrix.type = "edgelist")
22. └─network::as.network.data.frame(na.omit(edges[, 1:2]), matrix.type = "edgelist")
23. └─network:::.validate_edge_df(...)
24. └─base::stop(...)
Run rlang::last_trace(drop = FALSE) to see 5 hidden frames.
I can't run successfully on both linux and window10 systems, the same error occurs,here is my running environment(win10)
> sessionInfo()
R version 4.4.1 (2024-06-14 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 10 x64 (build 19045)
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Simplified)_China.utf8 LC_CTYPE=Chinese (Simplified)_China.utf8
[3] LC_MONETARY=Chinese (Simplified)_China.utf8 LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_China.utf8
time zone: Asia/Shanghai
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] geomnet_0.3.1 ggplot2_3.5.1
loaded via a namespace (and not attached):
[1] tidyr_1.3.1 plotly_4.10.4 utf8_1.2.4 generics_0.1.3 lattice_0.22-6
[6] stringi_1.7.6 hms_1.1.3 statnet.common_4.9.0 digest_0.6.29 magrittr_2.0.3
[11] grid_4.4.1 pkgload_1.4.0 fastmap_1.2.0 jsonlite_1.8.8 network_1.18.2
[16] pkgbuild_1.4.4 sessioninfo_1.2.2 urlchecker_1.0.1 promises_1.2.0.1 httr_1.4.7
[21] purrr_1.0.2 fansi_1.0.6 viridisLite_0.4.2 scales_1.3.0 lazyeval_0.2.2
[26] cli_3.6.2 shiny_1.8.1.1 rlang_1.1.3.9000 ellipsis_0.3.2 munsell_0.5.1
[31] remotes_2.5.0 withr_3.0.0 cachem_1.0.6 devtools_2.4.5 tools_4.4.1
[36] tzdb_0.4.0 coda_0.19-4.1 memoise_2.0.1 dplyr_1.1.4 colorspace_2.1-0
[41] httpuv_1.6.5 curl_4.3.2 vctrs_0.6.5 R6_2.5.1 mime_0.12
[46] lifecycle_1.0.4 stringr_1.5.1 fs_1.5.2 htmlwidgets_1.6.4 usethis_2.2.3
[51] miniUI_0.1.1.1 sna_2.7-2 pkgconfig_2.0.3 pillar_1.9.0 later_1.3.0
[56] gtable_0.3.5 data.table_1.14.2 glue_1.6.2 profvis_0.3.7 Rcpp_1.0.8.3
[61] tibble_3.2.1 tidyselect_1.2.1 rstudioapi_0.16.0 xtable_1.8-4 htmltools_0.5.8.1
[66] readr_2.1.5 compiler_4.4.1
Hi,
Running R version 3.2.0 (2015-04-16) on x86_64-apple-darwin13.4.0
Layout ALL vertices first, then facet instead of recomputing the layout for each facet.
Error in rep(yes, length.out = len) :
attempt to replicate an object of type 'closure'
how i am suppose to deal with it
Hi,
Thank you for creating this amazing product. I am eager to use it to generate network for my analysis. However, I am stuck at step one - I cannot install the package!! Here is the error message. Could you help me identify what the problem would be? Thank you!!
Downloading github repo sctyner/geomnet@master
Installing geomnet
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ
--no-save --no-restore CMD INSTALL
'/private/var/folders/0p/zrfyxxm9021bpfhlybcss75c0000gn/T/Rtmp4Nxf8o/devtoolsfee77a0000a/sctyner-geomnet-b78193e'
--library='/Library/Frameworks/R.framework/Versions/3.1/Resources/library'
--install-tests
Appears when facetting, although facetting still works as intended. Issue appears to be with ggplot2:::Layout$get_scales(data$PANEL[1])
.
Vertices have strange dots when plotted as .jpg or .png (see below), but not when plotted as .pdf.
Hi!
I am using geom_net to plot my network data and I am pretty impressed by how useful and nice this package is. Since I am using the line width to represent weighted edges, it would be possible to include an additional legend for line width in my plot? I mean, I would like to have a legend with line width proportional to the values that I have in the dataframe.
I appreciate any help or feedback on this!
Thanks
Gustavo
I am not sure if this is a bug or a feature. If this is a feature, adding an argument to offer both would be really helpful.
when creating circles with geom_circle, the radius is proportional to the limits of the figure. Thus, a radius of 0.5 reflects 0.5 times the x and the y axis of the screen. Given it's the radius, it would completely fill the figure. It would be more intuitive and streamlined with other gg functions to have the radius using the actual x and y values on the grid.
kind regards
Youri
edit:
I wrote a solution:
https://github.com/yhoogstrate/geomnet
I am not too deep into the gg enviroment so this probably isn't the most elegant solution.
Allow users to input their own layout ((x,y) coords of vertices and vertex id?).
Have legends appear on the right for color, shape, linetype, etc. I'm assuming they will show up once we fix the grouping, but in case they don't I thought I'd make an issue for it.
I have a directed graph and the node that everything leads to (only appears in the column "to_id") does not get a label.
Is it possible to add text to the edges in geom_net using the very intuitive geom_net
api?
I do not see anything in the documentation that talks to this
library(geomnet)
library(ggplot2)
x <- structure(list(from = c("a", "b", "d", "f", "g", "e", "c", "i",
"e", "h", "i", "i", "j", "j"), to = c("", "", "", "", "", "a",
"b", "c", "d", "e", "f", "g", "h", "i"), edge_val = c(NA, NA,
NA, NA, NA, 1.6, 2.25, 1.75, 0.95, 1.8, 3.2, 2.6, 2.95, 2.45)), .Names = c("from",
"to", "edge_val"), class = "data.frame", row.names = c(NA, -14L
))
ggplot(x, aes(from_id = from, to_id = to, linewidth = edge_val)) +
geom_net(layout.alg = "fruchtermanreingold", labelgeom = "text",repel = TRUE,
size = 4, labelon = TRUE, vjust = -1, ecolour = "grey80",
directed = FALSE, fontsize = 4, ealpha = 0.5) +
theme_net()
Is this no longer part of CRAN?
The package is archived.
When I try to build the github version I get
* creating vignettes ... ERROR
--- re-building ‘geomnet-vignette.Rmd’ using rmarkdown
Quitting from lines 15-112 (geomnet-vignette.Rmd)
Error: processing vignette 'geomnet-vignette.Rmd' failed with diagnostics:
The first two columns of `x` must be of the same type.
--- failed re-building ‘geomnet-vignette.Rmd’
SUMMARY: processing the following file failed:
‘geomnet-vignette.Rmd’
Error: Vignette re-building failed.
Execution halted
After installing last CRAN archived version, when trying to compile first examples in that vignette I also get
Error: The first two columns of `x` must be of the same type.
Further, I get a similar error to the one in CRAN (https://cran-archive.r-project.org/web/checks/2021/2021-06-21_check_results_geomnet.html)
Error: `loops` is `FALSE`, but `x` contains loops.
The following values are affected:
- `x[604, 1:2]`
- `x[605, 1:2]`
- `x[610, 1:2]`
- `x[615, 1:2]`
- `x[617, 1:2]`
- `x[618, 1:2]`
Execution halted
if I do
network::as.network(bloodnet[,1:2], matrix.type = "edgelist")
Error: `loops` is `FALSE`, but `x` contains loops.
The following values are affected:
- `x[13, 1:2]`
- `x[14, 1:2]`
- `x[15, 1:2]`
- `x[16, 1:2]`
- `x[21, 1:2]`
- `x[22, 1:2]`
but not sure as they relates.
Hello,
I am trying to set a range for the linewidth, similar to what I can do with node size:
scale_size_continuous(range = c(3,10))
Is this functionality included in geom_net?
Thank you
Maybe this can be done in ggplot2 but to date I can't figure out how. I notice you provide for "labelcolour" in geom_net though. My goal is to generate an even better network plot by making it more readable. Also want to try to integrate "ggrepel." As a teacher myself I really like being able to show students how to produce nice networks without a lot of messing around. You have done a great job with "geomnet."
Best regards
Mike Gallagher
geomnet's no longer on CRAN. I wonder if you plan to get it back, or if you need help doing so?
I suggest adding to which release this sentence in your readme.md refers:
geomnet is a package built on top of the most recent major ggplot2 release.
hi, i like your package very much and I want to learn it.
when I try your example, I find that I can't find hp.edges.
Can you put the data in your repo or pacakge?
Thank you very much and looking forward to your reply.
Yang
Grouping doesn't work in the usual ggplot2 way when it comes to aes things.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.