{"id":13789078,"url":"https://github.com/sctyner/geomnet","last_synced_at":"2026-03-10T20:33:17.876Z","repository":{"id":21041105,"uuid":"24339210","full_name":"sctyner/geomnet","owner":"sctyner","description":"Examples and data for geom_net","archived":false,"fork":false,"pushed_at":"2021-08-23T06:55:17.000Z","size":71534,"stargazers_count":96,"open_issues_count":10,"forks_count":23,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-05-12T03:43:49.646Z","etag":null,"topics":["cran","ggplot2","networks","plotly","visualization"],"latest_commit_sha":null,"homepage":"http://sctyner.github.io/geomnet/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sctyner.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-22T17:59:42.000Z","updated_at":"2025-03-22T11:22:33.000Z","dependencies_parsed_at":"2022-08-30T20:00:18.141Z","dependency_job_id":null,"html_url":"https://github.com/sctyner/geomnet","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/sctyner/geomnet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sctyner%2Fgeomnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sctyner%2Fgeomnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sctyner%2Fgeomnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sctyner%2Fgeomnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sctyner","download_url":"https://codeload.github.com/sctyner/geomnet/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sctyner%2Fgeomnet/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30352877,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T15:55:29.454Z","status":"ssl_error","status_checked_at":"2026-03-10T15:54:58.440Z","response_time":106,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cran","ggplot2","networks","plotly","visualization"],"created_at":"2024-08-03T21:00:58.300Z","updated_at":"2026-03-10T20:33:17.848Z","avatar_url":"https://github.com/sctyner.png","language":"R","readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n# geomnet \u003cimg src=\"man/figures/logo.png\" align=\"right\" width=\"120\" /\u003e\n\n[![CRAN Status](http://www.r-pkg.org/badges/version/geomnet)](https://cran.r-project.org/package=geomnet)\n[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/geomnet)](https://www.r-pkg.org/pkg/geomnet)\n[![Travis-CI Build Status](https://travis-ci.org/sctyner/geomnet.svg?branch=master)](https://travis-ci.org/sctyner/geomnet)\n\n`geomnet` is a package built on top of the most recent major `ggplot2` release. It provides a `ggplot2` `geom` called `geom_net` to visualize graphs and networks. It also include the function `stat_net` to calculate network layouts with the `sna` package. Finally, the function `geom_circle` is included to draw circles using `ggplot2`.\n\nYou can install `geomnet` directly from CRAN\n`install.packages('geomnet')`\nor from Github\n`devtools::install_github(\"sctyner/geomnet\")`\n\n```{r, echo = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\"\n)\n```\n\n# Examples\n\n## `ggplot2` Theme Elements\n\nThis example shows the theme inheritance properties of the theme elements of `ggplot2`. Note: this example has not been updated since the release of `ggplot2 2.2.0` and as such the content may have changed. \n\n```{r theme, fig.align='center', message=FALSE, warning=FALSE}\nlibrary(dplyr)\nlibrary(geomnet)\ndata(theme_elements)\n# data step\nTEnet \u003c- fortify(as.edgedf(theme_elements$edges[,c(\"parent\", \"child\")]), theme_elements$vertices)\n# create a degree variable for use later\nTEnet \u003c- TEnet %\u003e%\n  group_by(from_id) %\u003e%\n  mutate(degree = sqrt(10 * n() + 1))\n# plot\nggplot(data = TEnet,\n       aes(from_id = from_id, to_id = to_id)) +\n  geom_net(layout.alg = \"fruchtermanreingold\",\n    aes(fontsize = degree), directed = TRUE,\n    labelon = TRUE, size = 1, labelcolour = 'black',\n    ecolour = \"grey70\", arrowsize = 0.5,\n    linewidth = 0.5, repel = TRUE) +\n  theme_net() +\n  xlim(c(-0.05, 1.05))\n```\n\n## Blood Donation Diagram\n\nIn this example, we reimagine the [traditional blood donation diagram](http://www.redcrossblood.org/learn-about-blood/blood-types) as a directed network. Arrows point to the blood type that receives. This example provides two data frames to `geom_net()`.  \n\n```{r blood, fig.align='center'}\nlibrary(geomnet)\ndata(blood)\nggplot(data = blood$edges, aes(from_id = from, to_id = to)) +\n  geom_net(colour = \"darkred\", layout.alg = \"circle\", labelon = TRUE, \n           size = 15, directed = TRUE, vjust = 0.5, labelcolour = \"grey80\",\n           arrowsize = 1.5, linewidth = 0.5, arrowgap = 0.05,\n           selfloops = TRUE, ecolour = \"grey40\") + \n  theme_net() \n```\n\n## Harry Potter Peer Support Network\n\nIn this fun example from [this website](http://www.stats.ox.ac.uk/~snijders/siena/siena.html), there is a tie between two students if one provides emotional support to the other at some point in the book. It is a directed network, so in the visualization, the arrow points to the student receiving support. \n\n```{r HP, echo = FALSE, message=FALSE, warning=FALSE}\nlibrary(dplyr)\ntemp \u003c- tempfile()\ndownload.file(\"http://www.stats.ox.ac.uk/~snijders/siena/bossaert_meidert_harrypotter.zip\",temp)\nhp1 \u003c- read.table(unz(temp, \"hpbook1.txt\"))\nhp1 \u003c- as.matrix(hp1)\ndiag(hp1) \u003c- 0\nhp1 \u003c- data.frame(hp1)\nhp1$id \u003c- 1:64\nhp1 \u003c- hp1 %\u003e% tidyr::gather(var, value, -id) %\u003e%\n               dplyr::filter(value == 1) %\u003e% \n               dplyr::select(-value) %\u003e% \n               dplyr::mutate(var = readr::parse_number(var), book = 1) %\u003e% \n               dplyr::rename(from = id, to = var)\nhp2 \u003c- read.table(unz(temp, \"hpbook2.txt\"))\nhp2 \u003c- as.matrix(hp2)\ndiag(hp2) \u003c- 0\nhp2 \u003c- data.frame(hp2)\nhp2$id \u003c- 1:64\nhp2 \u003c- hp2 %\u003e% tidyr::gather(var, value, -id) %\u003e%\n               dplyr::filter(value == 1) %\u003e% \n               dplyr::select(-value) %\u003e% \n               dplyr::mutate(var = readr::parse_number(var), book = 2) %\u003e% \n               dplyr::rename(from = id, to = var)\nhp3 \u003c- read.table(unz(temp, \"hpbook3.txt\"))\nhp3 \u003c- as.matrix(hp3)\ndiag(hp3) \u003c- 0\nhp3 \u003c- data.frame(hp3)\nhp3$id \u003c- 1:64\nhp3 \u003c- hp3 %\u003e% tidyr::gather(var, value, -id) %\u003e%\n               dplyr::filter(value == 1) %\u003e% \n               dplyr::select(-value) %\u003e% \n               dplyr::mutate(var = readr::parse_number(var), book = 3) %\u003e% \n               dplyr::rename(from = id, to = var)\nhp4 \u003c- read.table(unz(temp, \"hpbook4.txt\"))\nhp4 \u003c- as.matrix(hp4)\ndiag(hp4) \u003c- 0\nhp4 \u003c- data.frame(hp4)\nhp4$id \u003c- 1:64\nhp4 \u003c- hp4 %\u003e% tidyr::gather(var, value, -id) %\u003e%\n               dplyr::filter(value == 1) %\u003e% \n               dplyr::select(-value) %\u003e% \n               dplyr::mutate(var = readr::parse_number(var), book = 4) %\u003e% \n               dplyr::rename(from = id, to = var)\nhp5 \u003c- read.table(unz(temp, \"hpbook5.txt\"))\nhp5 \u003c- as.matrix(hp5)\ndiag(hp5) \u003c- 0\nhp5 \u003c- data.frame(hp5)\nhp5$id \u003c- 1:64\nhp5 \u003c- hp5 %\u003e% tidyr::gather(var, value, -id) %\u003e%\n               dplyr::filter(value == 1) %\u003e% \n               dplyr::select(-value) %\u003e% \n               dplyr::mutate(var = readr::parse_number(var), book = 5) %\u003e% \n               dplyr::rename(from = id, to = var)\nhp6 \u003c- read.table(unz(temp, \"hpbook6.txt\"))\nhp6 \u003c- as.matrix(hp6)\ndiag(hp6) \u003c- 0\nhp6 \u003c- data.frame(hp6)\nhp6$id \u003c- 1:64\nhp6 \u003c- hp6 %\u003e% tidyr::gather(var, value, -id) %\u003e%\n               dplyr::filter(value == 1) %\u003e% \n               dplyr::select(-value) %\u003e% \n               dplyr::mutate(var = readr::parse_number(var), book = 6) %\u003e% \n               dplyr::rename(from = id, to = var)\nhp \u003c- rbind(hp1, hp2, hp3, hp4, hp5, hp6)\nhp.attributes \u003c- read.table(unz(temp, \"hpattributes.txt\"), header=TRUE, stringsAsFactors = F)\nhp.names \u003c- read.table(unz(temp, \"hpnames.txt\"), header=TRUE, stringsAsFactors = F)\nhp.names[,1] \u003c- as.integer(hp.names[,1])\nhp.1 \u003c- merge(hp, hp.names, by.x = \"from\", by.y = \"id\")\nnames(hp.1)[4] \u003c- \"name1\"\nhp.2 \u003c- merge(hp.1, hp.names, by.x = \"to\", by.y = \"id\")\nnames(hp.2)[5] \u003c- \"name2\"\nhp.edges \u003c- hp.2[, c(\"name1\", \"name2\", \"book\")] %\u003e% dplyr::arrange(book, name1, name2)\nhp.chars \u003c- merge(hp.names, hp.attributes)\nhp.chars$house \u003c- factor(hp.chars$house, labels = c(\"Gryffindor\", \"Hufflepuff\", \"Ravenclaw\", \"Slytherin\"))\nhp.chars$gender \u003c- factor(hp.chars$gender, labels = c(\"M\", \"F\"))\nunlink(temp)\nhp.chars \u003c- hp.chars[,-1]\n```\n\n```{r HPplot, fig.width=10, fig.height=8, fig.align='center', warning = FALSE}\nlibrary(geomnet)\nhead(hp.edges)\nhead(hp.chars)\nhp.all \u003c- fortify(as.edgedf(hp.edges), hp.chars, group = \"book\")\n# only plot the characters with any connections in a given book. \nggplot(data=hp.all, aes(from_id = from, to_id = to_id)) + \n  geom_net(fiteach=T, directed = T, size = 3, linewidth = .5, \n           ealpha = .5, labelon = T, fontsize = 3, repel = T, \n           labelcolour = \"black\", arrowsize = .5, singletons = FALSE,\n           aes(colour = house, group = house, shape = gender)) + \n  scale_colour_manual(values = c(\"#941B08\",\"#F1F31C\", \n                                 \"#071A80\", \"#154C07\")) + \n  facet_wrap(~book, labeller = \"label_both\") + \n  theme_net() + theme(panel.background = element_rect(colour = 'black'))\n```\n\n## Interactivity with `plotly`!\n\nNow including interactivity with `ggplotly()`!\n\n```{r football, eval = FALSE}\n# blood donation example\nlibrary(geomnet)\n# devtools::install_github(\"ropensci/plotly\")\nlibrary(plotly)\ndata(blood)\nbloodnet \u003c- fortify(as.edgedf(blood$edges), blood$vertices)\np \u003c- ggplot(data = bloodnet, aes(from_id = from_id, to_id = to_id))\n\n# create data plot\np2 \u003c- p + geom_net(aes(size=Predominance, colour=type, shape=rho, linetype=group_to),\n             linewidth=0.75, labelon =TRUE, directed = TRUE, labelcolour=\"black\") +\n  facet_wrap(~Ethnicity) +\n  scale_colour_brewer(palette=\"Set2\") \nggplotly(p2) %\u003e% hide_legend()\n\n# Classic College Football Example\ndata(\"football\")\n# data step: merge vertices and edges\nftnet \u003c- fortify(as.edgedf(football$edges), football$vertices)\n\n# create data plot\ngg \u003c- ggplot(data = ftnet,\n       aes(from_id = from_id, to_id = to_id)) +\n  geom_net(layout.alg = 'fruchtermanreingold',\n    aes(colour = value, group = value,\n        linetype = factor(same.conf != 1)),\n    linewidth = 0.5,\n    size = 5, vjust = -0.75, alpha = 0.3) +\n  theme_net() +\n  theme(legend.position = \"bottom\") +\n  scale_colour_brewer(\"Conference\", palette = \"Paired\")  +\n  guides(linetype = FALSE)\nggplotly(gg)\n```\n","funding_links":[],"categories":["R","Network Visualization"],"sub_categories":["Miscellaneous"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsctyner%2Fgeomnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsctyner%2Fgeomnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsctyner%2Fgeomnet/lists"}