Skip to content

Commit

Permalink
nsides and size working again
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Sep 12, 2023
1 parent c25d8b0 commit 479154f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
2 changes: 0 additions & 2 deletions R/geometry.R
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,3 @@ map_attribute_to_shape <- function(x) {

}



41 changes: 26 additions & 15 deletions R/netplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,31 @@ nplot.default <- function(
netenv$M <- nrow(edgelist)
netenv$graph_class <- class(x)

# Mapping attributes ---------------------------------------------------------

# Nsides
if (length(vertex.nsides) && inherits(vertex.nsides, "formula")) {

rhs <- as.character(vertex.nsides[[2]])
vertex.nsides <- map_attribute_to_shape(
get_graph_attribute(graph = x, attribute = rhs)
)

}

# And size
if (length(vertex.size) && inherits(vertex.size, "formula")) {

rhs <- as.character(vertex.size[[2]])
vertex.size <- get_graph_attribute(graph = x, attribute = rhs)

# Now check if it is numeric. If not, it should return an error
if (!is.numeric(vertex.size)) {
stop("vertex.size must be numeric")
}

}

# Sampling edges -------------------------------------------------------------
if (sample.edges < 1) {

Expand Down Expand Up @@ -332,11 +357,6 @@ nplot.default <- function(
if (length(netenv[[p]]) > 0 && length(netenv[[p]]) < netenv$N)
netenv[[p]] <- .rep(netenv[[p]], netenv$N)

# New: Handling vertex shape
if (!is.character(nsides) && !is.numeric(nsides)) {
stop("nsides parameter must be a character string or a numeric value")
}

# Checking defaults for edges
edge_par <- ls(pattern = "^edge\\.", envir = netenv)
for (p in edge_par)
Expand Down Expand Up @@ -413,19 +433,10 @@ nplot.default <- function(
)

# Generating grobs -----------------------------------------------------------
if (length(vertex.nsides) && inherits(vertex.nsides, "formula")) {

rhs <- as.character(vertex.nsides[[2]])
vertex.nsides <- map_attribute_to_shape(
get_graph_attribute(graph = x, attribute = rhs)
)

}

if (!skip.vertex) {
grob.vertex <- vector("list", netenv$N)
for (v in 1:netenv$N)
grob.vertex[[v]] <- grob_vertex(netenv, v, nsides = nsides) # Pass nsides parameter
grob.vertex[[v]] <- grob_vertex(netenv, v)
} else
grob.vertex <- NULL

Expand Down
4 changes: 3 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ data("UKfaculty", package = "igraphdata")
l <- layout_with_fr(UKfaculty)
plot(UKfaculty, layout = l) # ala igraph
nplot(UKfaculty, layout = l, vertex.nsides = ~ Group) # ala netplot
V(UKfaculty)$ss <- runif(vcount(UKfaculty))
nplot(UKfaculty, layout = l, vertex.nsides = ~ Group, vertex.size = ~ ss) # ala netplot
sna::gplot(intergraph::asNetwork(UKfaculty), coord=l)
```

Expand Down

0 comments on commit 479154f

Please sign in to comment.