summaryrefslogtreecommitdiff
path: root/R
diff options
context:
space:
mode:
authorChris Sobczak <chris@sobczak.family>2026-06-15 20:04:48 -0700
committerChris Sobczak <chris@sobczak.family>2026-06-15 20:04:48 -0700
commit25cb322d244542d76613bb5918d06cc86b24bf20 (patch)
tree445247ad323ac1c811ec27a1857bcb736cc9baf6 /R
parentd5c80a572e0e08c1a96f1d629fa9984f333b0195 (diff)
Adjust
Diffstat (limited to 'R')
-rw-r--r--R/networkplot.R20
1 files changed, 16 insertions, 4 deletions
diff --git a/R/networkplot.R b/R/networkplot.R
index 10dfc01..b95d979 100644
--- a/R/networkplot.R
+++ b/R/networkplot.R
@@ -10,15 +10,27 @@
#' @param title Optional plot title
#' @param groups Optional data.frame mapping nodes to groups
#' @param group_label Optional string labeling the kind of grouping
-#' @param r_label The string naming the relationship type (default 'Correlation')
#'
#' @return A ggraph object
#'
#' @import ggraph
#' @import igraph
#'
+#' @example
+#' set.seed(1)
+#' X <- matrix(rnorm(100), ncol = 10)
+#' colnames(X) <- letters[1:10]
+#' R <- cor(X)
+#' networkplot(R, title = 'Networkplot without groups')
+#'
+#' groups <- data.frame(
+#' node = letters[1:5],
+#' group = c(rep('A', 5), rep('B', 5))
+#' )
+#' networkplot(R, groups = groups, group_label = 'Letter', title = 'Networkplot with groups')
+#'
#' @export
-networkplot <- function(R, groups = NULL, group_label = NULL, title = NULL, r_label = 'Correlation'){
+networkplot <- function(R, groups = NULL, group_label = NULL, title = NULL){
Rm <- tryCatch({
if(is.matrix(R)){
if(nrow(R) != ncol(R)) stop('R must be square')
@@ -140,8 +152,7 @@ networkplot <- function(R, groups = NULL, group_label = NULL, title = NULL, r_la
mid = 'white',
high = 'blue',
midpoint = 0,
- limits = c(-1, 1),
- name = r_label
+ limits = c(-1, 1)
) +
# operates on node data from the layout
# leaf is a logical vector (provided by the ggraph object g)
@@ -177,6 +188,7 @@ networkplot <- function(R, groups = NULL, group_label = NULL, title = NULL, r_la
y = c(-1.2, 1.2)
) +
ggraph::scale_edge_alpha(guide = 'none') +
+ ggplot2::guides(edge_colour = 'none') +
ggplot2::theme_void()
if(!is.null(title)){