Skip to content

Commit

Permalink
Merge pull request #203 from fdchevalier/pie_circle
Browse files Browse the repository at this point in the history
Nodes of single population improved
  • Loading branch information
zkamvar authored May 2, 2019
2 parents 084ee5e + 1cf5ba9 commit 0b8d9ed
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Authors@R: c(person(c("Zhian", "N."), "Kamvar", role = c("cre", "aut"),
email = "briank.lists@gmail.com", comment = c(ORCID = "0000-0003-1665-4343")),
person(c("Patrick", "G."), "Meirmans", role = "ctb",
email = "p.g.meirmans@uva.nl", comment = c(ORCID = "0000-0002-6395-8107")),
person(c("Frédéric", "D."), "Chevalier", role = "ctb",
email = "fcheval@txbiomed.org", comment = c(ORCID = "0000-0003-2611-8106")),
person(c("Niklaus", "J."), "Grunwald", role = "ths",
email = "grunwaln@science.oregonstate.edu", comment = c(ORCID = "0000-0003-1656-7602")))
Maintainer: Zhian N. Kamvar <zkamvar@gmail.com>
Expand Down
7 changes: 7 additions & 0 deletions R/internal.r
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,13 @@ update_poppr_graph <- function(graphlist, PALETTE){
if (nrow(lookup) > 1){
colorlist <- V(graphlist$graph)$pie.color
V(graphlist$graph)$pie.color <- lapply(colorlist, update_colors, lookup)
# Update color vector for circles if present
pie.single <- lengths(V(graphlist$graph)$pie) == 1
if (any(pie.single)) {
the_circles <- unlist(V(graphlist$graph)$pie.color[pie.single])
V(graphlist$graph)$color[pie.single] <- the_circles # set the color palette
names(V(graphlist$graph)$color)[pie.single] <- names(the_circles) # set the population names
}
} else {
colorlist <- V(graphlist$graph)$color
V(graphlist$graph)$color <- rep(PALETTE(1), length(colorlist))
Expand Down
17 changes: 15 additions & 2 deletions R/msn_handlers.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ msn_constructor <-
mlg.cp <- mlg.cp[rank(cmlg)]
# This creates a list of colors corresponding to populations.
mlg.color <- lapply(mlg.cp, function(x) color[pnames %in% names(x)])
# Set shape and circle color vectors
mlg.sp <- rep("pie", length(mlg.cp)) # set shape
names(mlg.sp) <- names(mlg.cp)
mlg.cc <- rep(NA, length(mlg.cp)) # set circle color
names(mlg.cc) <- names(mlg.cp)
# Transform pie made of single population into circle
pie.single <- lengths(mlg.cp) == 1
if (any(pie.single)) {
mlg.sp[pie.single] <- "circle"
mlg.cc[pie.single] <- unlist(mlg.color[pie.single])
}
}


Expand Down Expand Up @@ -194,9 +205,10 @@ msn_constructor <-
edge.width = E(mst)$width,
edge.color = E(mst)$color,
vertex.size = sqrt(mlg.number) * 5,
vertex.shape = "pie",
vertex.shape = mlg.sp,
vertex.pie = mlg.cp,
vertex.pie.color = mlg.color,
vertex.color = mlg.cc,
vertex.label = vlab,
...
)
Expand Down Expand Up @@ -227,9 +239,10 @@ msn_constructor <-

V(mst)$size <- sqrt(mlg.number)
if (piece_of_pie){
V(mst)$shape <- "pie"
V(mst)$shape <- mlg.sp
V(mst)$pie <- mlg.cp
V(mst)$pie.color <- mlg.color
V(mst)$color <- mlg.cc
} else {
V(mst)$color <- color
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-msn.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ sbruv_no_ties <- bruvo.msn(gend_single, replen = c(1,1), showplot = FALSE)
sbruv_ties <- bruvo.msn(gend_single, replen = c(1,1), showplot = FALSE, include.ties = TRUE)
spmsn_no_ties <- poppr.msn(gend_single, distmat = gend_bruvo, showplot = FALSE)
spmsn_ties <- poppr.msn(gend_single, distmat = gend_bruvo, showplot = FALSE, include.ties = TRUE)
pienames <- c("name", "size", "shape", "pie", "pie.color", "label")
pienames <- c("name", "size", "shape", "pie", "pie.color", "color", "label")
nopienames <- c("name", "size", "color", "label")

context("Input parameter tests")
Expand Down

0 comments on commit 0b8d9ed

Please sign in to comment.