Skip to content

Commit

Permalink
Adding figure with gexf-js
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Aug 12, 2021
1 parent 47612ad commit 324e6da
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 157 deletions.
62 changes: 37 additions & 25 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,44 @@ citation(package="rgexf")

# Examples

## Example 1: Static net ##
```{r}
## Example 1: Importing GEXF files

We can use the `read.gexf` function to read GEXF files into R:

```{r read-lesmiserables}
# Loading the package
library(rgexf)
g <- system.file("gexf-graphs/lesmiserables.gexf", package="rgexf")
g <- read.gexf(g)
head(g) # Taking a look at the first handful
```

Moreover, we can use the `gexf.to.igraph()` function to convert the
`gexf` object into an `igraph` object:

```{r igraph}
library(igraph)
ig <- gexf.to.igraph(g)
op <- par(mai = rep(0, 4)) # Making room
plot(ig)
par(op)
```


Using the `plot.gexf` method--which uses the `gexf-js` JavaScript library--results
in a Web visualization of the graph, like this:

```r
plot(g)
```
![](inst/gexf-graphs/lesmiserables.png)

An live version of the figure is available [here](https://gvegayon.github.io/rgexf/lesmiserables).

## Example 2: Static net ##
```{r}
# Creating a group of individuals and their relations
people <- data.frame(matrix(c(1:4, 'juan', 'pedro', 'matthew', 'carlos'),ncol=2))
people
Expand All @@ -90,7 +123,7 @@ write.gexf(people, relations)
```


## Example 2: Dynamic net ##
## Example 3: Dynamic net ##

```{r}
# Defining the dynamic structure, note that there are some nodes that have NA at the end.
Expand All @@ -105,7 +138,7 @@ write.gexf(people, relations, nodeDynamic=time)



## Example 3: More complex... Dynamic graph with attributes both for nodes and edges##
## Example 4: More complex... Dynamic graph with attributes both for nodes and edges##

First we define dynamics

Expand All @@ -132,29 +165,8 @@ write.gexf(nodes=people, edges=relations, edgeDynamic=time.edges,
edgesAtt=edge.att, nodeDynamic=time.nodes, nodesAtt=node.att)
```

## Example 4: Importing GEXF files

We can use the `read.gexf` function to read GEXF files into R:

```{r read-lesmiserables}
g <- system.file("gexf-graphs/lesmiserables.gexf", package="rgexf")
g <- read.gexf(g)
head(g) # Taking a look at the first handful
```

Moreover, we can use the `gexf.to.igraph()` function to convert the
`gexf` object into an `igraph` object:

```{r igraph}
library(igraph)
ig <- gexf.to.igraph(g)

op <- par(mai = rep(0, 4)) # Making room
plot(ig)
par(op)
```

An example of the plot method using the `gexf-js` JavaScript library is available [here](https://gvegayon.github.io/rgexf/lesmiserables)

# Code of Conduct

Expand Down
Loading

0 comments on commit 324e6da

Please sign in to comment.