4.4 Loading Packages
Packages are collections of R functions, data, and compiled code.
igraph is collection of network analysis tools with the emphasis on efficiency, portability and ease of use
install.packages("ggraph",repos = "http://cran.us.r-project.org")
The library function tells R to add the package to the current R session
suppressPackageStartupMessages(library(igraph))
suppressPackageStartupMessages(library(ggraph))
suppressPackageStartupMessages(library(tidygraph))
suppressPackageStartupMessages(library(tidyverse))
%>%
matrix_data2 graph.adjacency(mode = "undirected")%>%
plot()
<- matrix_data2 %>%
tbl_links graph.adjacency()%>%
get.edgelist() %>%
as_tibble() %>%
::rename(from = "V1", to = "V2") dplyr
## Warning: The `x` argument of `as_tibble.matrix()` must have unique column names if
## `.name_repair` is omitted as of tibble 2.0.0.
## ℹ Using compatibility `.name_repair`.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
<- data.frame(name = tbl_links %>% unlist %>% unique())%>%
tbl_nodes as_tibble()
<- graph_from_data_frame(tbl_links, tbl_nodes, directed = FALSE)
graph
%>%
graph ggraph()+
geom_edge_link() +
geom_node_point()+
geom_node_text(aes(label = name), repel = TRUE, size = 8)
## Using "stress" as default layout
## Warning: Using the `size` aesthetic in this geom was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` in the `default_aes` field and elsewhere instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.