Skip to content

Commit

Permalink
Merge pull request #35 from snlab-ch/develop
Browse files Browse the repository at this point in the history
v0.3.0
  • Loading branch information
jhollway authored Dec 15, 2023
2 parents b69fd13 + 0f69f65 commit 824a8d3
Show file tree
Hide file tree
Showing 36 changed files with 1,520 additions and 627 deletions.
40 changes: 20 additions & 20 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: manynet
Title: Many Ways to Make, Manipulate, and Map Myriad Networks
Version: 0.2.10
Date: 2023-12-06
Description: A set of tools for making, manipulating, and mapping many different types of networks.
Title: Many Ways to Make, Modify, and Map Myriad Networks
Version: 0.3.0
Date: 2023-12-15
Description: A set of tools for making, modifying, and mapping many different types of networks.
All functions operate with matrices, edge lists, and 'igraph', 'network', and 'tidygraph' objects,
and on one-mode, two-mode (bipartite), and sometimes three-mode networks.
The package includes functions for importing and exporting, creating and generating networks,
Expand All @@ -20,31 +20,31 @@ Imports:
dplyr (>= 1.1.0),
ggplot2,
ggraph,
igraph (>= 1.5.0.1),
igraph (>= 1.6.0),
network,
tidygraph
Suggests:
BiocManager,
concaveman,
gganimate,
ggforce,
gifski,
graphlayouts,
grDevices,
knitr,
learnr,
methods,
migraph,
minMSE,
multiplex,
patchwork,
png,
readxl,
rmarkdown,
roxygen2,
RSiena,
testthat,
xml2,
patchwork,
rmarkdown,
learnr,
grDevices,
BiocManager,
minMSE,
graphlayouts,
ggforce,
multiplex,
concaveman,
migraph,
knitr,
gifski,
png
xml2
Enhances:
Rgraphviz
Authors@R:
Expand Down
26 changes: 17 additions & 9 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ S3method(as_network,network.goldfish)
S3method(as_network,siena)
S3method(as_network,tbl_graph)
S3method(as_siena,igraph)
S3method(as_siena,tbl_graph)
S3method(as_tidygraph,data.frame)
S3method(as_tidygraph,diff_model)
S3method(as_tidygraph,igraph)
S3method(as_tidygraph,list)
S3method(as_tidygraph,matrix)
Expand Down Expand Up @@ -248,7 +250,6 @@ export("%>%")
export(.E)
export(.G)
export(.N)
export(activate)
export(add_node_attribute)
export(add_nodes)
export(add_tie_attribute)
Expand Down Expand Up @@ -292,13 +293,11 @@ export(ggplot)
export(ggsave)
export(ggtitle)
export(guides)
export(iheid_palette)
export(is.igraph)
export(is.network)
export(is.tbl_graph)
export(is_acyclic)
export(is_aperiodic)
export(is_bipartite)
export(is_complex)
export(is_connected)
export(is_directed)
Expand Down Expand Up @@ -327,6 +326,7 @@ export(layout_tbl_graph_multilevel)
export(layout_tbl_graph_quad)
export(layout_tbl_graph_railway)
export(layout_tbl_graph_triad)
export(many_palettes)
export(mutate)
export(mutate_ties)
export(na_to_mean)
Expand All @@ -350,17 +350,29 @@ export(rename)
export(rename_ties)
export(run_tute)
export(scale_color_centres)
export(scale_color_ethz)
export(scale_color_iheid)
export(scale_color_rug)
export(scale_color_sdgs)
export(scale_color_uzh)
export(scale_colour_centres)
export(scale_colour_ethz)
export(scale_colour_iheid)
export(scale_colour_rug)
export(scale_colour_sdgs)
export(scale_colour_uzh)
export(scale_fill_centres)
export(scale_fill_ethz)
export(scale_fill_iheid)
export(scale_fill_rug)
export(scale_fill_sdgs)
export(scale_fill_uzh)
export(select_ties)
export(summarise_ties)
export(theme_ethz)
export(theme_iheid)
export(theme_rug)
export(theme_uzh)
export(tie_attribute)
export(tie_signs)
export(tie_weights)
Expand Down Expand Up @@ -446,10 +458,6 @@ importFrom(ggraph,geom_node_text)
importFrom(ggraph,get_con)
importFrom(ggraph,ggraph)
importFrom(ggraph,scale_edge_width_continuous)
importFrom(graphics,image)
importFrom(graphics,par)
importFrom(graphics,rect)
importFrom(graphics,text)
importFrom(igraph,E)
importFrom(igraph,V)
importFrom(igraph,add_edges)
Expand All @@ -458,8 +466,8 @@ importFrom(igraph,any_multiple)
importFrom(igraph,as.directed)
importFrom(igraph,as.undirected)
importFrom(igraph,as_adjacency_matrix)
importFrom(igraph,as_biadjacency_matrix)
importFrom(igraph,as_data_frame)
importFrom(igraph,as_incidence_matrix)
importFrom(igraph,bipartite.projection)
importFrom(igraph,complementer)
importFrom(igraph,decompose)
Expand All @@ -474,8 +482,8 @@ importFrom(igraph,eulerian_path)
importFrom(igraph,get.edgelist)
importFrom(igraph,get.vertex.attribute)
importFrom(igraph,graph_from_adjacency_matrix)
importFrom(igraph,graph_from_biadjacency_matrix)
importFrom(igraph,graph_from_data_frame)
importFrom(igraph,graph_from_incidence_matrix)
importFrom(igraph,gsize)
importFrom(igraph,induced_subgraph)
importFrom(igraph,is.connected)
Expand Down
39 changes: 39 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
# manynet 0.3.0

2023-12-15

## Package

* Overhaul of the README to summarise many of the unique aspects of the package

## Making

* Added `as_tidygraph()` method for diff_model objects
* Added `as_siena()` method for tidygraph objects

## Modifying

* Manipulating functions now called Modifying
* `to_waves()` now works on diff_model objects, add attributes and names
* `is_multiplex()` now recognises a tie/edge 'type' attribute as evidence of multiplexity
* Deleted unnecessary reexports from other packages
- `igraph::is_bipartite()` is superseded by `is_twomode()`
- `tidygraph::activate()` is superseded by `mutate_ties()` and similar functions
* Fixed bug by replacing older `igraph::as_incidence_matrix()` and `igraph::graph_from_incidence_matrix()`
with `igraph::as_biadjacency_matrix()` and `igraph::graph_from_biadjacency_matrix()`

## Mapping

* `autographr()` now plots diff_model objects, showing the diffusion as a heatmap on the vertices
* `autographs()` and `autographd()` now utilise network information in diff_model objects to provide better layouts
* Fixed bug with specifying `node_size` in `autographd()`
* `many_palettes` replaces `iheid_palette`
* Added new palettes, themes and scales for graphs
- `theme_ethz()`, `scale_color_ethz()`/`scale_colour_ethz()`, and `scale_fill_ethz()` for ETH Zürich
- `theme_uzh()`, `scale_color_uzh()`/`scale_colour_uzh()`, and `scale_fill_uzh()` for Uni Zürich
- `theme_rug()`, `scale_color_rug()`/`scale_colour_rug()`, and `scale_fill_rug()` for Uni Gröningen

## Data

* Added `ison_physicians` data that includes four, multiplex networks with adoption data

# manynet 0.2.10

2023-12-06
Expand Down
53 changes: 53 additions & 0 deletions R/data_ison.R
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,56 @@
#' ison_friends
#' ```
"ison_friends"


# Physicians ####

#' Four multiplex one-mode physician diffusion data (Coleman, Katz, and Menzel, 1966)
#'
#' @description
#' Ron Burt prepared this data from
#' Coleman, Katz and Menzel's 1966 study on medical innovation.
#' They had collected data from physicians in four towns in Illinois:
#' Peoria, Bloomington, Quincy and Galesburg.
#' These four networks are held as separate networks in a list.
#'
#' Coleman, Katz and Menzel were concerned with the impact of network ties
#' on the physicians' adoption of a new drug, tetracycline.
#' Data on three types of ties were collected in response to three questions:
#'
#' - advice: "When you need information or advice about questions of therapy
#' where do you usually turn?"
#' - discussion: "And who are the three or four physicians with whom you most often find yourself
#' discussing cases or therapy in the course of an ordinary week – last week for instance?"
#' - friendship: "Would you tell me the first names of your three friends
#' whom you see most often socially?"
#'
#' Additional questions and records of prescriptions provided additional information:
#' - recorded date of tetracycline `adoption` date
#' - years in `practice`
#' (note that these are `{messydates}`-compatible dates)
#' - `conferences` attended
#' (those that attended "Specialty" conferences presumably also attended "General" conferences)
#' - regular subscriptions to medical `journals`
#' - `free_time` spent associating with doctors
#' - `discussions` on medical matters when with other doctors sociallyy
#' - memberships in `clubs` with other doctores
#' - number of top 3 `friends` that are doctors
#' - time practicing in current `community`
#' - `patients` load (ordinal)
#' - physical `proximity` to other physicians (in building/sharing office)
#' - medical `specialty` (GP/Internist/Pediatrician/Other)
#' @docType data
#' @keywords datasets
#' @name ison_physicians
#' @usage data(ison_physicians)
#' @references
#' Coleman, James, Elihu Katz, and Herbert Menzel. 1966.
#' \emph{Medical innovation: A diffusion study}.
#' Indianapolis: The Bobbs-Merrill Company.
#' @source `{networkdata}`
#' @format
#' ```{r, echo = FALSE}
#' ison_physicians
#' ```
"ison_physicians"
32 changes: 24 additions & 8 deletions R/make_as.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ as_edgelist.siena <- function(.data,

#' @rdname as
#' @importFrom dplyr arrange
#' @importFrom igraph edge_attr_names as_adjacency_matrix as_incidence_matrix
#' @importFrom igraph edge_attr_names as_adjacency_matrix as_biadjacency_matrix
#' @importFrom network is.bipartite list.edge.attributes as.matrix.network
#' @export
as_matrix <- function(.data,
Expand Down Expand Up @@ -202,10 +202,10 @@ as_matrix.igraph <- function(.data,
twomode = NULL) {
if ((!is.null(twomode) && twomode) | (is.null(twomode) & is_twomode(.data))) {
if (is_weighted(.data) | is_signed(.data)) {
mat <- igraph::as_incidence_matrix(.data, sparse = FALSE,
mat <- igraph::as_biadjacency_matrix(.data, sparse = FALSE,
attr = igraph::edge_attr_names(.data)[[1]])
} else {
mat <- igraph::as_incidence_matrix(.data, sparse = FALSE,
mat <- igraph::as_biadjacency_matrix(.data, sparse = FALSE,
attr = NULL)
}
} else {
Expand Down Expand Up @@ -293,7 +293,7 @@ as_matrix.siena <- function(.data,
# igraph ####

#' @rdname as
#' @importFrom igraph graph_from_data_frame graph_from_incidence_matrix
#' @importFrom igraph graph_from_data_frame graph_from_biadjacency_matrix
#' graph_from_adjacency_matrix delete_vertex_attr V vertex_attr
#' edge_attr delete_edge_attr set_edge_attr
#' @importFrom network list.edge.attributes as.sociomatrix
Expand Down Expand Up @@ -329,11 +329,11 @@ as_igraph.matrix <- function(.data,
twomode = FALSE) {
if (nrow(.data) != ncol(.data) | twomode) {
if (!(all(.data %in% c(0, 1)))) {
graph <- igraph::graph_from_incidence_matrix(.data,
graph <- igraph::graph_from_biadjacency_matrix(.data,
weighted = TRUE,
directed = FALSE)
} else {
graph <- igraph::graph_from_incidence_matrix(.data,
graph <- igraph::graph_from_biadjacency_matrix(.data,
directed = FALSE)
}
} else {
Expand Down Expand Up @@ -374,10 +374,10 @@ as_igraph.network <- function(.data,
if (network::is.bipartite(.data)) {
if ("weight" %in% network::list.edge.attributes(.data)) {
graph <- network::as.sociomatrix(.data, attrname = "weight")
graph <- igraph::graph_from_incidence_matrix(graph, weighted = TRUE)
graph <- igraph::graph_from_biadjacency_matrix(graph, weighted = TRUE)
} else {
graph <- network::as.sociomatrix(.data)
graph <- igraph::graph_from_incidence_matrix(graph)
graph <- igraph::graph_from_biadjacency_matrix(graph)
}
} else {
if ("weight" %in% network::list.edge.attributes(.data)) {
Expand Down Expand Up @@ -656,6 +656,17 @@ as_tidygraph.siena <- function(.data, twomode = FALSE) {
as_tidygraph(as_igraph.siena(.data, twomode = FALSE))
}

#' @export
as_tidygraph.diff_model <- function(.data, twomode = FALSE) {
out <- as_tidygraph(attr(.data, "network"))
attr(out, "diff_model") <- .data
if (!"name" %in% names(node_attribute(out))) {
out <- add_node_attribute(out, "name",
as.character(seq_len(igraph::vcount(out))))
}
out
}

# Network ####

#' @rdname as
Expand Down Expand Up @@ -775,6 +786,11 @@ as_siena.igraph <- function(.data, twomode = FALSE) {
RSiena::sienaDataCreate(list("depnet" = depnet))
}

#' @export
as_siena.tbl_graph <- function(.data, twomode = FALSE) {
as_siena.igraph(.data, twomode = twomode)
}

# graphAM ####

#' @rdname as
Expand Down
8 changes: 4 additions & 4 deletions R/make_create.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#' using `as_edgelist()`, `as_matrix()`,
#' `as_tidygraph()`, or `as_network()`.
#' @importFrom tidygraph as_tbl_graph
#' @importFrom igraph graph_from_incidence_matrix
#' @importFrom igraph graph_from_biadjacency_matrix
NULL

#' @describeIn create Creates an empty graph of the given dimensions.
Expand Down Expand Up @@ -135,7 +135,7 @@ create_ring <- function(n, directed = FALSE, width = 1, ...) {

#' @describeIn create Creates a graph of the given dimensions
#' that has a maximally central node.
#' @importFrom igraph graph_from_adjacency_matrix graph_from_incidence_matrix
#' @importFrom igraph graph_from_adjacency_matrix graph_from_biadjacency_matrix
#' make_star
#' @examples
#' create_star(12)
Expand Down Expand Up @@ -464,7 +464,7 @@ create_explicit <- function(...){
# #' Will construct an affiliation matrix,
# #' with decreasing fill across n2.
# #' @importFrom tidygraph as_tbl_graph
# #' @importFrom igraph graph_from_incidence_matrix
# #' @importFrom igraph graph_from_biadjacency_matrix
# #' @examples
# #' create_nest(10, 12)
# #' @export
Expand All @@ -474,7 +474,7 @@ create_explicit <- function(...){
# out <- matrix(0, n1, n2)
# out[(row(out) - col(out)) >= 0] <- 1
# if(as == "tidygraph") out <- tidygraph::as_tbl_graph(out)
# if(as == "igraph") out <- igraph::graph_from_incidence_matrix(out)
# if(as == "igraph") out <- igraph::graph_from_biadjacency_matrix(out)
# out
# }
#
Expand Down
1 change: 0 additions & 1 deletion R/manip_from.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ from_subgraphs <- function(.data) {
#' @importFrom dplyr distinct
#' @examples
#' ison_adolescents %>%
#' activate(edges) %>%
#' to_egos() %>%
#' from_egos()
#' @export
Expand Down
Loading

0 comments on commit 824a8d3

Please sign in to comment.