-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from snlab-ch/develop
Some teaching-related additions
- Loading branch information
Showing
55 changed files
with
959 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#' One-mode subset of adolescent society dataset | ||
#' | ||
#' @docType data | ||
#' @keywords datasets | ||
#' @name adolescent_society | ||
#' @usage data(adolescent_society) | ||
#' @format tidygraph graph object | ||
#' @references Coleman, James S. 1961. The Adolescent Society. | ||
#' New York:Free Press. | ||
#' | ||
#' Feld, Scott. 1991. “Why your friends have more friends than you do” | ||
#' American Journal of Sociology 96(6): 1464-1477. | ||
"adolescent_society" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#' One-mode centrality demonstration structure | ||
#' | ||
#' @docType data | ||
#' @keywords datasets | ||
#' @name brandes | ||
#' @usage data(brandes) | ||
#' @format A tidygraph `tbl_graph` with 11 nodes and 24 edges. | ||
"brandes" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#' Visualising graphs and identifying nodes with maximum values of the specified | ||
#' measure. | ||
#' @param object a migraph-consistent object | ||
#' @param FUN some arbitrary function that runs on the object and | ||
#' returns a numeric vector that can be used to scale the nodes | ||
#' @examples | ||
#' ggidentify(brandes, node_degree) | ||
#' ggidentify(brandes, node_betweenness) | ||
#' ggidentify(brandes, node_closeness) | ||
#' ggidentify(brandes, node_eigenvector) | ||
#' @export | ||
ggidentify <- function(object, FUN){ | ||
|
||
measure <- FUN(object) | ||
colord <- ifelse(measure == max(measure), | ||
"max", "other") | ||
|
||
ggraph::ggraph(object) + | ||
ggraph::theme_graph() + | ||
ggraph::geom_edge_link() + | ||
ggraph::geom_node_point(aes(size = measure, | ||
colour = colord)) + | ||
ggplot2::scale_color_manual(breaks = c("max", "other"), | ||
values = c("red", "blue")) + | ||
ggplot2::theme(legend.position = "none") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#' Plot graph with quick labels | ||
#' | ||
#' For quick and easy graphing of networks with labels | ||
#' @param x A migraph-consistent network/graph | ||
#' @param algorithm An initial network layout, | ||
#' currently either Kamada-Kawai ("kk") or | ||
#' Fruchterman-Reingold ("fr") | ||
#' @importFrom ggraph create_layout ggraph geom_edge_link geom_node_text geom_conn_bundle get_con geom_node_point | ||
#' @importFrom ggplot2 theme_void | ||
#' @importFrom igraph as_edgelist | ||
#' @importFrom stats dist | ||
#' @examples | ||
#' ggraphlabel(adolescent_society) | ||
#' @export | ||
ggraphlabel <- function(x, algorithm = c("kk","fr")){ | ||
name <- NULL # initialize variables to avoid CMD check notes | ||
x <- as_tidygraph(x) | ||
algorithm <- match.arg(algorithm) | ||
|
||
gg <- ggraph::create_layout(x, layout = "igraph", | ||
algorithm = algorithm, maxiter = 10000) | ||
|
||
ggraph::ggraph(x, graph = gg) + | ||
ggraph::geom_conn_bundle(data = ggraph::get_con(from = igraph::as_edgelist(x, names = FALSE)[,1], | ||
to = igraph::as_edgelist(x, names = FALSE)[,2]), alpha = 0.1) + | ||
# ggraph::geom_edge_link(arrow = arrow(length = unit(3, 'mm')), | ||
# start_cap = circle(4, 'mm'), | ||
# end_cap = circle(4, 'mm'), show.legend = FALSE) + | ||
ggraph::geom_node_text(aes(label = name)) + ggplot2::theme_void() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.