summaryrefslogtreecommitdiff
path: root/R
diff options
context:
space:
mode:
Diffstat (limited to 'R')
-rw-r--r--R/networkplot.R14
1 files changed, 11 insertions, 3 deletions
diff --git a/R/networkplot.R b/R/networkplot.R
index 01627ea..9d251ea 100644
--- a/R/networkplot.R
+++ b/R/networkplot.R
@@ -102,6 +102,9 @@ networkplot <- function(R, groups = NULL, group_label = NULL, title = NULL, r_la
# this includes the hierarchy vertices (root, groups)
# this is required by igraph as a node ID table
vertices <- data.frame(name = unique(c(hierarchy$from, hierarchy$to)))
+ importance <- rowSums(abs(Rm)) / (nrow(Rm) - 1)
+ vertices$importance <- importance[match(vertices$name, rownames(Rm))]
+ vertices$importance[is.na(vertices$importance)] <- 0
# If groups were passed, add a column to vertices called group
if(!is.null(groups)){
@@ -160,10 +163,14 @@ networkplot <- function(R, groups = NULL, group_label = NULL, title = NULL, r_la
ggplot2::aes(
filter = .data$leaf,
colour = .data$group,
+ size = .data$importance,
x = .data$x * 1.05,
y = .data$y * 1.05
- ),
- size = 2
+ )
+ ) +
+ ggplot2::scale_size_continuous(
+ range = c(1, 6), # tweak this
+ guide = "none" # usually better visually
) +
# labels nodes and groups
ggraph::geom_node_text(
@@ -173,14 +180,15 @@ networkplot <- function(R, groups = NULL, group_label = NULL, title = NULL, r_la
x = .data$x * 1.1,
y = .data$y * 1.1,
angle = atan2(.data$y, .data$x) * 180 / pi,
- hjust = atan2(.data$y, .data$x) > pi / 2
),
+ hjust = 0,
size = 2
) +
ggplot2::expand_limits(
x = c(-1.2, 1.2),
y = c(-1.2, 1.2)
) +
+ ggraph::scale_edge_alpha(guide = 'none') +
ggplot2::theme_void()
if(!is.null(title)){