Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.4.2 #62

Merged
merged 29 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3b16c80
Closed #57 by adding on.exit line to play_diffusions()
jhollway Jan 25, 2024
6b0c375
Fixed bug in generate_random() for two-mode networks with specified n…
jhollway Jan 31, 2024
445840f
Fixed bug with edge sizes when plotting weighted networks using `auto…
henriquesposito Feb 23, 2024
604acc3
to_reciprocated.matrix now uses matrix addition
jhollway Feb 16, 2024
506643d
Updated `autographd()` to fix bugs related to node and edge colors an…
henriquesposito Feb 27, 2024
1a700a3
Updated `autographd()`to work with unbalanced network lists and retai…
henriquesposito Feb 28, 2024
7823d19
Uncomented some examples for `autographr()`
henriquesposito Feb 29, 2024
7a9416a
Updated themes to be compatible with newer and older versions of `{gg…
henriquesposito Mar 4, 2024
e756bcc
Updated examples in `autographr()`
henriquesposito Mar 4, 2024
582f60d
Updated examples for themes and scales
henriquesposito Mar 4, 2024
8f38254
Fixed a small issue with the latest changes in `autographd()`
henriquesposito Mar 4, 2024
78bc7ea
Updated the lineage layout to base it self on a hierarchical two mode…
henriquesposito Mar 6, 2024
79ed308
Updated label placement in `autographr()` to avoid label overlaps across
henriquesposito Mar 6, 2024
417b711
Updated layout partition to correctly fix node placement in Y axis
henriquesposito Mar 6, 2024
d296a5b
Updated label placement for lineage layout
henriquesposito Mar 6, 2024
0b3e7f2
Updated lineage layout to check for overalaping nodes
henriquesposito Mar 7, 2024
48243a4
Fixed issues with hierarchy layout when "center" is declared
henriquesposito Mar 8, 2024
858e4b3
Fixed label positions for hierarchy layouts
henriquesposito Mar 8, 2024
bf1c108
Updated version in DESCRIPTION file
henriquesposito Mar 11, 2024
179f2a6
Updated NEWS file to match PR
henriquesposito Mar 11, 2024
ef65975
"configuration" layout added to direct to relevant triad/quad layout
jhollway Mar 8, 2024
4ecdaa3
Updated tests for `autographr()`
henriquesposito Mar 11, 2024
5f6ac84
Updated tests for `to_reciprocated.matrix()`
henriquesposito Mar 11, 2024
7956be6
Standardised reference to edge variables for edge-related graphing ar…
jaeltan Mar 12, 2024
edc76f8
Updated NEWS file
henriquesposito Mar 12, 2024
bce3c55
Updated NEWS file
henriquesposito Mar 12, 2024
9b76267
Updated CRAN comments
henriquesposito Mar 12, 2024
a217154
Reverted description for edge size and color arguments in `autographr…
henriquesposito Mar 12, 2024
278ea9b
Updated name for helper function to check colors for consistency.
henriquesposito Mar 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: manynet
Title: Many Ways to Make, Modify, Mark, and Map Myriad Networks
Version: 0.4.1
Date: 2024-01-24
Version: 0.4.2
Date: 2024-03-12
Description: A set of tools for making, modifying, marking, 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.
Expand All @@ -15,7 +15,7 @@ License: MIT + file LICENSE
Language: en-GB
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.0
RoxygenNote: 7.3.1
Imports:
dplyr (>= 1.1.0),
ggplot2,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ export(join_ties)
export(labs)
export(layout_tbl_graph_alluvial)
export(layout_tbl_graph_concentric)
export(layout_tbl_graph_configuration)
export(layout_tbl_graph_hierarchy)
export(layout_tbl_graph_ladder)
export(layout_tbl_graph_lineage)
Expand Down
20 changes: 20 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# manynet 0.4.2

2024-03-12

## Making

- Closed #57 by updating `play_diffusions()` to revert future plan on exit
- Fixed bug with how `generate_random()` works for two-mode networks with specified number of ties

## Mapping

- Closed #6 by updating how "lineage" layout works and places nodes on Y axis
- Closed #39 by making `autographr()` more flexible and efficient in setting variables to aesthetics
- Updated themes to be compatible with newer and older versions of `{ggplot2}`
- Added "configuration" layout for small triad/quad networks

## Modifying

- Updated `to_reciprocated.matrix()` to consistently work with matrices

# manynet 0.4.1

2023-12-24
Expand Down
2 changes: 1 addition & 1 deletion R/make_generate.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
if(!as.integer(p)==p) stop("`p` must be an integer if above 1.")
g <- igraph::sample_bipartite(n[1], n[2],
m = p,
type = "gmp",
type = "gnm",

Check warning on line 82 in R/make_generate.R

View check run for this annotation

Codecov / codecov/patch

R/make_generate.R#L82

Added line #L82 was not covered by tests
directed = directed,
mode = "out")
} else {
Expand Down
5 changes: 4 additions & 1 deletion R/make_play.R
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,11 @@
verbose = FALSE) {
thisRequires("future")
thisRequires("furrr")
oplan <- future::plan(strategy)
on.exit(future::plan(oplan), add = TRUE)

Check warning on line 261 in R/make_play.R

View check run for this annotation

Codecov / codecov/patch

R/make_play.R#L260-L261

Added lines #L260 - L261 were not covered by tests

if(missing(steps)) steps <- network_nodes(.data)
future::plan(strategy)

out <- furrr::future_map_dfr(1:times, function(j){
data.frame(sim = j,
play_diffusion(.data,
Expand Down
2 changes: 1 addition & 1 deletion R/manip_reformat.R
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ to_reciprocated.tbl_graph <- function(.data) {

#' @export
to_reciprocated.matrix <- function(.data) {
as_matrix(to_reciprocated(as_igraph(.data)))
.data + t(.data)
}

#' @export
Expand Down
218 changes: 98 additions & 120 deletions R/map_autographr.R

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions R/map_layout_configurations.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
#' Layout algorithms based on configurational positions
#'
#' @description
#' Configurational layouts locate nodes at symmetric coordinates
#' to help illustrate the particular layouts.
#' Currently "triad" and "quad" layouts are available.
#' The "configuration" layout will choose the appropriate configurational
#' layout automatically.
#'
#' @name configuration_layouts
#' @family mapping
#' @inheritParams partition_layouts
NULL

#' @rdname configuration_layouts
#' @export
layout_tbl_graph_configuration <- function(.data,
circular = FALSE, times = 1000){
if (network_nodes(.data) == 3) {
layout_tbl_graph_triad(.data, circular = circular, times = times)
} else if (network_nodes(.data) == 4) {
layout_tbl_graph_quad(.data, circular = circular, times = times)

Check warning on line 22 in R/map_layout_configurations.R

View check run for this annotation

Codecov / codecov/patch

R/map_layout_configurations.R#L19-L22

Added lines #L19 - L22 were not covered by tests
}}

#' @rdname configuration_layouts
#' @export
layout_tbl_graph_triad <- function(.data,
Expand Down
57 changes: 14 additions & 43 deletions R/map_layout_partition.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ layout_tbl_graph_hierarchy <- function(.data, center = NULL,
if (is.null(center)) {
thisRequiresBio("Rgraphviz")
prep <- as_matrix(.data, twomode = FALSE)
if(anyDuplicated(rownames(prep))){
if(anyDuplicated(rownames(prep))) {
rownames(prep) <- seq_len(nrow(prep))
colnames(prep) <- seq_len(ncol(prep))
}
Expand All @@ -84,15 +84,13 @@ layout_tbl_graph_hierarchy <- function(.data, center = NULL,
Evt2 <- cbind(rep(2, floor(ncol(net)/2)), nrm(rng(floor(mm/2))))
crd <- rbind(Act, Evt1, Evt2)
crd[which(is.nan(crd))] <- 0.5
crd[, 2] <- crd[, 2] * cos(pi) - crd[, 1] * sin(pi)
rownames(crd) <- c(dimnames(net)[[1]], dimnames(net)[[2]])
} else if (center == "events") {
Act1 <- cbind(rep(0, ceiling(nrow(net)/2)), nrm(rng(ceiling(nn/2))))
Act2 <- cbind(rep(2, floor(nrow(net)/2)), nrm(rng(floor(nn/2))))
Evt <- cbind(rep(1, ncol(net)), nrm(rng(mm)))
crd <- rbind(Act1, Act2, Evt)
crd[which(is.nan(crd))] <- 0.5
crd[, 2] <- crd[, 2] * cos(pi) - crd[, 1] * sin(pi)
rownames(crd) <- c(dimnames(net)[[1]], dimnames(net)[[2]])
} else {
if (center %in% node_names(.data)) {
Expand All @@ -107,7 +105,6 @@ layout_tbl_graph_hierarchy <- function(.data, center = NULL,
}
crd <- rbind(side1, side2)
crd[which(is.nan(crd))] <- 0.5
crd[, 2] <- crd[, 2] * cos(pi) - crd[, 1] * sin(pi)
rownames(crd) <- c(dimnames(net)[[1]], dimnames(net)[[2]])
} else stop("Please declare actors, events, or a node name as center.")
}
Expand Down Expand Up @@ -139,7 +136,7 @@ layout_tbl_graph_alluvial <- function(.data,
#' @rdname partition_layouts
#' @export
layout_tbl_graph_railway <- function(.data,
circular = FALSE, times = 1000){
circular = FALSE, times = 1000) {
res <- layout_tbl_graph_hierarchy(as_igraph(.data))
res$x <- c(match(res[res[,2]==0,1], sort(res[res[,2]==0,1])),
match(res[res[,2]==1,1], sort(res[res[,2]==1,1])))
Expand Down Expand Up @@ -239,52 +236,21 @@ layout_tbl_graph_lineage <- function(.data, rank, circular = FALSE) {
if (length(rank) > 1 & length(rank) != length(.data)) {
stop("Please pass the function a `rank` node attribute or a vector.")
} else if (length(rank) != length(.data)) {
rank <- node_attribute(.data, rank)
if (!is.numeric(rank))
stop("Please declare a numeric attribute to `rank` nodes.")
rank <- as.numeric(node_attribute(.data, rank))
}
thisRequiresBio("Rgraphviz")
prep <- as_matrix(.data, twomode = FALSE)
if(anyDuplicated(rownames(prep))){
rownames(prep) <- seq_len(nrow(prep))
colnames(prep) <- seq_len(ncol(prep))
}
if(any(prep<0)) prep[prep<0] <- 0
out <- as_graphAM(prep)
out <- suppressMessages(Rgraphviz::layoutGraph(out, layoutType = 'dot',
attrs = list(graph = list(rankdir = "BT"))))
nodeX <- .rescale(out@renderInfo@nodes$nodeX)
names <- names(nodeX)
nodeY <- .rescale(rank*(-1))
.to_lo(.adjust(nodeX, nodeY, names))
out <- layout_tbl_graph_alluvial(
as_igraph(mutate(.data, type = ifelse(
rank > mean(rank), TRUE, FALSE)), twomode = TRUE))
out$x <- .rescale(rank)
.check_dup(out)
}

.rescale <- function(vector){
(vector - min(vector)) / (max(vector) - min(vector))
}

.adjust <- function(x, y, names) {
out <- data.frame(cbind(x, y, names))
adj <- data.frame()
for (k in levels(as.factor(y))) {
a <- subset(out, y == k)
if (length(a[,1]) == 1) {
a[,1] <- ifelse(a[,1] > 0.8, as.numeric(a[,1])*0.8,
ifelse(a[,1] < 0.2, as.numeric(a[,1])*1.2,
as.numeric(a[,1])))
} else if (length(a[,1]) > 2) {
a[,1] <- seq(min(a[,1]), max(a[,1]), len = length(a[,1]))
}
adj <- rbind(adj, a)
}
name <- data.frame(names = out[,3])
out <- dplyr::left_join(name, adj, by = "names")
out <- apply(out[,2:3], 2, as.numeric)
rownames(out) <- name$names
out
}

.to_lo <- function(mat){
.to_lo <- function(mat) {
res <- as.data.frame(mat)
names(res) <- c("x","y")
res
Expand All @@ -299,6 +265,11 @@ to_list <- function(members){
out
}

.check_dup <- function(mat) {
mat$y <- ifelse(duplicated(mat[c('x','y')]), mat$y*0.95, mat$y)
mat
}

#' @importFrom igraph degree
getNNvec <- function(.data, members){
lapply(members, function(circle){
Expand Down
Loading
Loading