Skip to content

Commit

Permalink
Fix a bug to plot several sub-populations
Browse files Browse the repository at this point in the history
  • Loading branch information
aursiber committed May 22, 2020
1 parent e9eb428 commit 00623fe
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions R/mondrian.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ mondrian <- function(data, labels = colnames(data), xlab = "", ylab = "" , main

if(!is.null(pop)) { ## Individuals are grouped in sub-populations

labelpop <- levels(unique(data[, pop]))
labelpop <- as.vector(unique(data$pop))
nbpop <- length(labelpop)

## Graphic window management
nrow <- floor(sqrt(nbpop + 1))
par(mfrow = c(nrow, ceiling(nbpop / nrow)))
nbrow <- floor(sqrt(nbpop + 1))
par(mfrow = c(nbrow, ceiling(nbpop / nbrow)))

outpop <- list()
## Results for each sub-population
subpop <- by(data, data[, pop], function(x) mondrian(x[, - pop], pop = NULL, xlab = xlab, ylab = ylab, main = unique(x[, pop]), col = col, indiv = indiv, ...))
subpop <- by(data, data$pop, function(x) mondrian(x[, -pop], pop = NULL, xlab = xlab, ylab = ylab, main = unique(x[, pop]), col = col, indiv = indiv, ...))
outpop <- lapply(subpop, function(x) x)
names(outpop) <- labelpop

## Result if all individuals belong to the same population
outpop$pop <- mondrian(data[, - pop], xlab = xlab, ylab = ylab , main = "Total population", col = col, pop = NULL, indiv = indiv, ...)
outpop$pop <- mondrian(data[, -pop], xlab = xlab, ylab = ylab , main = "Total population", col = col, pop = NULL, indiv = indiv, ...)
par(mfrow = c(1, 1))
invisible(outpop)

Expand Down

0 comments on commit 00623fe

Please sign in to comment.