Skip to content

Commit a739d0b

Browse files
committed
Import GrapML guide for using Gitnet data in R.
1 parent 1100e14 commit a739d0b

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

notebooks/import_graphml.r

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
library(igraph)
2+
3+
# Set the working directory to your own preferred directory.
4+
# Something like 'C:/users/user/Desktop/' would work well in Windows.
5+
# Something like '~/Users/user/Desktop/' should work on OSX or Linux.
6+
7+
setwd("C:/users/user/Desktop/")
8+
9+
# Import the GRAPHML file exported from gitnet.
10+
# See the gitnet walkthrough if you do not know how to create and export a GRAPHML file.
11+
12+
G <- read.graph("mygraph.graphml", format = c("graphml"))
13+
14+
# The removes multiple edges from the plot.
15+
# Since graphs created with gitnet are multigraphs (with multiple edges),
16+
# it is best to only use this when you want to make a simple looking plot, not for analysis.
17+
18+
G <- simplify(G, remove.multiple = TRUE, remove.loops = TRUE,
19+
edge.attr.comb = igraph_opt("edge.attr.comb"))
20+
21+
# These are some settings that look pretty good.
22+
23+
V(G)$size = 3 # Set vertex size, slightly smaller than the default.
24+
E(G)$width = 1 # Set edge size.
25+
V(G)$label.cex = 0.4 # Change the size of labels.
26+
V(G)$label.color = "black"
27+
28+
# There is some customization here. Depending on the modes you used in your graph, you can specify colours.
29+
# If you chose to add colours (simple or complex), you could select new mappings for them here:
30+
# V(G)[colour == "original"]$color = "new"
31+
32+
V(G)[type == "author"]$color = "oldlace"
33+
V(G)[type == "files"]$color = "lightcoral"
34+
35+
lay = layout.kamada.kawai(G)
36+
37+
# This saves the plot as a pdf in the current directory.
38+
39+
pdf("myplot.pdf")
40+
par(mar=c(0,0,0,0)+.5)
41+
plot(G, layout = lay, vertex.label = NA)
42+
dev.off()

0 commit comments

Comments
 (0)