Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- title: "R Notebook"
- output: html_notebook
- ---
- ```{r}
- library(igraph)
- ```
- ```{r}
- m = matrix(0, nrow=3, ncol=3)
- m
- ```
- ```{r}
- dim(m)
- ```
- ```{r}
- m[1,2] = 1
- m[2,3] = 1
- m[3,1] = 1
- m
- ```
- ```{r}
- m = matrix(c(0,1,0,0,0,1,1,0,0), nrow=3, byrow=T)
- m
- ```
- ```{r}
- nodes = c('A','B','C')
- rownames(m) = nodes
- colnames(m) = nodes
- m
- ```
- ```{r}
- g = graph_from_adjacency_matrix(m,mode = "undirected")
- V(g)
- ```
- ```{r}
- V(g)$color = 'red'
- V(g)$size = 40
- V(g)$size2 = 50
- V(g)$shape = 'circle'
- E(g)$weight = c(1,2,3)
- E(g)$label = E(g)$weight
- V(g)[1]$color = 'yellow'
- plot(g, edge.width = E(g)$weight, layout=layout.circle)
- ```
- ```{r}
- g2 = graph(edges = c(1,2, 2,3, 3,4, 4,1))
- V(g2)[1]$label = 'A very long name'
- V(g2)[2]$label = 'Another very long name'
- V(g2)[3]$label = 'short name'
- V(g2)[c(1,2)]$color = 'green'
- plot(g2)
- ```
- ```{r}
- g=graph(n=12,edges=c(1,2))
- l = matrix(c(3,6,1,5,3,5,4,5,2,4,4,4,1,3,3,3,3,2,1,1,3,1,5,1), nrow=12, byrow=T)
- l
- ```
- ```{r}
- V(g)$size = 30
- plot(g, layout=l)
- ```
- ```{r}
- g3 = graph(edge = c('A','B', 'B','C', 'C','A') )
- plot(g3)
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement