R/Biplots.r

Defines functions Biplots

Documented in Biplots

Biplots <-
function (Data, groups = rep(1, nrow(Data)), PointLabels = rownames(Data), 
    AxisLabels = colnames(Data), excel = NULL, ExcelGroupsCol = 0) 
{
    tclRequire("BWidget")
    if (!missing(excel) | !missing(ExcelGroupsCol)) {
        stop("Due to the removal of the `xlsReadWrite' package from CRAN, the direct import of data from Excel 1997-2003 files has been deprecated as from BiplotGUI 0.0-4.1. As an alternative mechanism, consider the `RODBC' package.")
    }
    Data <- as.matrix(Data)
    n <- nrow(Data)
    n.in <- n
    samples.in <- 1:n
    samples.in.PreviousScaling <- samples.in
    if (missing(PointLabels) && is.null(PointLabels)) 
        PointLabels <- 1:n
    group <- substr(groups, start = 1, stop = 14)
    group <- factor(group, exclude = NULL)
    g <- nlevels(group)
    g.in <- g
    g.n <- as.numeric(table(group))
    g.n.in <- g.n
    groups.in <- 1:g
    p <- ncol(Data)
    p.in <- p
    variables.in <- 1:p
    if (missing(AxisLabels) && is.null(AxisLabels)) 
        AxisLabels <- paste("V", 1:p, sep = "")
    eps <- 1e-08
    boptions <- list()
    boptions$MDS.convergence <- 1e-06
    boptions$MDS.MaximumIterations <- 5000
    boptions$Procrustes.convergence <- 1e-06
    boptions$Procrustes.MaximumIterations <- 5000
    boptions$IterationsToLiveUpdate <- 5
    boptions$ReuseExternalWindows <- FALSE
    boptions$ThreeD.FlyBy <- FALSE
    boptions$ThreeD.MouseButtonAction <- c("trackball", "zoom", 
        "fov")
    boptions$axes.tick.inter.n <- rep(20, p)
    boptions$ExternalGraphWidth <- 7
    boptions$ExternalGraphHeight <- 7
    boptions$BiplotRegion.WithoutLegend.Main.mar <- c(2, 4, 2, 
        4)
    boptions$BiplotRegion.WithLegend.Main.mar <- c(1, 4, 4, 4)
    boptions$BiplotRegion.WithLegend.Legend.mar <- c(0, 0, 0, 
        0)
    boptions$DiagnosticGraphs.External.WithoutLegend.mar <- c(2, 
        4, 2, 4)
    boptions$DiagnosticGraphs.External.WithLegend.Main.mar <- c(1, 
        4, 4, 4)
    boptions$DiagnosticGraphs.External.WithLegend.Legend.mar <- c(0, 
        0, 0, 0)
    boptions$DiagnosticGraphs.Screen.mar <- c(2.5, 3, 2.5, 2)
    boptions$Legend.cex <- 0.65
    boptions$Legend.TextString <- "12345678901234"
    bpar <- list()
    bpar.initialise1.func <- function() {
        bpar$groups.label.text <<- levels(group)
        if (g == 1) 
            bpar$gpoints.pch <<- 22
        else bpar$gpoints.pch <<- rep(21:25, length.out = g)
        bpar$gpoints.cex <<- rep(1, g)
        bpar$gpoints.col.fg <<- rep("black", g)
        if (g == 1) 
            bpar$gpoints.col.bg <<- "red"
        else bpar$gpoints.col.bg <<- hcl(seq(0, 360, length = g + 
            2)[-c(1, g + 2)], 200, 60)
        bpar$gpoints.label.font <<- rep(1, g)
        bpar$gpoints.label.cex <<- rep(0.85, g)
        if (g == 1) 
            bpar$gpoints.label.col <<- "black"
        else bpar$gpoints.label.col <<- hcl(seq(0, 360, length = g + 
            2)[-c(1, g + 2)], 200, 60)
        bpar$gpoints.label.HorizOffset <<- rep(0, g)
        bpar$gpoints.label.VertOffset <<- rep(-1, g)
        bpar$ANewSample.pch <<- 22
        bpar$ANewSample.cex <<- 2
        bpar$ANewSample.col.fg <<- "black"
        bpar$ANewSample.col.bg <<- "black"
        bpar$ANewSample.label.text <<- "Interpolated"
        bpar$ANewSample.label.font <<- 2
        bpar$ANewSample.label.cex <<- 1
        bpar$ANewSample.label.col <<- "black"
        bpar$ANewSample.label.HorizOffset <<- 0
        bpar$ANewSample.label.VertOffset <<- -1
        bpar$ANewSample.LabelsInBiplot <<- TRUE
        if (g == 1) 
            bpar$gSampleGroupMeans.pch <<- 22
        else bpar$gSampleGroupMeans.pch <<- rep(21:25, length.out = g)
        bpar$gSampleGroupMeans.cex <<- rep(2, g)
        bpar$gSampleGroupMeans.col.fg <<- rep("black", g)
        if (g == 1) 
            bpar$gSampleGroupMeans.col.bg <<- "red"
        else bpar$gSampleGroupMeans.col.bg <<- hcl(seq(0, 360, 
            length = g + 2)[-c(1, g + 2)], 200, 60)
        bpar$gSampleGroupMeans.label.font <<- rep(2, g)
        bpar$gSampleGroupMeans.label.cex <<- rep(1, g)
        if (g == 1) 
            bpar$gSampleGroupMeans.label.col <<- "black"
        else bpar$gSampleGroupMeans.label.col <<- hcl(seq(0, 
            360, length = g + 2)[-c(1, g + 2)], 200, 60)
        bpar$gSampleGroupMeans.label.HorizOffset <<- rep(0, g)
        bpar$gSampleGroupMeans.label.VertOffset <<- rep(-1.1, 
            g)
        bpar$SampleGroupMeans.LabelsInBiplot <<- TRUE
        bpar$gConvexHullAlphaBag.lty <<- rep(1, g)
        bpar$gConvexHullAlphaBag.lwd <<- rep(4, g)
        if (g == 1) 
            bpar$gConvexHullAlphaBag.col.fg <<- hcl(0, 0, 60)
        else bpar$gConvexHullAlphaBag.col.fg <<- hcl(seq(0, 360, 
            length = g + 2)[-c(1, g + 2)], 200, 60)
        if (g == 1) 
            bpar$gConvexHullAlphaBag.col.bg <<- hcl(0, 0, 85)
        else bpar$gConvexHullAlphaBag.col.bg <<- hcl(seq(0, 360, 
            length = g + 2)[-c(1, g + 2)], 20, 85)
        bpar$gConvexHullAlphaBag.TukeyMedian.pch <<- rep(0, g)
        bpar$gConvexHullAlphaBag.TukeyMedian.cex <<- rep(2, g)
        if (g == 1) 
            bpar$gConvexHullAlphaBag.TukeyMedian.col.fg <<- "red"
        else bpar$gConvexHullAlphaBag.TukeyMedian.col.fg <<- hcl(seq(0, 
            360, length = g + 2)[-c(1, g + 2)], 200, 60)
        bpar$gConvexHullAlphaBag.TukeyMedian.col.bg <<- rep(NA, 
            g)
        bpar$gConvexHullAlphaBag.TukeyMedian.label.font <<- rep(4, 
            g)
        bpar$gConvexHullAlphaBag.TukeyMedian.label.cex <<- rep(1, 
            g)
        if (g == 1) 
            bpar$gConvexHullAlphaBag.TukeyMedian.label.col <<- "black"
        else bpar$gConvexHullAlphaBag.TukeyMedian.label.col <<- hcl(seq(0, 
            360, length = g + 2)[-c(1, g + 2)], 200, 60)
        bpar$gConvexHullAlphaBag.TukeyMedian.label.HorizOffset <<- rep(0, 
            g)
        bpar$gConvexHullAlphaBag.TukeyMedian.label.VertOffset <<- rep(-1, 
            g)
        bpar$ConvexHullAlphaBag.TukeyMedian.LabelsInBiplot <<- FALSE
        if (g == 1) 
            bpar$gClassificationRegion.col.bg <<- NA
        else bpar$gClassificationRegion.col.bg <<- hcl(seq(0, 
            360, length = g + 2)[-c(1, g + 2)], 25, 95)
        bpar$ClassificationRegion.PixelsPerBiplotDimension <<- 150
    }
    bpar.initialise1.func()
    bpar.initialise2.func <- function() {
        bpar$axes.label.text <<- substr(AxisLabels, start = 1, 
            stop = 14)
        bpar$axes.lty <<- rep(1, p)
        bpar$axes.lwd <<- rep(1, p)
        bpar$axes.col <<- hcl(h = seq(0, 360, length = p + 2), 
            l = 40, c = 110)[-c(1, p + 2)]
        bpar$axes.tick.n <<- rep(5, p)
        bpar$axes.tick.lty <<- rep(1, p)
        bpar$axes.tick.lwd <<- rep(1, p)
        bpar$axes.tick.col <<- bpar$axes.col
        bpar$axes.tick.RelLength <<- rep(0.0075, p)
        bpar$axes.marker.font <<- rep(1, p)
        bpar$axes.marker.cex <<- rep(0.75, p)
        bpar$axes.marker.col <<- bpar$axes.col
        bpar$axes.marker.RelOffset <<- rep(0.005, p)
        bpar$axes.label.font <<- rep(1, p)
        bpar$axes.label.cex <<- rep(0.75, p)
        bpar$axes.label.las <<- rep(1, p)
        bpar$axes.label.col <<- bpar$axes.col
    }
    bpar.initialise2.func()
    bpar.initialise3.func <- function() {
        bpar$interaction.prediction.lty <<- 3
        bpar$interaction.prediction.lwd <<- 1.5
        bpar$interaction.prediction.col <<- "black"
        bpar$interaction.prediction.pch <<- 19
        bpar$interaction.prediction.cex <<- 1
        bpar$interaction.prediction.circle.lwd <<- 1
        bpar$interaction.prediction.circle.col <<- "gray75"
        bpar$interaction.highlight.axes.col.fg <<- "blue"
        bpar$interaction.highlight.axes.col.bg <<- "gray85"
        bpar$interaction.highlight.ShowValues.font <<- 1
        bpar$interaction.highlight.ShowValues.cex <<- 0.75
        bpar$interaction.highlight.ShowValues.col <<- "gray75"
        bpar$interaction.highlight.ShowValues.HorizOffset <<- 0
        bpar$interaction.highlight.ShowValues.VertOffset <<- 1
        bpar$interaction.highlight.ShowValues.digits <<- 3
    }
    bpar.initialise3.func()
    bpar.initialise4.func <- function() {
        bpar$DiagnosticTabs.convergence.lty <<- 1
        bpar$DiagnosticTabs.convergence.lwd <<- 1
        bpar$DiagnosticTabs.convergence.col <<- "red"
        bpar$DiagnosticTabs.predictivities.axes.pch <<- 19
        bpar$DiagnosticTabs.predictivities.cex <<- 1
        bpar$DiagnosticTabs.predictivities.label.font <<- 1
        bpar$DiagnosticTabs.predictivities.label.cex <<- 0.85
        bpar$DiagnosticTabs.predictivities.label.HorizOffset <<- 0
        bpar$DiagnosticTabs.predictivities.label.VertOffset <<- -1
        bpar$DiagnosticTabs.predictivities.diagonal.col <<- "black"
        bpar$DiagnosticTabs.ShepardDiagram.pch <<- 1
        bpar$DiagnosticTabs.ShepardDiagram.cex <<- 1
        bpar$DiagnosticTabs.ShepardDiagram.col.fg <<- "gray50"
        bpar$DiagnosticTabs.ShepardDiagram.col.bg <<- "white"
        bpar$DiagnosticTabs.ShepardDiagram.disparities.lty <<- 1
        bpar$DiagnosticTabs.ShepardDiagram.disparities.lwd <<- 1
        bpar$DiagnosticTabs.ShepardDiagram.disparities.col.line <<- "orange"
        bpar$DiagnosticTabs.ShepardDiagram.disparities.pch <<- 22
        bpar$DiagnosticTabs.ShepardDiagram.disparities.cex <<- 0.4
        bpar$DiagnosticTabs.ShepardDiagram.disparities.col.fg <<- "steelblue"
        bpar$DiagnosticTabs.ShepardDiagram.disparities.col.bg <<- "steelblue"
        bpar$DiagnosticTabs.ShepardDiagram.digits <<- 3
        bpar$DiagnosticTabs.ShepardDiagram.WorstFittingPointPairs <<- 5
        bpar$DiagnosticTabs.predictions.digits <<- 3
    }
    bpar.initialise4.func()
    bpar.defaults <- bpar
    bparp <- list()
    bparp.func <- function() {
        bparp <<- list()
        temp1 <- order(order(group))
        bparp$points.pch <<- rep(bpar$gpoints.pch, times = g.n)[temp1]
        bparp$points.cex <<- rep(bpar$gpoints.cex, times = g.n)[temp1]
        bparp$points.col.fg <<- rep(bpar$gpoints.col.fg, times = g.n)[temp1]
        bparp$points.col.bg <<- rep(bpar$gpoints.col.bg, times = g.n)[temp1]
        bparp$points.label.text <<- PointLabels
        bparp$points.label.font <<- rep(bpar$gpoints.label.font, 
            times = g.n)[temp1]
        bparp$points.label.cex <<- rep(bpar$gpoints.label.cex, 
            times = g.n)[temp1]
        bparp$points.label.col <<- rep(bpar$gpoints.label.col, 
            times = g.n)[temp1]
        bparp$points.label.HorizOffset <<- rep(bpar$gpoints.label.HorizOffset, 
            times = g.n)[temp1]
        bparp$points.label.VertOffset <<- rep(bpar$gpoints.label.VertOffset, 
            times = g.n)[temp1]
    }
    graphics.off()
    mytkrplot <- function(fun, hscale = 1, vscale = 1, ...) {
        image <- paste("Rplot", .make.tkindex(), sep = "")
        .my.tkdev(hscale, vscale)
        try(fun())
        .Tcl(paste("image create Rplot", image))
        lab <- tklabel(..., image = image)
        tkbind(lab, "<Destroy>", function() .Tcl(paste("image delete", 
            image)))
        lab$image <- image
        lab$fun <- fun
        lab$hscale <- hscale
        lab$vscale <- vscale
        lab
    }
    getLabelUsr <- function(xi, yi, parin, .labels, .cex, horiz, 
        vert, showconv = FALSE) {
        usr1old <- parin$usr[1]
        usr2old <- parin$usr[2]
        usr3old <- parin$usr[3]
        usr4old <- parin$usr[4]
        yi[which(is.na(yi))] <- mean(yi[-which(is.na(yi))])
        c1i <- strwidth(.labels, cex = .cex, units = "figure") * 
            parin$fin[1]/parin$pin[1]
        c2i <- strheight(.labels, cex = .cex, units = "figure") * 
            parin$fin[2]/parin$pin[2]
        SSE <- Inf
        count <- 0
        while (SSE > eps) {
            usr1new <- suppressWarnings(min(xi + strwidth("x", 
                cex = .cex) * horiz + as.numeric(!is.na(.labels)) * 
                (-0.5 * c1i) * (usr2old - usr1old), xi))
            usr2new <- suppressWarnings(max(xi + strwidth("x", 
                cex = .cex) * horiz + as.numeric(!is.na(.labels)) * 
                (0.5 * c1i) * (usr2old - usr1new), xi))
            SSE <- (usr1new - usr1old)^2 + (usr2new - usr2old)^2
            count <- count + 1
            if (showconv) 
                cat("x :", count, ":", SSE, "\n")
            usr1old <- usr1new
            usr2old <- usr2new
        }
        SSE <- Inf
        count <- 0
        while (SSE > eps) {
            usr3new <- suppressWarnings(min(yi + strheight("x", 
                cex = .cex) * vert + as.numeric(!is.na(.labels)) * 
                (-0.5 * c2i) * (usr4old - usr3old), yi))
            usr4new <- suppressWarnings(max(yi + strheight("x", 
                cex = .cex) * vert + as.numeric(!is.na(.labels)) * 
                (0.5 * c2i) * (usr4old - usr3new), yi))
            SSE <- (usr3new - usr3old)^2 + (usr4new - usr4old)^2
            count <- count + 1
            if (showconv) 
                cat("y :", count, ":", SSE, "\n")
            usr3old <- usr3new
            usr4old <- usr4new
        }
        xlimt <- c(usr1new, usr2new)
        ylimt <- c(usr3new, usr4new)
        list(xlimt, ylimt)
    }
    mynewplot <- function(x, y, xlimtouse = NA, ylimtouse = NA, 
        fitaroundlabels = FALSE, .labels = NA, labels.cex, HorizOffset, 
        VertOffset, ...) {
        b <- list(...)
        if (!missing(xlimtouse) && !missing(ylimtouse)) 
            plot(x = x, y = y, xlim = xlimtouse, ylim = ylimtouse, 
                asp = 1, type = "n", xlab = "", ylab = "", ...)
        else if (fitaroundlabels) {
            if (any(names(b) %in% c("xaxt", "yaxt"))) 
                bwithoutaxt <- b[which(names(b) != "xaxt" & names(b) != 
                  "yaxt")]
            else bwithoutaxt <- b
            do.call("plot", c(list(x = x, y = y, type = "n", 
                asp = 1, xlab = "", ylab = "", xaxt = "n", yaxt = "n"), 
                bwithoutaxt))
            xylim <- getLabelUsr(xi = x, yi = y, parin = par(), 
                .labels = .labels, .cex = labels.cex, HorizOffset, 
                VertOffset, showconv = FALSE)
            if (any(names(bwithoutaxt) == "pch")) 
                bwithoutaxtpch <- bwithoutaxt[which(names(bwithoutaxt) != 
                  "pch")]
            else bwithoutaxtpch <- bwithoutaxt
            do.call("plot.window", c(list(xlim = xylim[[1]], 
                ylim = xylim[[2]]), asp = 1, bwithoutaxtpch))
            if (!any(names(b) == "xaxt") | (any(names(b) == "xaxt") && 
                b$xaxt != "n")) 
                axis(side = 1)
            if (!any(names(b) == "yaxt") | (any(names(b) == "yaxt") && 
                b$yaxt != "n")) 
                axis(side = 2)
        }
        else plot(x, y, type = "n", xlab = "", asp = 1, ylab = "", 
            ...)
    }
    legend2 <- function(x, y = NULL, legend, fill = NULL, col = par("col"), 
        lines.col = col, lty, lwd, pch, angle = 45, density = NULL, 
        bty = "o", bg = par("bg"), box.lwd = par("lwd"), box.lty = par("lty"), 
        box.col = par("fg"), pt.bg = NA, cex = 1, pt.cex = cex, 
        pt.lwd = lwd, xjust = 0, yjust = 1, x.intersp = 1, y.intersp = 1, 
        adj = c(0, 0.5), text.width = NULL, text.col = par("col"), 
        merge = do.lines && has.pch, trace = FALSE, plot = TRUE, 
        ncol = 1, horiz = FALSE, title = NULL, inset = 0, xpd, 
        title.col = text.col) {
        if (missing(legend) && !missing(y) && (is.character(y) || 
            is.expression(y))) {
            legend <- y
            y <- NULL
        }
        mfill <- !missing(fill) || !missing(density)
        if (!missing(xpd)) {
            op <- par("xpd")
            on.exit(par(xpd = op))
            par(xpd = xpd)
        }
        title <- as.graphicsAnnot(title)
        if (length(title) > 1) 
            stop("invalid title")
        legend <- as.graphicsAnnot(legend)
        n.leg <- if (is.call(legend)) 
            1
        else length(legend)
        if (n.leg == 0) 
            stop("'legend' is of length 0")
        auto <- if (is.character(x)) 
            match.arg(x, c("bottomright", "bottom", "bottomleft", 
                "left", "topleft", "top", "topright", "right", 
                "center"))
        else NA
        if (is.na(auto)) {
            xy <- xy.coords(x, y)
            x <- xy$x
            y <- xy$y
            nx <- length(x)
            if (nx < 1 || nx > 2) 
                stop("invalid coordinate lengths")
        }
        else nx <- 0
        xlog <- par("xlog")
        ylog <- par("ylog")
        rect2 <- function(left, top, dx, dy, density = NULL, 
            angle, ...) {
            r <- left + dx
            if (xlog) {
                left <- 10^left
                r <- 10^r
            }
            b <- top - dy
            if (ylog) {
                top <- 10^top
                b <- 10^b
            }
            rect(left, top, r, b, angle = angle, density = density, 
                ...)
        }
        segments2 <- function(x1, y1, dx, dy, ...) {
            x2 <- x1 + dx
            if (xlog) {
                x1 <- 10^x1
                x2 <- 10^x2
            }
            y2 <- y1 + dy
            if (ylog) {
                y1 <- 10^y1
                y2 <- 10^y2
            }
            segments(x1, y1, x2, y2, ...)
        }
        points2 <- function(x, y, ...) {
            if (xlog) 
                x <- 10^x
            if (ylog) 
                y <- 10^y
            points(x, y, ...)
        }
        text2 <- function(x, y, ...) {
            if (xlog) 
                x <- 10^x
            if (ylog) 
                y <- 10^y
            text(x, y, ...)
        }
        if (trace) 
            catn <- function(...) do.call("cat", c(lapply(list(...), 
                formatC), list("\n")))
        cin <- par("cin")
        Cex <- cex * par("cex")
        if (is.null(text.width)) 
            text.width <- max(abs(strwidth(legend, units = "user", 
                cex = cex)))
        else if (!is.numeric(text.width) || text.width < 0) 
            stop("'text.width' must be numeric, >= 0")
        xc <- Cex * xinch(cin[1L], warn.log = FALSE)
        yc <- Cex * yinch(cin[2L], warn.log = FALSE)
        if (xc < 0) 
            text.width <- -text.width
        xchar <- xc
        xextra <- 0
        yextra <- yc * (y.intersp - 1)
        ymax <- yc * max(1, strheight(legend, units = "user", 
            cex = cex)/yc)
        ychar <- yextra + ymax
        if (trace) 
            catn("  xchar=", xchar, "; (yextra,ychar)=", c(yextra, 
                ychar))
        if (mfill) {
            xbox <- xc * 0.8
            ybox <- yc * 0.5
            dx.fill <- xbox
        }
        do.lines <- (!missing(lty) && (is.character(lty) || any(lty > 
            0))) || !missing(lwd)
        n.legpercol <- if (horiz) {
            if (ncol != 1) 
                warning("horizontal specification overrides: Number of columns := ", 
                  n.leg)
            ncol <- n.leg
            1
        }
        else ceiling(n.leg/ncol)
        has.pch <- !missing(pch) && length(pch) > 0
        if (do.lines) {
            x.off <- if (merge) 
                -0.7
            else 0
        }
        else if (merge) 
            warning("'merge = TRUE' has no effect when no line segments are drawn")
        if (has.pch) {
            if (is.character(pch) && !is.na(pch[1L]) && nchar(pch[1L], 
                type = "c") > 1) {
                if (length(pch) > 1) 
                  warning("not using pch[2..] since pch[1L] has multiple chars")
                np <- nchar(pch[1L], type = "c")
                pch <- substr(rep.int(pch[1L], np), 1L:np, 1L:np)
            }
        }
        if (is.na(auto)) {
            if (xlog) 
                x <- log10(x)
            if (ylog) 
                y <- log10(y)
        }
        if (nx == 2) {
            x <- sort(x)
            y <- sort(y)
            left <- x[1L]
            top <- y[2L]
            w <- diff(x)
            h <- diff(y)
            w0 <- w/ncol
            x <- mean(x)
            y <- mean(y)
            if (missing(xjust)) 
                xjust <- 0.5
            if (missing(yjust)) 
                yjust <- 0.5
        }
        else {
            h <- (n.legpercol + (!is.null(title))) * ychar + 
                yc
            w0 <- text.width + (x.intersp + 1) * xchar
            if (mfill) 
                w0 <- w0 + dx.fill
            if (do.lines) 
                w0 <- w0 + (2 + x.off) * xchar
            w <- ncol * w0 + 0.5 * xchar
            if (!is.null(title) && (abs(tw <- strwidth(title, 
                units = "user", cex = cex) + 0.5 * xchar)) > 
                abs(w)) {
                xextra <- (tw - w)/2
                w <- tw
            }
            if (is.na(auto)) {
                left <- x - xjust * w
                top <- y + (1 - yjust) * h
            }
            else {
                usr <- par("usr")
                inset <- rep(inset, length.out = 2)
                insetx <- inset[1L] * (usr[2L] - usr[1L])
                left <- switch(auto, bottomright = , topright = , 
                  right = usr[2L] - w - insetx, bottomleft = , 
                  left = , topleft = usr[1L] + insetx, bottom = , 
                  top = , center = (usr[1L] + usr[2L] - w)/2)
                insety <- inset[2L] * (usr[4L] - usr[3L])
                top <- switch(auto, bottomright = , bottom = , 
                  bottomleft = usr[3L] + h + insety, topleft = , 
                  top = , topright = usr[4L] - insety, left = , 
                  right = , center = (usr[3L] + usr[4L] + h)/2)
            }
        }
        if (plot && bty != "n") {
            if (trace) 
                catn("  rect2(", left, ",", top, ", w=", w, ", h=", 
                  h, ", ...)", sep = "")
            rect2(left, top, dx = w, dy = h, col = bg, density = NULL, 
                lwd = box.lwd, lty = box.lty, border = box.col)
        }
        xt <- left + xchar + xextra + (w0 * rep.int(0:(ncol - 
            1), rep.int(n.legpercol, ncol)))[1L:n.leg]
        yt <- top - 0.5 * yextra - ymax - (rep.int(1L:n.legpercol, 
            ncol)[1L:n.leg] - 1 + (!is.null(title))) * ychar
        if (mfill) {
            if (plot) {
                fill <- rep(fill, length.out = n.leg)
                rect2(left = xt, top = yt + ybox/2, dx = xbox, 
                  dy = ybox, col = fill, density = density, angle = angle, 
                  border = "black")
            }
            xt <- xt + dx.fill
        }
        if (plot && (has.pch || do.lines)) 
            col <- rep(col, length.out = n.leg)
        if (missing(lwd)) 
            lwd <- par("lwd")
        if (do.lines) {
            seg.len <- 2
            if (missing(lty)) 
                lty <- 1
            lty <- rep(lty, length.out = n.leg)
            lwd <- rep(lwd, length.out = n.leg)
            ok.l <- !is.na(lty) & (is.character(lty) | lty > 
                0)
            if (trace) 
                catn("  segments2(", xt[ok.l] + x.off * xchar, 
                  ",", yt[ok.l], ", dx=", seg.len * xchar, ", dy=0, ...)")
            if (plot) 
                segments2(xt[ok.l] + x.off * xchar, yt[ok.l], 
                  dx = seg.len * xchar, dy = 0, lty = lty[ok.l], 
                  lwd = lwd[ok.l], col = lines.col[ok.l])
            xt <- xt + (seg.len + x.off) * xchar
        }
        if (has.pch) {
            pch <- rep(pch, length.out = n.leg)
            pt.bg <- rep(pt.bg, length.out = n.leg)
            pt.cex <- rep(pt.cex, length.out = n.leg)
            pt.lwd <- rep(pt.lwd, length.out = n.leg)
            ok <- !is.na(pch) & (is.character(pch) | pch >= 0)
            x1 <- (if (merge && do.lines) 
                xt - (seg.len/2) * xchar
            else xt)[ok]
            y1 <- yt[ok]
            if (trace) 
                catn("  points2(", x1, ",", y1, ", pch=", pch[ok], 
                  ", ...)")
            if (plot) 
                points2(x1, y1, pch = pch[ok], col = col[ok], 
                  cex = pt.cex[ok], bg = pt.bg[ok], lwd = pt.lwd[ok])
        }
        xt <- xt + x.intersp * xchar
        if (plot) {
            if (!is.null(title)) 
                text2(left + w/2, top - ymax, labels = title, 
                  adj = c(0.5, 0), cex = cex, col = title.col)
            text2(xt, yt, labels = legend, adj = adj, cex = cex, 
                col = text.col)
        }
        invisible(list(rect = list(w = w, h = h, left = left, 
            top = top), text = list(x = xt, y = yt)))
    }
    my.plot.tile.list <- function(x, verbose = FALSE, close = FALSE, 
        pch = 1, polycol = NA, showpoints = TRUE, asp = 1, ...) {
        object <- x
        if (!inherits(object, "tile.list")) 
            stop("Argument \"object\" is not of class tile.list.\n")
        n <- length(object)
        x.all <- unlist(lapply(object, function(w) {
            c(w$pt[1], w$x)
        }))
        y.all <- unlist(lapply(object, function(w) {
            c(w$pt[2], w$y)
        }))
        x.pts <- unlist(lapply(object, function(w) {
            w$pt[1]
        }))
        y.pts <- unlist(lapply(object, function(w) {
            w$pt[2]
        }))
        rx <- range(x.all)
        ry <- range(y.all)
        polycol <- apply(col2rgb(polycol, TRUE), 2, function(x) {
            do.call(rgb, as.list(x/255))
        })
        polycol <- rep(polycol, length = length(object))
        hexbla <- do.call(rgb, as.list(col2rgb("black", TRUE)/255))
        hexwhi <- do.call(rgb, as.list(col2rgb("white", TRUE)/255))
        ptcol <- ifelse(polycol == hexbla, hexwhi, hexbla)
        lnwid <- ifelse(polycol == hexbla, 2, 1)
        for (i in 1:n) {
            inner <- !any(object[[i]]$bp)
            if (close | inner) 
                polygon(object[[i]], col = polycol[i], border = ptcol[i], 
                  lwd = lnwid[i])
            else {
                x <- object[[i]]$x
                y <- object[[i]]$y
                bp <- object[[i]]$bp
                ni <- length(x)
                for (j in 1:ni) {
                  jnext <- if (j < ni) 
                    j + 1
                  else 1
                  do.it <- mid.in(x[c(j, jnext)], y[c(j, jnext)], 
                    rx, ry)
                  if (do.it) 
                    segments(x[j], y[j], x[jnext], y[jnext], 
                      col = ptcol[i], lwd = lnwid[i])
                }
            }
            if (verbose & showpoints) 
                points(object[[i]]$pt[1], object[[i]]$pt[2], 
                  pch = pch, col = ptcol[i])
            if (verbose & i < n) 
                readline("Go? ")
        }
        if (showpoints) 
            points(x.pts, y.pts, pch = pch, col = ptcol)
        invisible()
    }
    text2hex <- function(textcol) {
        WhichSystemButtonFace <- which(textcol == "SystemButtonFace")
        if (.Platform$OS.type == "unix") 
            textcol[WhichSystemButtonFace] <- "white"
        else textcol[WhichSystemButtonFace] <- NA
        temp1 <- col2rgb(textcol)/256
        temp2 <- rgb(temp1[1], temp1[2], temp1[3])
        if (.Platform$OS.type == "windows") 
            temp2[WhichSystemButtonFace] <- "SystemButtonFace"
        temp2
    }
    tkchooseColor <- function(...) tcl("tk_chooseColor", ...)
    linebreak <- function(stringin = "", cutoff = 60) {
        stringin <- as.character(stringin)
        temp1 <- strsplit(stringin, c(" ", "-"))[[1]]
        temp1[-length(temp1)] <- paste(temp1[-length(temp1)], 
            " ", sep = "")
        nwords <- length(temp1)
        currentword <- 1
        currentindices <- currentword:nwords
        repeat {
            temp2 <- cumsum(nchar(temp1)[currentindices])
            temp3 <- which(temp2 > cutoff)
            if (length(temp3) == 0) 
                break
            else temp3 <- temp3[1]
            temp1[currentindices[temp3] - 1] <- paste(temp1[currentindices[temp3] - 
                1], "\n", sep = "")
            currentword <- currentindices[temp3]
            if (currentword >= nwords) 
                break
            currentindices <- currentword:nwords
        }
        paste(temp1, collapse = "")
    }
    mytktip <- function(widget, ...) {
        temp1 <- list(...)
        temp2 <- lapply(temp1, function(x) linebreak(x))
        if (length(temp1) > 1) 
            temp3 <- paste(unlist(temp2), collapse = " \n\n")
        else temp3 <- unlist(temp2)
        .Tcl(paste("DynamicHelp::add ", widget, " -text \"", 
            temp3, "\"", sep = ""))
    }
    SquareRootMatrix <- function(mat) {
        temp1 <- svd(mat)
        if (min(temp1$d) <= 0) 
            stop("mat is required to be positive definite.")
        temp2 <- temp1$u %*% diag(sqrt(temp1$d)) %*% t(temp1$u)
        (temp2 + t(temp2))/2
    }
    PythagorasDistance <- function(X, Y) {
        n <- nrow(X)
        m <- nrow(Y)
        bx <- rowSums(X^2)
        by <- rowSums(Y^2)
        D <- matrix(bx, nrow = n, ncol = m) + matrix(by, nrow = n, 
            ncol = m, byrow = TRUE) - 2 * X %*% t(Y)
        if (identical(X, Y)) 
            diag(D) <- 0
        D^0.5
    }
    GUI.TopLevel <- tktoplevel()
    tkwm.title(GUI.TopLevel, "BiplotGUI")
    Rico <- tk2ico.load(file.path(Sys.getenv("R_HOME"), "bin", 
        "R.exe"), res = "R")
    tk2ico.set(GUI.TopLevel, Rico)
    tk2ico.destroy(Rico)
    rm(Rico)
    tkwm.deiconify(GUI.TopLevel)
    GUI.AvailableScreenWidth <- round(as.numeric(tkwinfo("screenwidth", 
        GUI.TopLevel)))
    GUI.AvailableScreenHeight <- round(as.numeric(tkwinfo("screenheight", 
        GUI.TopLevel)))
    if (GUI.AvailableScreenWidth/GUI.AvailableScreenHeight <= 
        1080/720) {
        GUI.ScreenWidth <- min(1080, round(GUI.AvailableScreenWidth * 
            0.9))
        GUI.ScreenHeight <- min(720, round(GUI.AvailableScreenWidth/1080 * 
            720 * 0.9))
    }
    else {
        GUI.ScreenWidth <- min(1080, round(GUI.AvailableScreenHeight/720 * 
            1080 * 0.9))
        GUI.ScreenHeight <- min(720, round(GUI.AvailableScreenHeight * 
            0.9))
    }
    .Tcl(paste("wm geometry ", GUI.TopLevel, " ", GUI.ScreenWidth, 
        "x", GUI.ScreenHeight, "+", round(GUI.AvailableScreenWidth/2 - 
            GUI.ScreenWidth/2, 0), "+", round(GUI.AvailableScreenHeight/2 - 
            GUI.ScreenHeight/2, 0), sep = ""))
    .Tcl(paste("wm minsize ", GUI.TopLevel, " 900 600", sep = ""))
    GUI.resize.allowed <- TRUE
    GUI.resize.counter <- 0
    tkbind(GUI.TopLevel, "<Destroy>", function() GUI.resize.allowed <<- FALSE)
    GUI.resize.replot <- function() {
        if (GUI.WindowWidth != (temp1 <- as.numeric(tkwinfo("width", 
            GUI.TopLevel))) | GUI.WindowHeight != (temp2 <- as.numeric(tkwinfo("height", 
            GUI.TopLevel)))) {
            Biplot.replot()
            CurrentTab <- tclvalue(tcl(DiagnosticTabs.nb, "index", 
                "current"))
            tcl(DiagnosticTabs.nb, "tab", 0, state = "normal")
            tkselect(DiagnosticTabs.nb, 0)
            ConvergenceTab.replot()
            PointsTab.replot()
            GroupsTab.replot()
            AxesTab.replot()
            PredictionsTab.place()
            Kraal.replot()
            tkselect(DiagnosticTabs.nb, CurrentTab)
            if (tclvalue(Points.var) %in% c("10", "11", "12")) 
                tcl(DiagnosticTabs.nb, "tab", 0, state = "normal")
            else tcl(DiagnosticTabs.nb, "tab", 0, state = "disabled")
            GUI.WindowWidth <<- temp1
            GUI.WindowHeight <<- temp2
        }
        GUI.resize.counter <<- 0
    }
    GUI.resize <- function() {
        if (GUI.resize.allowed) {
            GUI.resize.counter <<- GUI.resize.counter + 1
            temp1 <- .Tcl(paste("after 200 ", suppressWarnings(tclFun(GUI.resize.replot)), 
                sep = ""))
            if (GUI.resize.counter > 1) 
                .Tcl(paste("after cancel ", temp1, sep = ""))
        }
    }
    GUI.BindingsOff <- function() {
        tkconfigure(GUI.TopLevel, cursor = "watch")
        Other.ProgressBar.create()
        tkconfigure(Other.ProgressBar.pb, value = 0)
        .Tcl("update")
        tkbind(GUI.TopLevel, "<Control-s>", function() NULL)
        tkbind(GUI.TopLevel, "<Control-S>", function() NULL)
        tkbind(GUI.TopLevel, "<Control-c>", function() NULL)
        tkbind(GUI.TopLevel, "<Control-C>", function() NULL)
        tkbind(GUI.TopLevel, "<Control-p>", function() NULL)
        tkbind(GUI.TopLevel, "<Control-P>", function() NULL)
        if (.Platform$OS.type != "unix") 
            tkbind(GUI.TopLevel, "<Control-+>", function() NULL)
        tkbind(GUI.TopLevel, "<Control-minus>", function() NULL)
        tkbind(GUI.TopLevel, "<Control-g>", function() NULL)
        tkbind(GUI.TopLevel, "<Control-G>", function() NULL)
        tkbind(GUI.TopLevel, "<Control-a>", function() NULL)
        tkbind(GUI.TopLevel, "<Control-A>", function() NULL)
        tkbind(GUI.TopLevel, "<Control-r>", function() NULL)
        tkbind(GUI.TopLevel, "<Control-R>", function() NULL)
        tkbind(GUI.TopLevel, "a", function() NULL)
        tkbind(GUI.TopLevel, "A", function() NULL)
        tkbind(GUI.TopLevel, "r", function() NULL)
        tkbind(GUI.TopLevel, "R", function() NULL)
        tkbind(GUI.TopLevel, "b", function() NULL)
        tkbind(GUI.TopLevel, "B", function() NULL)
        tkbind(GUI.TopLevel, "c", function() NULL)
        tkbind(GUI.TopLevel, "C", function() NULL)
        tkbind(GUI.TopLevel, "d", function() NULL)
        tkbind(GUI.TopLevel, "D", function() NULL)
        tkbind(GUI.TopLevel, "0", function() NULL)
        tkbind(GUI.TopLevel, "1", function() NULL)
        tkbind(GUI.TopLevel, "2", function() NULL)
        tkbind(GUI.TopLevel, "3", function() NULL)
        tkbind(GUI.TopLevel, "4", function() NULL)
        tkbind(GUI.TopLevel, "5", function() NULL)
        tkbind(GUI.TopLevel, "6", function() NULL)
        tkbind(GUI.TopLevel, "<Control-n>", function() NULL)
        tkbind(GUI.TopLevel, "<Control-N>", function() NULL)
        tkbind(GUI.TopLevel, "<Control-l>", function() NULL)
        tkbind(GUI.TopLevel, "<Control-L>", function() NULL)
        tkbind(GUI.TopLevel, "<F1>", function() NULL)
        tkbind(GUI.TopLevel, "<Configure>", function() NULL)
        tkbind(BiplotRegion.image, "<Motion>", function() NULL)
        tkbind(BiplotRegion.image, "<Button-1>", function() NULL)
        tkbind(BiplotRegion.image, "<ButtonRelease-1>", function() NULL)
        tkbind(BiplotRegion.image, "<Button-3>", function() NULL)
        tkbind(GUI.TopLevel, "<F11>", function() NULL)
        tkbind(GUI.TopLevel, "<F12>", function() NULL)
        tkbind(ConvergenceTab.image, "<Button-3>", function() NULL)
        tkbind(PointsTab.image, "<Button-3>", function() NULL)
        tkbind(GroupsTab.image, "<Button-3>", function() NULL)
        tkbind(AxesTab.image, "<Button-3>", function() NULL)
        tkbind(Kraal.image, "<Motion>", function() NULL)
        tkbind(Kraal.image, "<Button-1>", function() NULL)
        tkbind(Kraal.image, "<ButtonRelease-1>", function() NULL)
        tkbind(Kraal.image, "<Button-3>", function() NULL)
    }
    GUI.BindingsOn <- function() {
        GUI.update()
        tkbind(GUI.TopLevel, "<Escape>", Other.Stop.cmd)
        tkbind(GUI.TopLevel, "<Control-s>", function() File.Save.as.cmd())
        tkbind(GUI.TopLevel, "<Control-S>", function() File.Save.as.cmd())
        tkbind(GUI.TopLevel, "<Control-c>", function() tkinvoke(MenuBar.File, 
            1))
        tkbind(GUI.TopLevel, "<Control-C>", function() tkinvoke(MenuBar.File, 
            1))
        tkbind(GUI.TopLevel, "<Control-p>", function() tkinvoke(MenuBar.File, 
            3))
        tkbind(GUI.TopLevel, "<Control-P>", function() tkinvoke(MenuBar.File, 
            3))
        if (.Platform$OS.type != "unix") 
            tkbind(GUI.TopLevel, "<Control-+>", function() tkinvoke(MenuBar.View, 
                16))
        tkbind(GUI.TopLevel, "<Control-minus>", function() tkinvoke(MenuBar.View, 
            17))
        tkbind(GUI.TopLevel, "<Control-g>", function() tkinvoke(MenuBar.Format, 
            1))
        tkbind(GUI.TopLevel, "<Control-G>", function() tkinvoke(MenuBar.Format, 
            1))
        tkbind(GUI.TopLevel, "<Control-a>", function() tkinvoke(MenuBar.Format, 
            2))
        tkbind(GUI.TopLevel, "<Control-A>", function() tkinvoke(MenuBar.Format, 
            2))
        tkbind(GUI.TopLevel, "<Control-r>", function() tkinvoke(MenuBar.Format, 
            6))
        tkbind(GUI.TopLevel, "<Control-R>", function() tkinvoke(MenuBar.Format, 
            6))
        tkbind(GUI.TopLevel, "a", function() tkinvoke(MenuBar.Points, 
            2))
        tkbind(GUI.TopLevel, "A", function() tkinvoke(MenuBar.Points, 
            2))
        tkbind(GUI.TopLevel, "r", function() tkinvoke(MenuBar.Points.MDS, 
            0))
        tkbind(GUI.TopLevel, "R", function() tkinvoke(MenuBar.Points.MDS, 
            0))
        tkbind(GUI.TopLevel, "b", function() tkinvoke(MenuBar.Points.MDS, 
            2))
        tkbind(GUI.TopLevel, "B", function() tkinvoke(MenuBar.Points.MDS, 
            2))
        tkbind(GUI.TopLevel, "c", function() tkinvoke(MenuBar.Points.MDS, 
            3))
        tkbind(GUI.TopLevel, "C", function() tkinvoke(MenuBar.Points.MDS, 
            3))
        tkbind(GUI.TopLevel, "d", function() tkinvoke(MenuBar.Points.MDS, 
            4))
        tkbind(GUI.TopLevel, "D", function() tkinvoke(MenuBar.Points.MDS, 
            4))
        tkbind(GUI.TopLevel, "0", function() tkinvoke(MenuBar.Axes, 
            0))
        tkbind(GUI.TopLevel, "1", function() tkinvoke(MenuBar.Joint, 
            0))
        tkbind(GUI.TopLevel, "2", function() tkinvoke(MenuBar.Joint, 
            1))
        tkbind(GUI.TopLevel, "3", function() tkinvoke(MenuBar.Joint, 
            3))
        tkbind(GUI.TopLevel, "4", function() tkinvoke(MenuBar.Axes, 
            2))
        tkbind(GUI.TopLevel, "5", function() tkinvoke(MenuBar.Axes, 
            3))
        tkbind(GUI.TopLevel, "6", function() tkinvoke(MenuBar.Axes, 
            5))
        tkbind(GUI.TopLevel, "<Control-n>", function() tkinvoke(MenuBar.Additional.Interpolate, 
            0))
        tkbind(GUI.TopLevel, "<Control-N>", function() tkinvoke(MenuBar.Additional.Interpolate, 
            0))
        tkbind(GUI.TopLevel, "<Control-l>", function() tkinvoke(MenuBar.Additional, 
            8))
        tkbind(GUI.TopLevel, "<Control-L>", function() tkinvoke(MenuBar.Additional, 
            8))
        tkbind(GUI.TopLevel, "<F1>", function() tkinvoke(MenuBar.Help, 
            0))
        tkbind(GUI.TopLevel, "<Configure>", GUI.resize)
        tkbind(BiplotRegion.image, "<Motion>", Biplot.motion)
        tkbind(BiplotRegion.image, "<Button-1>", Biplot.LeftClick)
        tkbind(BiplotRegion.image, "<ButtonRelease-1>", Biplot.LeftRelease)
        tkbind(BiplotRegion.image, "<Button-3>", Biplot.RightClick)
        tkbind(GUI.TopLevel, "<F11>", function() tkinvoke(Other.External.menu, 
            0))
        tkbind(GUI.TopLevel, "<F12>", function() tkinvoke(Other.External.menu, 
            1))
        tkbind(ConvergenceTab.image, "<Button-3>", ConvergenceTab.RightClick)
        tkbind(PointsTab.image, "<Button-3>", PointsTab.RightClick)
        tkbind(GroupsTab.image, "<Button-3>", GroupsTab.RightClick)
        tkbind(AxesTab.image, "<Button-3>", AxesTab.RightClick)
        tkbind(Kraal.image, "<Motion>", Kraal.motion)
        tkbind(Kraal.image, "<Button-1>", Kraal.LeftClick)
        tkbind(Kraal.image, "<ButtonRelease-1>", Kraal.LeftRelease)
        tkbind(Kraal.image, "<Button-3>", Kraal.RightClick)
        ExportTab.update()
        tkconfigure(Other.ProgressBar.pb, value = 100)
        Other.ProgressBar.destroy()
        tkconfigure(GUI.TopLevel, cursor = "arrow")
        .Tcl("update")
    }
    GUI.update <- function() {
        if (tclvalue(Biplot.Axes.var) %in% c("0", "1", "2", "10", 
            "11", "12") | tclvalue(Other.HideAxes.var) == "1") 
            tkentryconfigure(MenuBar.View, 3, state = "disabled")
        else tkentryconfigure(MenuBar.View, 3, state = "normal")
        for (temp1 in 2:3) tkentryconfigure(MenuBar.View, temp1, 
            variable = View.ClipAround.var)
        if (tclvalue(Other.HidePoints.var) == "1") 
            tkentryconfigure(MenuBar.View, 5, state = "disabled")
        else tkentryconfigure(MenuBar.View, 5, state = "normal")
        tkentryconfigure(MenuBar.View, 5, variable = View.ShowPointLabels.var)
        if (Biplot.axes.mode == 0) 
            tkentryconfigure(MenuBar.View, 6, state = "disabled")
        else tkentryconfigure(MenuBar.View, 6, state = "normal")
        tkentryconfigure(MenuBar.View, 6, variable = View.ShowPointValues.var)
        if (g > 1) {
            if (tclvalue(Other.HidePoints.var) == "1") 
                tkentryconfigure(MenuBar.View, 8, state = "disabled")
            else tkentryconfigure(MenuBar.View, 8, state = "normal")
        }
        tkentryconfigure(MenuBar.View, 8, variable = View.ShowGroupLabelsInLegend.var)
        if (tclvalue(Biplot.Axes.var) == "10" | tclvalue(Other.HideAxes.var) == 
            "1") 
            for (temp1 in c(10, 12)) {
                tkentryconfigure(MenuBar.View, temp1, state = "disabled")
                tkentryconfigure(Biplot.RightClickOutside.Menu, 
                  temp1 - 5, state = "disabled")
            }
        else for (temp1 in c(10, 12)) {
            tkentryconfigure(MenuBar.View, temp1, state = "normal")
            tkentryconfigure(Biplot.RightClickOutside.Menu, temp1 - 
                5, state = "normal")
        }
        if (tclvalue(Biplot.Axes.var) %in% c("10", "13", "14") | 
            tclvalue(Other.HideAxes.var) == "1") {
            tkentryconfigure(MenuBar.View, 11, state = "disabled")
            tkentryconfigure(Biplot.RightClickOutside.Menu, 6, 
                state = "disabled")
        }
        else {
            tkentryconfigure(MenuBar.View, 11, state = "normal")
            tkentryconfigure(Biplot.RightClickOutside.Menu, 6, 
                state = "normal")
        }
        for (temp1 in 10:12) {
            tkentryconfigure(MenuBar.View, temp1, variable = View.AxisLabels.var)
            tkentryconfigure(Biplot.RightClickOutside.Menu, temp1 - 
                5, variable = View.AxisLabels.var)
        }
        for (temp1 in c(0:1, 3)) tkentryconfigure(MenuBar.Joint, 
            temp1, variable = Biplot.Axes.var)
        if (tclvalue(Points.var) %in% c("10", "11", "12")) 
            tkentryconfigure(MenuBar.Points.MDS, 0, state = "normal")
        else tkentryconfigure(MenuBar.Points.MDS, 0, state = "disabled")
        if (tclvalue(Points.var) == "11") 
            for (temp1 in 6:7) tkentryconfigure(MenuBar.Points.MDS, 
                temp1, state = "normal", variable = Points.MDS.ApproachToTies.var)
        else for (temp1 in 6:7) tkentryconfigure(MenuBar.Points.MDS, 
            temp1, state = "disabled", variable = Points.MDS.ApproachToTies.var)
        if (tclvalue(Points.DissimilarityMetric.var) == "3" && 
            tclvalue(Points.var) == "0") 
            for (temp1 in 2:3) tkentryconfigure(MenuBar.Axes, 
                temp1, state = "disabled")
        else for (temp1 in 2:3) tkentryconfigure(MenuBar.Axes, 
            temp1, state = "normal")
        if ((tclvalue(Points.DissimilarityMetric.var) == "3" && 
            tclvalue(Points.var) == "0") || tclvalue(Points.var) %in% 
            c("10", "11", "12")) 
            for (temp1 in 5) tkentryconfigure(MenuBar.Axes, temp1, 
                state = "disabled")
        else for (temp1 in 5) tkentryconfigure(MenuBar.Axes, 
            temp1, state = "normal")
        for (temp1 in c(0, 2:3, 5)) tkentryconfigure(MenuBar.Axes, 
            temp1, variable = Biplot.Axes.var)
        if (tclvalue(Biplot.Axes.var) == "10") 
            for (temp1 in 0:1) tkentryconfigure(MenuBar.Additional.Interpolate, 
                temp1, state = "disabled")
        else for (temp1 in 0:1) tkentryconfigure(MenuBar.Additional.Interpolate, 
            temp1, state = "normal")
        if (tclvalue(Biplot.Axes.var) == "2") 
            tkentryconfigure(MenuBar.Additional, 6, state = "normal")
        else tkentryconfigure(MenuBar.Additional, 6, state = "disabled")
        tkentryconfigure(MenuBar.Additional.Interpolate, 0, variable = Additional.Interpolate.ANewSample.var)
        tkentryconfigure(MenuBar.Additional.Interpolate, 1, variable = Additional.Interpolate.SampleGroupMeans.var)
        tkentryconfigure(MenuBar.Additional, 2, variable = Additional.ConvexHull.var)
        tkentryconfigure(MenuBar.Additional, 3, variable = Additional.AlphaBag.var)
        tkentryconfigure(MenuBar.Additional, 5, variable = Additional.PointDensities.var)
        tkentryconfigure(MenuBar.Additional, 6, variable = Additional.ClassificationRegion.var)
        if (tclvalue(Other.HideAxes.var) == "1" || tclvalue(tkget(SettingsBox.action.combo)) != 
            "Predict") 
            tkentryconfigure(Biplot.RightClickInside.Menu, 5, 
                state = "disabled")
        else tkentryconfigure(Biplot.RightClickInside.Menu, 5, 
            state = "normal")
        if (tclvalue(Other.HidePoints.var) == "1" || tclvalue(Other.HideAxes.var) == 
            "1" || tclvalue(tkget(SettingsBox.action.combo)) != 
            "Predict") 
            tkentryconfigure(Biplot.RightClickInside.Menu, 6, 
                state = "disabled")
        else tkentryconfigure(Biplot.RightClickInside.Menu, 6, 
            state = "normal")
        for (temp1 in 4:6) tkentryconfigure(Biplot.RightClickInside.Menu, 
            temp1, variable = Biplot.points.mode)
        if (Biplot.axes.mode == 0) 
            tkentryconfigure(Biplot.RightClickInside.Menu, 8, 
                state = "disabled")
        else tkentryconfigure(Biplot.RightClickInside.Menu, 8, 
            state = "normal")
        if (tclvalue(Biplot.Axes.var) == "10" | tclvalue(Other.HideAxes.var) == 
            "1") 
            tkconfigure(SettingsBox.action.combo, state = "disabled")
        else tkconfigure(SettingsBox.action.combo, state = "normal")
        if (as.numeric(tclvalue(Biplot.Axes.var)) >= 10 && tclvalue(Points.var) %in% 
            c("10", "11", "12")) 
            tcl(DiagnosticTabs.nb, "tab", 0, state = "normal")
        else tcl(DiagnosticTabs.nb, "tab", 0, state = "disabled")
        switch(tclvalue(Biplot.Axes.var), `0` = {
            tcl(DiagnosticTabs.nb, "tab", 1, state = "normal")
            tcl(DiagnosticTabs.nb, "tab", 2, state = "disabled")
            tcl(DiagnosticTabs.nb, "tab", 3, state = "normal")
        }, `1` = {
            tcl(DiagnosticTabs.nb, "tab", 1, state = "disabled")
            tcl(DiagnosticTabs.nb, "tab", 2, state = "disabled")
            tcl(DiagnosticTabs.nb, "tab", 3, state = "disabled")
        }, `2` = {
            tcl(DiagnosticTabs.nb, "tab", 1, state = "normal")
            tcl(DiagnosticTabs.nb, "tab", 2, state = "normal")
            tcl(DiagnosticTabs.nb, "tab", 3, state = "normal")
        }, {
            tcl(DiagnosticTabs.nb, "tab", 1, state = "normal")
            tcl(DiagnosticTabs.nb, "tab", 2, state = "disabled")
            tcl(DiagnosticTabs.nb, "tab", 3, state = "disabled")
        })
        if (tclvalue(Biplot.Axes.var) == "10" | tclvalue(Other.HideAxes.var) == 
            "1" | !tclvalue(tkget(SettingsBox.action.combo)) == 
            "Predict") 
            tcl(DiagnosticTabs.nb, "tab", 4, state = "disabled")
        else tcl(DiagnosticTabs.nb, "tab", 4, state = "normal")
        if (tclvalue(Biplot.Axes.var) == "10") 
            tkentryconfigure(Other.Hide.menu, 1, state = "disabled")
        else tkentryconfigure(Other.Hide.menu, 1, state = "normal")
        if (as.numeric(tclvalue(Biplot.Axes.var)) >= 10 && as.numeric(tclvalue(Points.var)) >= 
            10) 
            tkentryconfigure(Other.External.menu, 1, state = "disabled")
        else tkentryconfigure(Other.External.menu, 1, state = "normal")
    }
    File.Save.as.cmd <- function() {
        GUI.BindingsOff()
        switch(tclvalue(File.SaveAs.var), `0` = File.SaveAs.PDF.cmd(), 
            `1` = File.SaveAs.Postscript.cmd(), `2` = File.SaveAs.Metafile.cmd(), 
            `3` = File.SaveAs.Bmp.cmd(), `4` = File.SaveAs.Png.cmd(), 
            `5` = File.SaveAs.Jpeg.cmd(), `6` = File.SaveAs.Jpeg.cmd(), 
            `7` = File.SaveAs.Jpeg.cmd(), `8` = File.SaveAs.PicTeX.cmd())
        GUI.BindingsOn()
    }
    File.SaveAs.var <- tclVar("0")
    File.SaveAs.PDF.cmd <- function() {
        FileName <- tclvalue(tkgetSaveFile(filetypes = "{{PDF files} {.pdf}} {{All files} *}"))
        if (nchar(FileName)) {
            nn <- nchar(FileName)
            if (nn < 5 || substr(FileName, nn - 3, nn) != ".pdf") 
                FileName <- paste(FileName, ".pdf", sep = "")
            pdf(FileName, width = boptions$ExternalGraphWidth, 
                height = boptions$ExternalGraphHeight)
            Biplot.plot(screen = FALSE)
            dev.off()
        }
        tkfocus(GUI.TopLevel)
    }
    File.SaveAs.Postscript.cmd <- function() {
        FileName <- tclvalue(tkgetSaveFile(filetypes = "{{Postscript files} {.ps}} {{All files} *}"))
        if (nchar(FileName)) {
            nn <- nchar(FileName)
            if (nn < 4 || substr(FileName, nn - 2, nn) != ".ps") 
                FileName <- paste(FileName, ".ps", sep = "")
            postscript(file = FileName, width = boptions$ExternalGraphWidth, 
                height = boptions$ExternalGraphHeight, horizontal = FALSE, 
                onefile = FALSE, paper = "default", family = "URWHelvetica")
            Biplot.plot(screen = FALSE)
            dev.off()
        }
        tkfocus(GUI.TopLevel)
    }
    File.SaveAs.Metafile.cmd <- function() {
        FileName <- tclvalue(tkgetSaveFile(filetypes = "{{Metafiles} {.wmf}} {{All files} *}"))
        if (nchar(FileName)) {
            nn <- nchar(FileName)
            if (nn < 5 || substr(FileName, nn - 3, nn) != ".wmf") 
                FileName <- paste(FileName, ".wmf", sep = "")
            win.metafile(FileName, width = boptions$ExternalGraphWidth, 
                height = boptions$ExternalGraphHeight, restoreConsole = FALSE)
            Biplot.plot(screen = FALSE)
            dev.off()
        }
        tkfocus(GUI.TopLevel)
    }
    File.SaveAs.Bmp.cmd <- function() {
        FileName <- tclvalue(tkgetSaveFile(filetypes = "{{Bitmap files} {.bmp}} {{All files} *}"))
        if (nchar(FileName)) {
            nn <- nchar(FileName)
            if (nn < 5 || substr(FileName, nn - 3, nn) != ".bmp") 
                FileName <- paste(FileName, ".bmp", sep = "")
            bmp(FileName, width = boptions$ExternalGraphWidth, 
                height = boptions$ExternalGraphHeight, units = "in", 
                restoreConsole = FALSE, res = 96)
            Biplot.plot(screen = FALSE)
            dev.off()
        }
        tkfocus(GUI.TopLevel)
    }
    File.SaveAs.Png.cmd <- function() {
        FileName <- tclvalue(tkgetSaveFile(filetypes = "{{Png files} {.png}} {{All files} *}"))
        if (nchar(FileName)) {
            nn <- nchar(FileName)
            if (nn < 5 || substr(FileName, nn - 3, nn) != ".png") 
                FileName <- paste(FileName, ".png", sep = "")
            png(FileName, width = boptions$ExternalGraphWidth, 
                height = boptions$ExternalGraphHeight, units = "in", 
                restoreConsole = FALSE, res = 96)
            Biplot.plot(screen = FALSE)
            dev.off()
        }
        tkfocus(GUI.TopLevel)
    }
    File.SaveAs.Jpeg.cmd <- function() {
        FileName <- tclvalue(tkgetSaveFile(filetypes = "{{Jpeg files} {.jpg .jpeg}} {{All files} *}"))
        if (nchar(FileName)) {
            nn <- nchar(FileName)
            if (nn < 5 || substr(FileName, nn - 3, nn) != ".jpg") 
                FileName <- paste(FileName, ".jpg", sep = "")
            jpeg(FileName, width = boptions$ExternalGraphWidth, 
                height = boptions$ExternalGraphHeight, units = "in", 
                restoreConsole = FALSE, res = 96, quality = File.Jpeg.quality)
            Biplot.plot(screen = FALSE)
            dev.off()
        }
        tkfocus(GUI.TopLevel)
    }
    File.Jpeg.quality <- NULL
    File.SaveAs.PicTeX.cmd <- function() {
        FileName <- tclvalue(tkgetSaveFile(filetypes = "{{TeX files} {.tex}} {{All files} *}"))
        if (nchar(FileName)) {
            nn <- nchar(FileName)
            if (nn < 5 || substr(FileName, nn - 3, nn) != ".tex") 
                FileName <- paste(FileName, ".tex", sep = "")
            pictex(FileName, width = boptions$ExternalGraphWidth, 
                height = boptions$ExternalGraphHeight, debug = FALSE, 
                bg = "white", fg = "black")
            Biplot.plot(screen = FALSE)
            dev.off()
        }
        tkfocus(GUI.TopLevel)
    }
    File.Copy.cmd <- function() {
        win.metafile(width = boptions$ExternalGraphWidth, height = boptions$ExternalGraphHeight, 
            restoreConsole = FALSE)
        Biplot.plot(screen = FALSE)
        dev.off()
    }
    File.Print.cmd <- function() {
        try(win.print(), silent = TRUE)
        if (geterrmessage() != "Error in win.print() : unable to start device devWindows\n") {
            Biplot.plot()
            dev.off()
        }
    }
    File.Options.cmd <- function() {
        local.GUI.func <- function() {
            top <- tktoplevel()
            tkwm.withdraw(top)
            onDefaults <- function() {
                local.MDSConvergence.var <<- tclVar(1e-06)
                tkconfigure(entry1, textvariable = local.MDSConvergence.var)
                local.MDSMaximumIterations.var <<- tclVar(5000)
                tkconfigure(entry2, textvariable = local.MDSMaximumIterations.var)
                local.ProcrustesConvergence.var <<- tclVar(1e-06)
                tkconfigure(entry3, textvariable = local.ProcrustesConvergence.var)
                local.ProcrustesMaximumIterations.var <<- tclVar(5000)
                tkconfigure(entry4, textvariable = local.ProcrustesMaximumIterations.var)
                local.IterationsToLiveUpdate.var <<- tclVar(5)
                tkconfigure(entry5, textvariable = local.IterationsToLiveUpdate.var)
                local.ReuseExternalWindows.var <<- tclVar(FALSE)
                tkconfigure(checkbutton1, variable = local.ReuseExternalWindows.var)
                local.ThreeDFlyBy.var <<- tclVar(FALSE)
                tkconfigure(checkbutton2, variable = local.ThreeDFlyBy.var)
                local.ThreeDMouseButtonActionLeft.var <<- tclVar("trackball")
                tkconfigure(combo1, text = "trackball")
                local.ThreeDMouseButtonActionMiddle.var <<- tclVar("zoom")
                tkconfigure(combo2, text = "zoom")
                local.ThreeDMouseButtonActionRight.var <<- tclVar("fov")
                tkconfigure(combo3, text = "fov")
            }
            onOK <- function() {
                boptions$MDS.convergence <<- as.numeric(tclvalue(local.MDSConvergence.var))
                boptions$MDS.MaximumIterations <<- as.numeric(tclvalue(local.MDSMaximumIterations.var))
                boptions$Procrustes.convergence <<- as.numeric(tclvalue(local.ProcrustesConvergence.var))
                boptions$Procrustes.MaximumIterations <<- as.numeric(tclvalue(local.ProcrustesMaximumIterations.var))
                boptions$IterationsToLiveUpdate <<- as.numeric(tclvalue(local.IterationsToLiveUpdate.var))
                boptions$ReuseExternalWindows <<- as.logical(as.numeric(tclvalue(local.ReuseExternalWindows.var)))
                boptions$ThreeD.FlyBy <<- as.logical(as.numeric(tclvalue(local.ThreeDFlyBy.var)))
                boptions$ThreeD.MouseButtonAction <<- c(tclvalue(tkget(combo1)), 
                  tclvalue(tkget(combo2)), tclvalue(tkget(combo3)))
                tkdestroy(top)
            }
            onCancel <- function() tkdestroy(top)
            local.MDSConvergence.var <- tclVar(boptions$MDS.convergence)
            local.MDSMaximumIterations.var <- tclVar(boptions$MDS.MaximumIterations)
            local.ProcrustesConvergence.var <- tclVar(boptions$Procrustes.convergence)
            local.ProcrustesMaximumIterations.var <- tclVar(boptions$Procrustes.MaximumIterations)
            local.IterationsToLiveUpdate.var <- tclVar(boptions$IterationsToLiveUpdate)
            local.ReuseExternalWindows.var <- tclVar(boptions$ReuseExternalWindows)
            local.ThreeDFlyBy.var <- tclVar(boptions$ThreeD.FlyBy)
            local.ThreeDMouseButtonActionLeft.var <- tclVar(boptions$ThreeD.MouseButtonAction[1])
            local.ThreeDMouseButtonActionMiddle.var <- tclVar(boptions$ThreeD.MouseButtonAction[2])
            local.ThreeDMouseButtonActionRight.var <- tclVar(boptions$ThreeD.MouseButtonAction[3])
            frame1 <- tkwidget(top, "TitleFrame", text = "Convergence")
            tkplace(frame1, relx = 0.05, relwidth = 0.9, y = 10, 
                height = 105, `in` = top)
            tkplace(tk2label(frame1, text = "MDS relative convergence"), 
                x = 11, y = 20, `in` = frame1)
            entry1 <- tk2entry(frame1, textvariable = local.MDSConvergence.var, 
                justify = "right", takefocus = FALSE)
            tkplace(entry1, relx = 0.95, y = 20, height = 18, 
                relwidth = 0.125, `in` = frame1, anchor = "ne")
            tkplace(tk2label(frame1, text = "MDS maximum iterations"), 
                x = 11, y = 40, `in` = frame1)
            entry2 <- tk2entry(frame1, textvariable = local.MDSMaximumIterations.var, 
                justify = "right", takefocus = FALSE)
            tkplace(entry2, relx = 0.95, y = 40, height = 18, 
                relwidth = 0.125, `in` = frame1, anchor = "ne")
            tkplace(tk2label(frame1, text = "Procrustes absolute convergence"), 
                x = 11, y = 60, `in` = frame1)
            entry3 <- tk2entry(frame1, textvariable = local.ProcrustesConvergence.var, 
                justify = "right", takefocus = FALSE)
            tkplace(entry3, relx = 0.95, y = 60, height = 18, 
                relwidth = 0.125, `in` = frame1, anchor = "ne")
            tkplace(tk2label(frame1, text = "Procrustes maximum iterations"), 
                x = 11, y = 80, `in` = frame1)
            entry4 <- tk2entry(frame1, textvariable = local.ProcrustesMaximumIterations.var, 
                justify = "right", takefocus = FALSE)
            tkplace(entry4, relx = 0.95, y = 80, height = 18, 
                relwidth = 0.125, `in` = frame1, anchor = "ne")
            frame2 <- tkwidget(top, "TitleFrame", text = "Graphical")
            tkplace(frame2, relx = 0.05, relwidth = 0.9, y = 130, 
                height = 125, `in` = top)
            tkplace(tk2label(frame2, text = "Iterations to live update"), 
                x = 11, y = 20, `in` = frame2)
            entry5 <- tk2entry(frame2, textvariable = local.IterationsToLiveUpdate.var, 
                justify = "right", takefocus = FALSE)
            tkplace(entry5, relx = 0.95, y = 20, height = 18, 
                relwidth = 0.125, `in` = frame2, anchor = "ne")
            tkplace(tk2label(frame2, text = "Re-use external windows"), 
                x = 11, y = 40, `in` = frame2)
            checkbutton1 <- tk2checkbutton(frame2, variable = local.ReuseExternalWindows.var)
            tkplace(checkbutton1, relx = 0.9, y = 40, height = 17, 
                `in` = frame2)
            tkplace(tk2label(frame2, text = "Three-dimensional `fly-by'"), 
                x = 11, y = 60, `in` = frame2)
            checkbutton2 <- tk2checkbutton(frame2, variable = local.ThreeDFlyBy.var)
            tkplace(checkbutton2, relx = 0.9, y = 60, height = 17, 
                `in` = frame2)
            tkplace(tk2label(frame2, text = "Three-dimensional mouse button action:"), 
                x = 11, y = 80, `in` = frame2)
            MousePossibilities <- c("none", "trackball", "xAxis", 
                "yAxis", "zAxis", "polar", "zoom", "fov")
            tkplace(tk2label(frame2, text = "Left"), x = 11, 
                y = 100, `in` = frame2)
            combo1 <- tkwidget(frame2, "ComboBox", editable = FALSE, 
                values = MousePossibilities, text = boptions$ThreeD.MouseButtonAction[1])
            tkplace(combo1, relx = 0.11, y = 100, relwidth = 0.2, 
                height = 17, `in` = frame2)
            tkplace(tk2label(frame2, text = "Middle"), relx = 0.33, 
                y = 100, `in` = frame2)
            combo2 <- tkwidget(frame2, "ComboBox", editable = FALSE, 
                values = MousePossibilities, text = boptions$ThreeD.MouseButtonAction[2])
            tkplace(combo2, relx = 0.44, y = 100, relwidth = 0.2, 
                height = 17, `in` = frame2)
            tkplace(tk2label(frame2, text = "Right"), relx = 0.66, 
                y = 100, `in` = frame2)
            combo3 <- tkwidget(frame2, "ComboBox", editable = FALSE, 
                values = MousePossibilities, text = boptions$ThreeD.MouseButtonAction[3])
            tkplace(combo3, relx = 0.755, y = 100, relwidth = 0.2, 
                height = 17, `in` = frame2)
            button1 <- tk2button(top, text = "Defaults", width = 10, 
                command = onDefaults)
            button2 <- tk2button(top, text = "OK", width = 10, 
                command = onOK)
            button3 <- tk2button(top, text = "Cancel", width = 10, 
                command = onCancel)
            tkplace(button1, relx = 0.05, rely = 0.99, anchor = "sw")
            tkplace(button2, relx = 0.775, rely = 0.99, anchor = "se")
            tkplace(button3, relx = 0.96, rely = 0.99, anchor = "se")
            tkbind(top, "<Return>", onOK)
            tkbind(top, "<Escape>", onCancel)
            tkbind(top, "<Destroy>", function() {
                tkgrab.release(top)
                tkfocus(GUI.TopLevel)
            })
            tkwm.geometry(top, paste("390x292", "+", round(GUI.AvailableScreenWidth/2 - 
                390/2, 0), "+", round(GUI.AvailableScreenHeight/2 - 
                292/2, 0), sep = ""))
            tkwm.focusmodel(top, "active")
            tkwm.resizable(top, "0", "0")
            tkwm.deiconify(top)
            tkwm.title(top, "Options")
            tkgrab.set(top)
            Rico <- tk2ico.load(res = "question")
            tk2ico.set(top, Rico)
            tk2ico.destroy(Rico)
            rm(Rico)
            tkwait.window(top)
        }
        local.GUI.func()
    }
    File.Exit.cmd <- function() {
        temp1 <- tkmessageBox(icon = "question", message = "Are you sure?", 
            parent = GUI.TopLevel, title = "Exit", type = "yesno")
        if (tclvalue(temp1) == "yes") 
            tkdestroy(GUI.TopLevel)
        else GUI.BindingsOn()
    }
    View.ShowTitle.cmd <- function() {
        Biplot.replot()
    }
    View.ShowTitle.var <- tclVar("0")
    View.ClipAroundPoints.cmd <- function() {
        Biplot.replot()
    }
    View.ClipAroundPointsAndAxes.cmd <- function() {
        Biplot.replot()
    }
    View.ClipAround.var <- tclVar("0")
    View.ShowPointLabels.cmd <- function() {
        Biplot.replot()
    }
    View.ShowPointLabels.var <- tclVar("1")
    View.ShowPointValues.cmd <- function() {
        Biplot.replot()
    }
    View.ShowPointValues.var <- tclVar("1")
    View.ShowGroupLabelsInLegend.cmd <- function() {
        Biplot.replot()
    }
    View.ShowGroupLabelsInLegend.var <- if (g == 1) 
        tclVar("0")
    else tclVar("1")
    View.DontShowAxisLabels.cmd <- function() {
        if (p.in < p) 
            Kraal.replot()
        Biplot.replot()
    }
    View.ShowClingingAxisLabels.cmd <- function() {
        if (p.in < p) 
            Kraal.replot()
        Biplot.replot()
    }
    View.ShowAxisLabelsInLegend.cmd <- function() {
        if (p.in < p) 
            Kraal.replot()
        Biplot.replot()
    }
    View.AxisLabels.var <- tclVar("1")
    View.ShowAdditionalLabelsInLegend.cmd <- function() {
        Biplot.replot()
    }
    View.ShowAdditionalLabelsInLegend.var <- tclVar("1")
    View.ShowNextLegendEntries.cmd <- function() {
        if (Legend.CurrentPage < Legend.LastPage) {
            Legend.CurrentPage <<- Legend.CurrentPage + 1
            Biplot.replot()
        }
    }
    View.ShowPreviousLegendEntries.cmd <- function() {
        if (Legend.CurrentPage > 1) {
            Legend.CurrentPage <<- Legend.CurrentPage - 1
            Biplot.replot()
        }
    }
    View.CalibrateDisplaySpaceAxes.cmd <- function() {
        Biplot.replot()
    }
    View.CalibrateDisplaySpaceAxes.var <- tclVar("0")
    Format.Title.cmd <- function() {
        local.GUI.func <- function() {
            top <- tktoplevel()
            tkwm.withdraw(top)
            onDefault <- function() {
                NewTitle <<- tclVar(Biplot.title.default)
                tkconfigure(entry1, textvariable = NewTitle)
            }
            onOK <- function() {
                tkdestroy(top)
                if (Biplot.title != tclvalue(NewTitle)) {
                  Biplot.title <<- tclvalue(NewTitle)
                  Biplot.replot()
                }
            }
            onCancel <- function() tkdestroy(top)
            NewTitle <- tclVar(Biplot.title)
            frame1 <- tk2frame(top, relief = "groove", borderwidth = "1.5p")
            label1 <- tk2label(frame1, text = "New title")
            entry1 <- tk2entry(frame1, textvariable = NewTitle)
            button1 <- tk2button(top, text = "OK", width = 10, 
                command = onOK)
            button2 <- tk2button(top, text = "Cancel", width = 10, 
                command = onCancel)
            button3 <- tk2button(top, text = "Default", width = 10, 
                command = onDefault)
            tkplace(frame1, relx = 0.5, rely = 0.4, relwidth = 0.9, 
                relheight = 0.4, anchor = "center")
            tkplace(label1, relx = 0.05, rely = 0.5, `in` = frame1, 
                anchor = "w")
            tkplace(entry1, relx = 0.5, rely = 0.5, relwidth = 0.45, 
                `in` = frame1, anchor = "w")
            tkplace(button1, relx = 0.7, rely = 0.85, anchor = "e")
            tkplace(button2, relx = 0.95, rely = 0.85, anchor = "e")
            tkplace(button3, relx = 0.05, rely = 0.85, anchor = "w")
            tkbind(entry1, "<Return>", onOK)
            tkbind(top, "<Escape>", onCancel)
            tkbind(top, "<Destroy>", function() {
                tkgrab.release(top)
                tkfocus(GUI.TopLevel)
            })
            tkwm.geometry(top, paste("300x120", "+", round(GUI.AvailableScreenWidth/2 - 
                300/2, 0), "+", round(GUI.AvailableScreenHeight/2 - 
                120/2, 0), sep = ""))
            tkwm.focusmodel(top, "active")
            tkwm.resizable(top, "0", "0")
            tkwm.deiconify(top)
            tkwm.title(top, "Title")
            tkgrab.set(top)
            Rico <- tk2ico.load(res = "question")
            tk2ico.set(top, Rico)
            tk2ico.destroy(Rico)
            rm(Rico)
            tkwait.window(top)
        }
        local.GUI.func()
    }
    Format.ByGroup.cmd <- function(WhichGroupInitially = 1, WhichTabInitially = 1) {
        local.GUI.func <- function() {
            ReturnToWindow <- tkfocus()
            top <- tktoplevel()
            tkwm.withdraw(top)
            WhichGroup <- WhichGroupInitially
            UpdateEntryBoxes <- function() {
                if (WhichGroup == 1 && tclvalue(local.points.cex.var[[1]]) != 
                  " ") 
                  for (temp1 in 2:(g + 1)) local.points.cex.var[[temp1]] <<- tclVar(tclvalue(local.points.cex.var[[1]]))
                if (WhichGroup == 1 && tclvalue(local.points.label.cex.var[[1]]) != 
                  " ") 
                  for (temp1 in 2:(g + 1)) local.points.label.cex.var[[temp1]] <<- tclVar(tclvalue(local.points.label.cex.var[[1]]))
                if (WhichGroup == 1 && tclvalue(local.points.label.HorizOffset.var[[1]]) != 
                  " ") 
                  for (temp1 in 2:(g + 1)) local.points.label.HorizOffset.var[[temp1]] <<- tclVar(tclvalue(local.points.label.HorizOffset.var[[1]]))
                if (WhichGroup == 1 && tclvalue(local.points.label.VertOffset.var[[1]]) != 
                  " ") 
                  for (temp1 in 2:(g + 1)) local.points.label.VertOffset.var[[temp1]] <<- tclVar(tclvalue(local.points.label.VertOffset.var[[1]]))
                if (WhichGroup == 1 && tclvalue(local.SampleGroupMeans.cex.var[[1]]) != 
                  " ") 
                  for (temp1 in 2:(g + 1)) local.SampleGroupMeans.cex.var[[temp1]] <<- tclVar(tclvalue(local.SampleGroupMeans.cex.var[[1]]))
                if (WhichGroup == 1 && tclvalue(local.SampleGroupMeans.label.cex.var[[1]]) != 
                  " ") 
                  for (temp1 in 2:(g + 1)) local.SampleGroupMeans.label.cex.var[[temp1]] <<- tclVar(tclvalue(local.SampleGroupMeans.label.cex.var[[1]]))
                if (WhichGroup == 1 && tclvalue(local.SampleGroupMeans.label.HorizOffset.var[[1]]) != 
                  " ") 
                  for (temp1 in 2:(g + 1)) local.SampleGroupMeans.label.HorizOffset.var[[temp1]] <<- tclVar(tclvalue(local.SampleGroupMeans.label.HorizOffset.var[[1]]))
                if (WhichGroup == 1 && tclvalue(local.SampleGroupMeans.label.VertOffset.var[[1]]) != 
                  " ") 
                  for (temp1 in 2:(g + 1)) local.SampleGroupMeans.label.VertOffset.var[[temp1]] <<- tclVar(tclvalue(local.SampleGroupMeans.label.VertOffset.var[[1]]))
                if (WhichGroup == 1 && tclvalue(local.ConvexHullAlphaBag.lwd.var[[1]]) != 
                  " ") 
                  for (temp1 in 2:(g + 1)) local.ConvexHullAlphaBag.lwd.var[[temp1]] <<- tclVar(tclvalue(local.ConvexHullAlphaBag.lwd.var[[1]]))
                if (WhichGroup == 1 && tclvalue(local.ConvexHullAlphaBag.TukeyMedian.cex.var[[1]]) != 
                  " ") 
                  for (temp1 in 2:(g + 1)) local.ConvexHullAlphaBag.TukeyMedian.cex.var[[temp1]] <<- tclVar(tclvalue(local.ConvexHullAlphaBag.TukeyMedian.cex.var[[1]]))
                if (WhichGroup == 1 && tclvalue(local.ConvexHullAlphaBag.TukeyMedian.cex.var[[1]]) != 
                  " ") 
                  for (temp1 in 2:(g + 1)) local.ConvexHullAlphaBag.TukeyMedian.cex.var[[temp1]] <<- tclVar(tclvalue(local.ConvexHullAlphaBag.TukeyMedian.cex.var[[1]]))
                if (WhichGroup == 1 && tclvalue(local.ConvexHullAlphaBag.TukeyMedian.label.cex.var[[1]]) != 
                  " ") 
                  for (temp1 in 2:(g + 1)) local.ConvexHullAlphaBag.TukeyMedian.label.cex.var[[temp1]] <<- tclVar(tclvalue(local.ConvexHullAlphaBag.TukeyMedian.label.cex.var[[1]]))
                if (WhichGroup == 1 && tclvalue(local.ConvexHullAlphaBag.TukeyMedian.label.HorizOffset.var[[1]]) != 
                  " ") 
                  for (temp1 in 2:(g + 1)) local.ConvexHullAlphaBag.TukeyMedian.label.HorizOffset.var[[temp1]] <<- tclVar(tclvalue(local.ConvexHullAlphaBag.TukeyMedian.label.HorizOffset.var[[1]]))
                if (WhichGroup == 1 && tclvalue(local.ConvexHullAlphaBag.TukeyMedian.label.VertOffset.var[[1]]) != 
                  " ") 
                  for (temp1 in 2:(g + 1)) local.ConvexHullAlphaBag.TukeyMedian.label.VertOffset.var[[temp1]] <<- tclVar(tclvalue(local.ConvexHullAlphaBag.TukeyMedian.label.VertOffset.var[[1]]))
            }
            ChangeGroup <- function() {
                UpdateEntryBoxes()
                temp <- as.numeric(tclvalue(tkcurselection(listbox1))) + 
                  1
                if (!is.na(temp)) 
                  WhichGroup <<- temp
                local.points.pch.var[[1]] <<- if (all(unlist(lapply(local.points.pch.var[-1], 
                  tclvalue)) == tclvalue(local.points.pch.var[[2]]))) 
                  local.points.pch.var[[2]]
                else tclVar(" ")
                tkconfigure(spinboxA1, textvariable = local.points.pch.var[[WhichGroup]])
                local.points.cex.var[[1]] <<- if (all(unlist(lapply(local.points.cex.var[-1], 
                  tclvalue)) == tclvalue(local.points.cex.var[[2]]))) 
                  local.points.cex.var[[2]]
                else tclVar(" ")
                tkconfigure(entryA1, textvariable = local.points.cex.var[[WhichGroup]])
                local.points.col.fg.var[[1]] <<- if (all(unlist(local.points.col.fg.var[-1]) == 
                  local.points.col.fg.var[[2]])) 
                  local.points.col.fg.var[[2]]
                else text2hex("SystemButtonFace")
                tkconfigure(labelA1, background = local.points.col.fg.var[[WhichGroup]])
                local.points.col.bg.var[[1]] <<- if (all(unlist(local.points.col.bg.var[-1]) == 
                  local.points.col.bg.var[[2]])) 
                  local.points.col.bg.var[[2]]
                else text2hex("SystemButtonFace")
                tkconfigure(labelA2, background = local.points.col.bg.var[[WhichGroup]])
                local.points.label.font.var[[1]] <<- if (all(unlist(lapply(local.points.label.font.var[-1], 
                  tclvalue)) == tclvalue(local.points.label.font.var[[2]]))) 
                  local.points.label.font.var[[2]]
                else tclVar(" ")
                tkconfigure(spinboxA2, textvariable = local.points.label.font.var[[WhichGroup]])
                local.points.label.cex.var[[1]] <<- if (all(unlist(lapply(local.points.label.cex.var[-1], 
                  tclvalue)) == tclvalue(local.points.label.cex.var[[2]]))) 
                  local.points.label.cex.var[[2]]
                else tclVar(" ")
                tkconfigure(entryA2, textvariable = local.points.label.cex.var[[WhichGroup]])
                local.points.label.col.var[[1]] <<- if (all(unlist(local.points.label.col.var[-1]) == 
                  local.points.label.col.var[[2]])) 
                  local.points.label.col.var[[2]]
                else text2hex("SystemButtonFace")
                tkconfigure(labelA3, background = local.points.label.col.var[[WhichGroup]])
                local.points.label.HorizOffset.var[[1]] <<- if (all(unlist(lapply(local.points.label.HorizOffset.var[-1], 
                  tclvalue)) == tclvalue(local.points.label.HorizOffset.var[[2]]))) 
                  local.points.label.HorizOffset.var[[2]]
                else tclVar(" ")
                tkconfigure(entryA3, textvariable = local.points.label.HorizOffset.var[[WhichGroup]])
                local.points.label.VertOffset.var[[1]] <<- if (all(unlist(lapply(local.points.label.VertOffset.var[-1], 
                  tclvalue)) == tclvalue(local.points.label.VertOffset.var[[2]]))) 
                  local.points.label.VertOffset.var[[2]]
                else tclVar(" ")
                tkconfigure(entryA4, textvariable = local.points.label.VertOffset.var[[WhichGroup]])
                local.SampleGroupMeans.pch.var[[1]] <<- if (all(unlist(lapply(local.SampleGroupMeans.pch.var[-1], 
                  tclvalue)) == tclvalue(local.SampleGroupMeans.pch.var[[2]]))) 
                  local.SampleGroupMeans.pch.var[[2]]
                else tclVar(" ")
                tkconfigure(spinboxB1, textvariable = local.SampleGroupMeans.pch.var[[WhichGroup]])
                local.SampleGroupMeans.cex.var[[1]] <<- if (all(unlist(lapply(local.SampleGroupMeans.cex.var[-1], 
                  tclvalue)) == tclvalue(local.SampleGroupMeans.cex.var[[2]]))) 
                  local.SampleGroupMeans.cex.var[[2]]
                else tclVar(" ")
                tkconfigure(entryB1, textvariable = local.SampleGroupMeans.cex.var[[WhichGroup]])
                local.SampleGroupMeans.col.fg.var[[1]] <<- if (all(unlist(local.SampleGroupMeans.col.fg.var[-1]) == 
                  local.SampleGroupMeans.col.fg.var[[2]])) 
                  local.SampleGroupMeans.col.fg.var[[2]]
                else text2hex("SystemButtonFace")
                tkconfigure(labelB1, background = local.SampleGroupMeans.col.fg.var[[WhichGroup]])
                local.SampleGroupMeans.col.bg.var[[1]] <<- if (all(unlist(local.SampleGroupMeans.col.bg.var[-1]) == 
                  local.SampleGroupMeans.col.bg.var[[2]])) 
                  local.SampleGroupMeans.col.bg.var[[2]]
                else text2hex("SystemButtonFace")
                tkconfigure(labelB2, background = local.SampleGroupMeans.col.bg.var[[WhichGroup]])
                local.SampleGroupMeans.label.font.var[[1]] <<- if (all(unlist(lapply(local.SampleGroupMeans.label.font.var[-1], 
                  tclvalue)) == tclvalue(local.SampleGroupMeans.label.font.var[[2]]))) 
                  local.SampleGroupMeans.label.font.var[[2]]
                else tclVar(" ")
                tkconfigure(spinboxB2, textvariable = local.SampleGroupMeans.label.font.var[[WhichGroup]])
                local.SampleGroupMeans.label.cex.var[[1]] <<- if (all(unlist(lapply(local.SampleGroupMeans.label.cex.var[-1], 
                  tclvalue)) == tclvalue(local.SampleGroupMeans.label.cex.var[[2]]))) 
                  local.SampleGroupMeans.label.cex.var[[2]]
                else tclVar(" ")
                tkconfigure(entryB2, textvariable = local.SampleGroupMeans.label.cex.var[[WhichGroup]])
                local.SampleGroupMeans.label.col.var[[1]] <<- if (all(unlist(local.SampleGroupMeans.label.col.var[-1]) == 
                  local.SampleGroupMeans.label.col.var[[2]])) 
                  local.SampleGroupMeans.label.col.var[[2]]
                else text2hex("SystemButtonFace")
                tkconfigure(labelB3, background = local.SampleGroupMeans.label.col.var[[WhichGroup]])
                local.SampleGroupMeans.label.HorizOffset.var[[1]] <<- if (all(unlist(lapply(local.SampleGroupMeans.label.HorizOffset.var[-1], 
                  tclvalue)) == tclvalue(local.SampleGroupMeans.label.HorizOffset.var[[2]]))) 
                  local.SampleGroupMeans.label.HorizOffset.var[[2]]
                else tclVar(" ")
                tkconfigure(entryB3, textvariable = local.SampleGroupMeans.label.HorizOffset.var[[WhichGroup]])
                local.SampleGroupMeans.label.VertOffset.var[[1]] <<- if (all(unlist(lapply(local.SampleGroupMeans.label.VertOffset.var[-1], 
                  tclvalue)) == tclvalue(local.SampleGroupMeans.label.VertOffset.var[[2]]))) 
                  local.SampleGroupMeans.label.VertOffset.var[[2]]
                else tclVar(" ")
                tkconfigure(entryB4, textvariable = local.SampleGroupMeans.label.VertOffset.var[[WhichGroup]])
                local.ConvexHullAlphaBag.lty.var[[1]] <<- if (all(unlist(lapply(local.ConvexHullAlphaBag.lty.var[-1], 
                  tclvalue)) == tclvalue(local.ConvexHullAlphaBag.lty.var[[2]]))) 
                  local.ConvexHullAlphaBag.lty.var[[2]]
                else tclVar(" ")
                tkconfigure(spinboxC1, textvariable = local.ConvexHullAlphaBag.lty.var[[WhichGroup]])
                local.ConvexHullAlphaBag.lwd.var[[1]] <<- if (all(unlist(lapply(local.ConvexHullAlphaBag.lwd.var[-1], 
                  tclvalue)) == tclvalue(local.ConvexHullAlphaBag.lwd.var[[2]]))) 
                  local.ConvexHullAlphaBag.lwd.var[[2]]
                else tclVar(" ")
                tkconfigure(entryC1, textvariable = local.ConvexHullAlphaBag.lwd.var[[WhichGroup]])
                local.ConvexHullAlphaBag.col.fg.var[[1]] <<- if (all(unlist(local.ConvexHullAlphaBag.col.fg.var[-1]) == 
                  local.ConvexHullAlphaBag.col.fg.var[[2]])) 
                  local.ConvexHullAlphaBag.col.fg.var[[2]]
                else text2hex("SystemButtonFace")
                tkconfigure(labelC1, background = local.ConvexHullAlphaBag.col.fg.var[[WhichGroup]])
                local.ConvexHullAlphaBag.col.bg.var[[1]] <<- if (all(unlist(local.ConvexHullAlphaBag.col.bg.var[-1]) == 
                  local.ConvexHullAlphaBag.col.bg.var[[2]])) 
                  local.ConvexHullAlphaBag.col.bg.var[[2]]
                else text2hex("SystemButtonFace")
                tkconfigure(labelC2, background = local.ConvexHullAlphaBag.col.bg.var[[WhichGroup]])
                local.ConvexHullAlphaBag.TukeyMedian.pch.var[[1]] <<- if (all(unlist(lapply(local.ConvexHullAlphaBag.TukeyMedian.pch.var[-1], 
                  tclvalue)) == tclvalue(local.ConvexHullAlphaBag.TukeyMedian.pch.var[[2]]))) 
                  local.ConvexHullAlphaBag.TukeyMedian.pch.var[[2]]
                else tclVar(" ")
                tkconfigure(spinboxC2, textvariable = local.ConvexHullAlphaBag.TukeyMedian.pch.var[[WhichGroup]])
                local.ConvexHullAlphaBag.TukeyMedian.cex.var[[1]] <<- if (all(unlist(lapply(local.ConvexHullAlphaBag.TukeyMedian.cex.var[-1], 
                  tclvalue)) == tclvalue(local.ConvexHullAlphaBag.TukeyMedian.cex.var[[2]]))) 
                  local.ConvexHullAlphaBag.TukeyMedian.cex.var[[2]]
                else tclVar(" ")
                tkconfigure(entryC2, textvariable = local.ConvexHullAlphaBag.TukeyMedian.cex.var[[WhichGroup]])
                local.ConvexHullAlphaBag.TukeyMedian.col.fg.var[[1]] <<- if (all(unlist(local.ConvexHullAlphaBag.TukeyMedian.col.fg.var[-1]) == 
                  local.ConvexHullAlphaBag.TukeyMedian.col.fg.var[[2]])) 
                  local.ConvexHullAlphaBag.TukeyMedian.col.fg.var[[2]]
                else text2hex("SystemButtonFace")
                tkconfigure(labelC3, background = local.ConvexHullAlphaBag.TukeyMedian.col.fg.var[[WhichGroup]])
                local.ConvexHullAlphaBag.TukeyMedian.col.bg.var[[1]] <<- if (all(unlist(local.ConvexHullAlphaBag.TukeyMedian.col.bg.var[-1]) == 
                  local.ConvexHullAlphaBag.TukeyMedian.col.bg.var[[2]])) 
                  local.ConvexHullAlphaBag.TukeyMedian.col.bg.var[[2]]
                else text2hex("SystemButtonFace")
                tkconfigure(labelC4, background = local.ConvexHullAlphaBag.TukeyMedian.col.bg.var[[WhichGroup]])
                local.ConvexHullAlphaBag.TukeyMedian.label.font.var[[1]] <<- if (all(unlist(lapply(local.ConvexHullAlphaBag.TukeyMedian.label.font.var[-1], 
                  tclvalue)) == tclvalue(local.ConvexHullAlphaBag.TukeyMedian.label.font.var[[2]]))) 
                  local.ConvexHullAlphaBag.TukeyMedian.label.font.var[[2]]
                else tclVar(" ")
                tkconfigure(spinboxC3, textvariable = local.ConvexHullAlphaBag.TukeyMedian.label.font.var[[WhichGroup]])
                local.ConvexHullAlphaBag.TukeyMedian.label.cex.var[[1]] <<- if (all(unlist(lapply(local.ConvexHullAlphaBag.TukeyMedian.label.cex.var[-1], 
                  tclvalue)) == tclvalue(local.ConvexHullAlphaBag.TukeyMedian.label.cex.var[[2]]))) 
                  local.ConvexHullAlphaBag.TukeyMedian.label.cex.var[[2]]
                else tclVar(" ")
                tkconfigure(entryC3, textvariable = local.ConvexHullAlphaBag.TukeyMedian.label.cex.var[[WhichGroup]])
                local.ConvexHullAlphaBag.TukeyMedian.label.col.var[[1]] <<- if (all(unlist(local.ConvexHullAlphaBag.TukeyMedian.label.col.var[-1]) == 
                  local.ConvexHullAlphaBag.TukeyMedian.label.col.var[[2]])) 
                  local.ConvexHullAlphaBag.TukeyMedian.label.col.var[[2]]
                else text2hex("SystemButtonFace")
                tkconfigure(labelC5, background = local.ConvexHullAlphaBag.TukeyMedian.label.col.var[[WhichGroup]])
                local.ConvexHullAlphaBag.TukeyMedian.label.HorizOffset.var[[1]] <<- if (all(unlist(lapply(local.ConvexHullAlphaBag.TukeyMedian.label.HorizOffset.var[-1], 
                  tclvalue)) == tclvalue(local.ConvexHullAlphaBag.TukeyMedian.label.HorizOffset.var[[2]]))) 
                  local.ConvexHullAlphaBag.TukeyMedian.label.HorizOffset.var[[2]]
                else tclVar(" ")
                tkconfigure(entryC4, textvariable = local.ConvexHullAlphaBag.TukeyMedian.label.HorizOffset.var[[WhichGroup]])
                local.ConvexHullAlphaBag.TukeyMedian.label.VertOffset.var[[1]] <<- if (all(unlist(lapply(local.ConvexHullAlphaBag.TukeyMedian.label.VertOffset.var[-1], 
                  tclvalue)) == tclvalue(local.ConvexHullAlphaBag.TukeyMedian.label.VertOffset.var[[2]]))) 
                  local.ConvexHullAlphaBag.TukeyMedian.label.VertOffset.var[[2]]
                else tclVar(" ")
                tkconfigure(entryC5, textvariable = local.ConvexHullAlphaBag.TukeyMedian.label.VertOffset.var[[WhichGroup]])
                local.ClassificationRegion.col.bg.var[[1]] <<- if (all(unlist(local.ClassificationRegion.col.bg.var[-1]) == 
                  local.ClassificationRegion.col.bg.var[[2]])) 
                  local.ClassificationRegion.col.bg.var[[2]]
                else text2hex("SystemButtonFace")
                tkconfigure(labelD1, background = local.ClassificationRegion.col.bg.var[[WhichGroup]])
            }
            onDefaults <- function() {
                bpar.initialise1.func()
                initialise()
                ChangeGroup()
            }
            onOK <- function() {
                UpdateEntryBoxes()
                bpar$gpoints.pch <<- as.numeric(lapply(local.points.pch.var[-1], 
                  tclvalue))
                bpar$gpoints.cex <<- as.numeric(lapply(local.points.cex.var[-1], 
                  tclvalue))
                bpar$gpoints.col.fg <<- unlist(local.points.col.fg.var[-1])
                bpar$gpoints.col.bg <<- unlist(local.points.col.bg.var[-1])
                bpar$gpoints.label.font <<- as.numeric(lapply(local.points.label.font.var[-1], 
                  tclvalue))
                bpar$gpoints.label.cex <<- as.numeric(lapply(local.points.label.cex.var[-1], 
                  tclvalue))
                bpar$gpoints.label.col <<- unlist(local.points.label.col.var[-1])
                bpar$gpoints.label.HorizOffset <<- as.numeric(lapply(local.points.label.HorizOffset.var[-1], 
                  tclvalue))
                bpar$gpoints.label.VertOffset <<- as.numeric(lapply(local.points.label.VertOffset.var[-1], 
                  tclvalue))
                bpar$gSampleGroupMeans.pch <<- as.numeric(lapply(local.SampleGroupMeans.pch.var[-1], 
                  tclvalue))
                bpar$gSampleGroupMeans.cex <<- as.numeric(lapply(local.SampleGroupMeans.cex.var[-1], 
                  tclvalue))
                bpar$gSampleGroupMeans.col.fg <<- unlist(local.SampleGroupMeans.col.fg.var[-1])
                bpar$gSampleGroupMeans.col.bg <<- unlist(local.SampleGroupMeans.col.bg.var[-1])
                bpar$gSampleGroupMeans.label.font <<- as.numeric(lapply(local.SampleGroupMeans.label.font.var[-1], 
                  tclvalue))
                bpar$gSampleGroupMeans.label.cex <<- as.numeric(lapply(local.SampleGroupMeans.label.cex.var[-1], 
                  tclvalue))
                bpar$gSampleGroupMeans.label.col <<- unlist(local.SampleGroupMeans.label.col.var[-1])
                bpar$gSampleGroupMeans.label.HorizOffset <<- as.numeric(lapply(local.SampleGroupMeans.label.HorizOffset.var[-1], 
                  tclvalue))
                bpar$gSampleGroupMeans.label.VertOffset <<- as.numeric(lapply(local.SampleGroupMeans.label.VertOffset.var[-1], 
                  tclvalue))
                bpar$gConvexHullAlphaBag.lty <<- as.numeric(lapply(local.ConvexHullAlphaBag.lty.var[-1], 
                  tclvalue))
                bpar$gConvexHullAlphaBag.lwd <<- as.numeric(lapply(local.ConvexHullAlphaBag.lwd.var[-1], 
                  tclvalue))
                bpar$gConvexHullAlphaBag.col.fg <<- unlist(local.ConvexHullAlphaBag.col.fg.var[-1])
                bpar$gConvexHullAlphaBag.col.bg <<- unlist(local.ConvexHullAlphaBag.col.bg.var[-1])
                bpar$gConvexHullAlphaBag.TukeyMedian.pch <<- as.numeric(lapply(local.ConvexHullAlphaBag.TukeyMedian.pch.var[-1], 
                  tclvalue))
                bpar$gConvexHullAlphaBag.TukeyMedian.cex <<- as.numeric(lapply(local.ConvexHullAlphaBag.TukeyMedian.cex.var[-1], 
                  tclvalue))
                bpar$gConvexHullAlphaBag.TukeyMedian.col.fg <<- unlist(local.ConvexHullAlphaBag.TukeyMedian.col.fg.var[-1])
                bpar$gConvexHullAlphaBag.TukeyMedian.col.bg <<- unlist(local.ConvexHullAlphaBag.TukeyMedian.col.bg.var[-1])
                bpar$gConvexHullAlphaBag.TukeyMedian.label.font <<- as.numeric(lapply(local.ConvexHullAlphaBag.TukeyMedian.label.font.var[-1], 
                  tclvalue))
                bpar$gConvexHullAlphaBag.TukeyMedian.label.cex <<- as.numeric(lapply(local.ConvexHullAlphaBag.TukeyMedian.label.cex.var[-1], 
                  tclvalue))
                bpar$gConvexHullAlphaBag.TukeyMedian.label.col <<- unlist(local.ConvexHullAlphaBag.TukeyMedian.label.col.var[-1])
                bpar$gConvexHullAlphaBag.TukeyMedian.label.HorizOffset <<- as.numeric(lapply(local.ConvexHullAlphaBag.TukeyMedian.label.HorizOffset.var[-1], 
                  tclvalue))
                bpar$gConvexHullAlphaBag.TukeyMedian.label.VertOffset <<- as.numeric(lapply(local.ConvexHullAlphaBag.TukeyMedian.label.VertOffset.var[-1], 
                  tclvalue))
                bpar$gClassificationRegion.col.bg <<- unlist(local.ClassificationRegion.col.bg.var[-1])
                bparp.func()
                if (WhichTabInitially == 1) 
                  Biplot.replot()
                if (tclvalue(Biplot.Axes.var) %in% c("0", "2")) 
                  PointsTab.predictivities.replot()
                if (tclvalue(Biplot.Axes.var) == "2") 
                  GroupsTab.replot()
                if (n.in < n) 
                  Kraal.replot()
                tkdestroy(top)
            }
            onCancel <- function() tkdestroy(top)
            local.points.pch.var <- NULL
            local.points.cex.var <- NULL
            local.points.col.fg.var <- NULL
            local.points.col.bg.var <- NULL
            local.points.label.font.var <- NULL
            local.points.label.cex.var <- NULL
            local.points.label.col.var <- NULL
            local.points.label.HorizOffset.var <- NULL
            local.points.label.VertOffset.var <- NULL
            local.SampleGroupMeans.pch.var <- NULL
            local.SampleGroupMeans.cex.var <- NULL
            local.SampleGroupMeans.col.fg.var <- NULL
            local.SampleGroupMeans.col.bg.var <- NULL
            local.SampleGroupMeans.label.font.var <- NULL
            local.SampleGroupMeans.label.cex.var <- NULL
            local.SampleGroupMeans.label.col.var <- NULL
            local.SampleGroupMeans.label.HorizOffset.var <- NULL
            local.SampleGroupMeans.label.VertOffset.var <- NULL
            local.ConvexHullAlphaBag.lty.var <- NULL
            local.ConvexHullAlphaBag.lwd.var <- NULL
            local.ConvexHullAlphaBag.col.fg.var <- NULL
            local.ConvexHullAlphaBag.col.bg.var <- NULL
            local.ConvexHullAlphaBag.TukeyMedian.pch.var <- NULL
            local.ConvexHullAlphaBag.TukeyMedian.cex.var <- NULL
            local.ConvexHullAlphaBag.TukeyMedian.col.fg.var <- NULL
            local.ConvexHullAlphaBag.TukeyMedian.col.bg.var <- NULL
            local.ConvexHullAlphaBag.TukeyMedian.label.font.var <- NULL
            local.ConvexHullAlphaBag.TukeyMedian.label.cex.var <- NULL
            local.ConvexHullAlphaBag.TukeyMedian.label.col.var <- NULL
            local.ConvexHullAlphaBag.TukeyMedian.label.HorizOffset.var <- NULL
            local.ConvexHullAlphaBag.TukeyMedian.label.VertOffset.var <- NULL
            local.ClassificationRegion.col.bg.var <- NULL
            initialise <- function() {
                local.points.pch.var <<- lapply(c(if (identical(bpar$gpoints.pch, 
                  rep(bpar$gpoints.pch[1], g))) bpar$gpoints.pch[1] else " ", 
                  as.character(bpar$gpoints.pch)), tclVar)
                local.points.cex.var <<- lapply(c(if (identical(bpar$gpoints.cex, 
                  rep(bpar$gpoints.cex[1], g))) bpar$gpoints.cex[1] else " ", 
                  as.character(bpar$gpoints.cex)), tclVar)
                local.points.col.fg.var <<- lapply(c(if (identical(bpar$gpoints.col.fg, 
                  rep(bpar$gpoints.col.fg[1], g))) bpar$gpoints.col.fg[1] else "SystemButtonFace", 
                  as.character(bpar$gpoints.col.fg)), text2hex)
                local.points.col.bg.var <<- lapply(c(if (identical(bpar$gpoints.col.bg, 
                  rep(bpar$gpoints.col.bg[1], g))) bpar$gpoints.col.bg[1] else "SystemButtonFace", 
                  as.character(bpar$gpoints.col.bg)), text2hex)
                local.points.label.font.var <<- lapply(c(if (identical(bpar$gpoints.label.font, 
                  rep(bpar$gpoints.label.font[1], g))) bpar$gpoints.label.font[1] else " ", 
                  as.character(bpar$gpoints.label.font)), tclVar)
                local.points.label.cex.var <<- lapply(c(if (identical(bpar$gpoints.label.cex, 
                  rep(bpar$gpoints.label.cex[1], g))) bpar$gpoints.label.cex[1] else " ", 
                  as.character(bpar$gpoints.label.cex)), tclVar)
                local.points.label.col.var <<- lapply(c(if (identical(bpar$gpoints.label.col, 
                  rep(bpar$gpoints.label.col[1], g))) bpar$gpoints.label.col[1] else "SystemButtonFace", 
                  as.character(bpar$gpoints.label.col)), text2hex)
                local.points.label.HorizOffset.var <<- lapply(c(if (identical(bpar$gpoints.label.HorizOffset, 
                  rep(bpar$gpoints.label.HorizOffset[1], g))) bpar$gpoints.label.HorizOffset[1] else " ", 
                  as.character(bpar$gpoints.label.HorizOffset)), 
                  tclVar)
                local.points.label.VertOffset.var <<- lapply(c(if (identical(bpar$gpoints.label.VertOffset, 
                  rep(bpar$gpoints.label.VertOffset[1], g))) bpar$gpoints.label.VertOffset[1] else " ", 
                  as.character(bpar$gpoints.label.VertOffset)), 
                  tclVar)
                local.SampleGroupMeans.pch.var <<- lapply(c(if (identical(bpar$gSampleGroupMeans.pch, 
                  rep(bpar$gSampleGroupMeans.pch[1], g))) bpar$gSampleGroupMeans.pch[1] else " ", 
                  as.character(bpar$gSampleGroupMeans.pch)), 
                  tclVar)
                local.SampleGroupMeans.cex.var <<- lapply(c(if (identical(bpar$gSampleGroupMeans.cex, 
                  rep(bpar$gSampleGroupMeans.cex[1], g))) bpar$gSampleGroupMeans.cex[1] else " ", 
                  as.character(bpar$gSampleGroupMeans.cex)), 
                  tclVar)
                local.SampleGroupMeans.col.fg.var <<- lapply(c(if (identical(bpar$gSampleGroupMeans.col.fg, 
                  rep(bpar$gSampleGroupMeans.col.fg[1], g))) bpar$gSampleGroupMeans.col.fg[1] else "SystemButtonFace", 
                  as.character(bpar$gSampleGroupMeans.col.fg)), 
                  text2hex)
                local.SampleGroupMeans.col.bg.var <<- lapply(c(if (identical(bpar$gSampleGroupMeans.col.bg, 
                  rep(bpar$gSampleGroupMeans.col.bg[1], g))) bpar$gSampleGroupMeans.col.bg[1] else "SystemButtonFace", 
                  as.character(bpar$gSampleGroupMeans.col.bg)), 
                  text2hex)
                local.SampleGroupMeans.label.font.var <<- lapply(c(if (identical(bpar$gSampleGroupMeans.label.font, 
                  rep(bpar$gSampleGroupMeans.label.font[1], g))) bpar$gSampleGroupMeans.label.font[1] else " ", 
                  as.character(bpar$gSampleGroupMeans.label.font)), 
                  tclVar)
                local.SampleGroupMeans.label.cex.var <<- lapply(c(if (identical(bpar$gSampleGroupMeans.label.cex, 
                  rep(bpar$gSampleGroupMeans.label.cex[1], g))) bpar$gSampleGroupMeans.label.cex[1] else " ", 
                  as.character(bpar$gSampleGroupMeans.label.cex)), 
                  tclVar)
                local.SampleGroupMeans.label.col.var <<- lapply(c(if (identical(bpar$gSampleGroupMeans.label.col, 
                  rep(bpar$gSampleGroupMeans.label.col[1], g))) bpar$gSampleGroupMeans.label.col[1] else "SystemButtonFace", 
                  as.character(bpar$gSampleGroupMeans.label.col)), 
                  text2hex)
                local.SampleGroupMeans.label.HorizOffset.var <<- lapply(c(if (identical(bpar$gSampleGroupMeans.label.HorizOffset, 
                  rep(bpar$gSampleGroupMeans.label.HorizOffset[1], 
                    g))) bpar$gSampleGroupMeans.label.HorizOffset[1] else " ", 
                  as.character(bpar$gSampleGroupMeans.label.HorizOffset)), 
                  tclVar)
                local.SampleGroupMeans.label.VertOffset.var <<- lapply(c(if (identical(bpar$gSampleGroupMeans.label.VertOffset, 
                  rep(bpar$gSampleGroupMeans.label.VertOffset[1], 
                    g))) bpar$gSampleGroupMeans.label.VertOffset[1] else " ", 
                  as.character(bpar$gSampleGroupMeans.label.VertOffset)), 
                  tclVar)
                local.ConvexHullAlphaBag.lty.var <<- lapply(c(if (identical(bpar$gConvexHullAlphaBag.lty, 
                  rep(bpar$gConvexHullAlphaBag.lty[1], g))) bpar$gConvexHullAlphaBag.lty[1] else " ", 
                  as.character(bpar$gConvexHullAlphaBag.lty)), 
                  tclVar)
                local.ConvexHullAlphaBag.lwd.var <<- lapply(c(if (identical(bpar$gConvexHullAlphaBag.lwd, 
                  rep(bpar$gConvexHullAlphaBag.lwd[1], g))) bpar$gConvexHullAlphaBag.lwd[1] else " ", 
                  as.character(bpar$gConvexHullAlphaBag.lwd)), 
                  tclVar)
                local.ConvexHullAlphaBag.col.fg.var <<- lapply(c(if (identical(bpar$gConvexHullAlphaBag.col.fg, 
                  rep(bpar$gConvexHullAlphaBag.col.fg[1], g))) bpar$gConvexHullAlphaBag.col.fg[1] else "SystemButtonFace", 
                  as.character(bpar$gConvexHullAlphaBag.col.fg)), 
                  text2hex)
                local.ConvexHullAlphaBag.col.bg.var <<- lapply(c(if (identical(bpar$gConvexHullAlphaBag.col.bg, 
                  rep(bpar$gConvexHullAlphaBag.col.bg[1], g))) bpar$gConvexHullAlphaBag.col.bg[1] else "SystemButtonFace", 
                  as.character(bpar$gConvexHullAlphaBag.col.bg)), 
                  text2hex)
                local.ConvexHullAlphaBag.TukeyMedian.pch.var <<- lapply(c(if (identical(bpar$gConvexHullAlphaBag.TukeyMedian.pch, 
                  rep(bpar$gConvexHullAlphaBag.TukeyMedian.pch[1], 
                    g))) bpar$gConvexHullAlphaBag.TukeyMedian.pch[1] else " ", 
                  as.character(bpar$gConvexHullAlphaBag.TukeyMedian.pch)), 
                  tclVar)
                local.ConvexHullAlphaBag.TukeyMedian.cex.var <<- lapply(c(if (identical(bpar$gConvexHullAlphaBag.TukeyMedian.cex, 
                  rep(bpar$gConvexHullAlphaBag.TukeyMedian.cex[1], 
                    g))) bpar$gConvexHullAlphaBag.TukeyMedian.cex[1] else " ", 
                  as.character(bpar$gConvexHullAlphaBag.TukeyMedian.cex)), 
                  tclVar)
                local.ConvexHullAlphaBag.TukeyMedian.col.fg.var <<- lapply(c(if (identical(bpar$gConvexHullAlphaBag.TukeyMedian.col.fg, 
                  rep(bpar$gConvexHullAlphaBag.TukeyMedian.col.fg[1], 
                    g))) bpar$gConvexHullAlphaBag.TukeyMedian.col.fg[1] else "SystemButtonFace", 
                  as.character(bpar$gConvexHullAlphaBag.TukeyMedian.col.fg)), 
                  text2hex)
                local.ConvexHullAlphaBag.TukeyMedian.col.bg.var <<- lapply(c(if (identical(bpar$gConvexHullAlphaBag.TukeyMedian.col.bg, 
                  rep(bpar$gConvexHullAlphaBag.TukeyMedian.col.bg[1], 
                    g))) bpar$gConvexHullAlphaBag.TukeyMedian.col.bg[1] else "SystemButtonFace", 
                  as.character(bpar$gConvexHullAlphaBag.TukeyMedian.col.bg)), 
                  text2hex)
                local.ConvexHullAlphaBag.TukeyMedian.label.font.var <<- lapply(c(if (identical(bpar$gConvexHullAlphaBag.TukeyMedian.label.font, 
                  rep(bpar$gConvexHullAlphaBag.TukeyMedian.label.font[1], 
                    g))) bpar$gConvexHullAlphaBag.TukeyMedian.label.font[1] else " ", 
                  as.character(bpar$gConvexHullAlphaBag.TukeyMedian.label.font)), 
                  tclVar)
                local.ConvexHullAlphaBag.TukeyMedian.label.cex.var <<- lapply(c(if (identical(bpar$gConvexHullAlphaBag.TukeyMedian.label.cex, 
                  rep(bpar$gConvexHullAlphaBag.TukeyMedian.label.cex[1], 
                    g))) bpar$gConvexHullAlphaBag.TukeyMedian.label.cex[1] else " ", 
                  as.character(bpar$gConvexHullAlphaBag.TukeyMedian.label.cex)), 
                  tclVar)
                local.ConvexHullAlphaBag.TukeyMedian.label.col.var <<- lapply(c(if (identical(bpar$gConvexHullAlphaBag.TukeyMedian.label.col, 
                  rep(bpar$gConvexHullAlphaBag.TukeyMedian.label.col[1], 
                    g))) bpar$gConvexHullAlphaBag.TukeyMedian.label.col[1] else "SystemButtonFace", 
                  as.character(bpar$gConvexHullAlphaBag.TukeyMedian.label.col)), 
                  text2hex)
                local.ConvexHullAlphaBag.TukeyMedian.label.HorizOffset.var <<- lapply(c(if (identical(bpar$gConvexHullAlphaBag.TukeyMedian.label.HorizOffset, 
                  rep(bpar$gConvexHullAlphaBag.TukeyMedian.label.HorizOffset[1], 
                    g))) bpar$gConvexHullAlphaBag.TukeyMedian.label.HorizOffset[1] else " ", 
                  as.character(bpar$gConvexHullAlphaBag.TukeyMedian.label.HorizOffset)), 
                  tclVar)
                local.ConvexHullAlphaBag.TukeyMedian.label.VertOffset.var <<- lapply(c(if (identical(bpar$gConvexHullAlphaBag.TukeyMedian.label.VertOffset, 
                  rep(bpar$gConvexHullAlphaBag.TukeyMedian.label.VertOffset[1], 
                    g))) bpar$gConvexHullAlphaBag.TukeyMedian.label.VertOffset[1] else " ", 
                  as.character(bpar$gConvexHullAlphaBag.TukeyMedian.label.VertOffset)), 
                  tclVar)
                local.ClassificationRegion.col.bg.var <<- lapply(c(if (identical(bpar$gClassificationRegion.col.bg, 
                  rep(bpar$gClassificationRegion.col.bg[1], g))) bpar$gClassificationRegion.col.bg[1] else "SystemButtonFace", 
                  as.character(bpar$gClassificationRegion.col.bg)), 
                  text2hex)
            }
            initialise()
            listbox1 <- tkwidget(top, "listbox", bg = "white", 
                relief = "groove", borderwidth = "1.5p", yscrollcommand = function(...) tkset(listbox1.scry, 
                  ...))
            listbox1.scry <- tkscrollbar(top, repeatinterval = 5, 
                command = function(...) tkyview(listbox1, ...))
            tkinsert(listbox1, "end", "All groups")
            if (g > 1) 
                for (i in bpar$groups.label.text) tkinsert(listbox1, 
                  "end", i)
            tkselect(listbox1, "set", WhichGroupInitially - 1)
            notebook <- tk2notebook(top, tabs = NULL)
            notebook.A <- tk2frame(notebook)
            tkadd(notebook, notebook.A, text = "Points")
            frameA1 <- tkwidget(notebook.A, "TitleFrame", text = "Plotting character")
            tkplace(frameA1, relx = 0.05, relwidth = 0.9, y = 10, 
                height = 105, `in` = notebook.A)
            tkplace(tk2label(frameA1, text = "Symbol"), x = 11, 
                y = 20, `in` = frameA1)
            spinboxA1 <- tkwidget(frameA1, "SpinBox", textvariable = local.points.pch.var[[WhichGroup]], 
                editable = FALSE, values = c(" ", "NA", 0:25), 
                justify = "right", modifycmd = function() {
                  if (WhichGroup == 1 && tclvalue(local.points.pch.var[[1]]) != 
                    " ") 
                    for (temp1 in 2:(g + 1)) local.points.pch.var[[temp1]] <<- tclVar(tclvalue(local.points.pch.var[[1]]))
                })
            tkplace(spinboxA1, relx = 0.95, y = 20, height = 18, 
                relwidth = 0.125, `in` = frameA1, anchor = "ne")
            tkplace(tk2label(frameA1, text = "Size"), x = 11, 
                y = 40, `in` = frameA1)
            entryA1 <- tk2entry(frameA1, textvariable = local.points.cex.var[[WhichGroup]], 
                justify = "right", takefocus = FALSE)
            tkplace(entryA1, relx = 0.95, y = 40, height = 18, 
                relwidth = 0.125, `in` = frameA1, anchor = "ne")
            tkplace(tk2label(frameA1, text = "Foreground colour"), 
                x = 11, y = 60, `in` = frameA1)
            labelA1 <- tklabel(frameA1, background = local.points.col.fg.var[[WhichGroup]], 
                relief = "groove", borderwidth = "1.5p")
            tkplace(labelA1, relx = 0.95, y = 60, height = 18, 
                relwidth = 0.125, `in` = frameA1, anchor = "ne")
            tkbind(labelA1, "<Button-1>", function() {
                temp1 <- tkchooseColor(initialcolor = local.points.col.fg.var[[WhichGroup]])
                if (!(tclvalue(temp1) == "")) {
                  temp1 <- tclvalue(temp1)
                  local.points.col.fg.var[[WhichGroup]] <<- temp1
                  tkconfigure(labelA1, background = local.points.col.fg.var[[WhichGroup]])
                  if (WhichGroup == 1) 
                    for (temp1 in 2:(g + 1)) local.points.col.fg.var[[temp1]] <<- local.points.col.fg.var[[1]]
                }
            })
            tkplace(tk2label(frameA1, text = "Background colour"), 
                x = 11, y = 80, `in` = frameA1)
            labelA2 <- tklabel(frameA1, background = local.points.col.bg.var[[WhichGroup]], 
                relief = "groove", borderwidth = "1.5p")
            tkplace(labelA2, relx = 0.95, y = 80, height = 18, 
                relwidth = 0.125, `in` = frameA1, anchor = "ne")
            tkbind(labelA2, "<Button-1>", function() {
                temp1 <- tkchooseColor(initialcolor = local.points.col.bg.var[[WhichGroup]])
                if (!(tclvalue(temp1) == "")) {
                  temp1 <- tclvalue(temp1)
                  local.points.col.bg.var[[WhichGroup]] <<- temp1
                  tkconfigure(labelA2, background = local.points.col.bg.var[[WhichGroup]])
                  if (WhichGroup == 1) 
                    for (temp1 in 2:(g + 1)) local.points.col.bg.var[[temp1]] <<- local.points.col.bg.var[[1]]
                }
            })
            frameA2 <- tkwidget(notebook.A, "TitleFrame", text = "Label")
            tkplace(frameA2, relx = 0.05, relwidth = 0.9, y = 130, 
                height = 125, `in` = notebook.A)
            tkplace(tk2label(frameA2, text = "Font"), x = 11, 
                y = 20, `in` = frameA2)
            spinboxA2 <- tkwidget(frameA2, "SpinBox", textvariable = local.points.label.font.var[[WhichGroup]], 
                editable = FALSE, values = c(" ", 1:4), justify = "right", 
                modifycmd = function() {
                  if (WhichGroup == 1 && tclvalue(local.points.label.font.var[[1]]) != 
                    " ") 
                    for (temp1 in 2:(g + 1)) local.points.label.font.var[[temp1]] <<- tclVar(tclvalue(local.points.label.font.var[[1]]))
                })
            tkplace(spinboxA2, relx = 0.95, y = 20, height = 18, 
                relwidth = 0.125, `in` = frameA2, anchor = "ne")
            tkplace(tk2label(frameA2, text = "Size"), x = 11, 
                y = 40, `in` = frameA2)
            entryA2 <- tk2entry(frameA2, textvariable = local.points.label.cex.var[[WhichGroup]], 
                justify = "right", takefocus = FALSE)
            tkplace(entryA2, relx = 0.95, y = 40, height = 18, 
                relwidth = 0.125, `in` = frameA2, anchor = "ne")
            tkplace(tk2label(frameA2, text = "Colour"), x = 11, 
                y = 60, `in` = frameA2)
            labelA3 <- tklabel(frameA2, background = local.points.label.col.var[[WhichGroup]], 
                relief = "groove", borderwidth = "1.5p")
            tkplace(labelA3, relx = 0.95, y = 60, height = 18, 
                relwidth = 0.125, `in` = frameA2, anchor = "ne")
            tkbind(labelA3, "<Button-1>", function() {
                temp1 <- tkchooseColor(initialcolor = local.points.label.col.var[[WhichGroup]])
                if (!(tclvalue(temp1) == "")) {
                  temp1 <- tclvalue(temp1)
                  local.points.label.col.var[[WhichGroup]] <<- temp1
                  tkconfigure(labelA3, background = local.points.label.col.var[[WhichGroup]])
                  if (WhichGroup == 1) 
                    for (temp1 in 2:(g + 1)) local.points.label.col.var[[temp1]] <<- local.points.label.col.var[[1]]
                }
            })
            tkplace(tk2label(frameA2, text = "Horizontal offset"), 
                x = 11, y = 80, `in` = frameA2)
            entryA3 <- tk2entry(frameA2, textvariable = local.points.label.HorizOffset.var[[WhichGroup]], 
                justify = "right", takefocus = FALSE)
            tkplace(entryA3, relx = 0.95, y = 80, height = 18, 
                relwidth = 0.125, `in` = frameA2, anchor = "ne")
            tkplace(tk2label(frameA2, text = "Vertical offset"), 
                x = 11, y = 100, `in` = frameA2)
            entryA4 <- tk2entry(frameA2, textvariable = local.points.label.VertOffset.var[[WhichGroup]], 
                justify = "right", takefocus = FALSE)
            tkplace(entryA4, relx = 0.95, y = 100, height = 18, 
                relwidth = 0.125, `in` = frameA2, anchor = "ne")
            notebook.B <- tk2frame(notebook)
            tkadd(notebook, notebook.B, text = "Sample group means")
            frameB1 <- tkwidget(notebook.B, "TitleFrame", text = "Plotting character")
            tkplace(frameB1, relx = 0.05, relwidth = 0.9, y = 10, 
                height = 105, `in` = notebook.B)
            tkplace(tk2label(frameB1, text = "Symbol"), x = 11, 
                y = 20, `in` = frameB1)
            spinboxB1 <- tkwidget(frameB1, "SpinBox", textvariable = local.SampleGroupMeans.pch.var[[WhichGroup]], 
                editable = FALSE, values = c(" ", "NA", 0:25), 
                justify = "right", modifycmd = function() {
                  if (WhichGroup == 1 && tclvalue(local.SampleGroupMeans.pch.var[[1]]) != 
                    " ") 
                    for (temp1 in 2:(g + 1)) local.SampleGroupMeans.pch.var[[temp1]] <<- tclVar(tclvalue(local.SampleGroupMeans.pch.var[[1]]))
                })
            tkplace(spinboxB1, relx = 0.95, y = 20, height = 18, 
                relwidth = 0.125, `in` = frameB1, anchor = "ne")
            tkplace(tk2label(frameB1, text = "Size"), x = 11, 
                y = 40, `in` = frameB1)
            entryB1 <- tk2entry(frameB1, textvariable = local.SampleGroupMeans.cex.var[[WhichGroup]], 
                justify = "right", takefocus = FALSE)
            tkplace(entryB1, relx = 0.95, y = 40, height = 18, 
                relwidth = 0.125, `in` = frameB1, anchor = "ne")
            tkplace(tk2label(frameB1, text = "Foreground colour"), 
                x = 11, y = 60, `in` = frameB1)
            labelB1 <- tklabel(frameB1, background = local.SampleGroupMeans.col.fg.var[[WhichGroup]], 
                relief = "groove", borderwidth = "1.5p")
            tkplace(labelB1, relx = 0.95, y = 60, height = 18, 
                relwidth = 0.125, `in` = frameB1, anchor = "ne")
            tkbind(labelB1, "<Button-1>", function() {
                temp1 <- tkchooseColor(initialcolor = local.SampleGroupMeans.col.fg.var[[WhichGroup]])
                if (!(tclvalue(temp1) == "")) {
                  temp1 <- tclvalue(temp1)
                  local.SampleGroupMeans.col.fg.var[[WhichGroup]] <<- temp1
                  tkconfigure(labelB1, background = local.SampleGroupMeans.col.fg.var[[WhichGroup]])
                  if (WhichGroup == 1) 
                    for (temp1 in 2:(g + 1)) local.SampleGroupMeans.col.fg.var[[temp1]] <<- local.SampleGroupMeans.col.fg.var[[1]]
                }
            })
            tkplace(tk2label(frameB1, text = "Background colour"), 
                x = 11, y = 80, `in` = frameB1)
            labelB2 <- tklabel(frameB1, background = local.SampleGroupMeans.col.bg.var[[WhichGroup]], 
                relief = "groove", borderwidth = "1.5p")
            tkplace(labelB2, relx = 0.95, y = 80, height = 18, 
                relwidth = 0.125, `in` = frameB1, anchor = "ne")
            tkbind(labelB2, "<Button-1>", function() {
                temp1 <- tkchooseColor(initialcolor = local.SampleGroupMeans.col.bg.var[[WhichGroup]])
                if (!(tclvalue(temp1) == "")) {
                  temp1 <- tclvalue(temp1)
                  local.SampleGroupMeans.col.bg.var[[WhichGroup]] <<- temp1
                  tkconfigure(labelB2, background = local.SampleGroupMeans.col.bg.var[[WhichGroup]])
                  if (WhichGroup == 1) 
                    for (temp1 in 2:(g + 1)) local.SampleGroupMeans.col.bg.var[[temp1]] <<- local.SampleGroupMeans.col.bg.var[[1]]
                }
            })
            frameB2 <- tkwidget(notebook.B, "TitleFrame", text = "Label")
            tkplace(frameB2, relx = 0.05, relwidth = 0.9, y = 130, 
                height = 125, `in` = notebook.B)
            tkplace(tk2label(frameB2, text = "Font"), x = 11, 
                y = 20, `in` = frameB2)
            spinboxB2 <- tkwidget(frameB2, "SpinBox", textvariable = local.SampleGroupMeans.label.font.var[[WhichGroup]], 
                editable = FALSE, values = c(" ", 1:4), justify = "right", 
                modifycmd = function() {
                  if (WhichGroup == 1 && tclvalue(local.SampleGroupMeans.label.font.var[[1]]) != 
                    " ") 
                    for (temp1 in 2:(g + 1)) local.SampleGroupMeans.label.font.var[[temp1]] <<- tclVar(tclvalue(local.SampleGroupMeans.label.font.var[[1]]))
                })
            tkplace(spinboxB2, relx = 0.95, y = 20, height = 18, 
                relwidth = 0.125, `in` = frameB2, anchor = "ne")
            tkplace(tk2label(frameB2, text = "Size"), x = 11, 
                y = 40, `in` = frameB2)
            entryB2 <- tk2entry(frameB2, textvariable = local.SampleGroupMeans.label.cex.var[[WhichGroup]], 
                justify = "right", takefocus = FALSE)
            tkplace(entryB2, relx = 0.95, y = 40, height = 18, 
                relwidth = 0.125, `in` = frameB2, anchor = "ne")
            tkplace(tk2label(frameB2, text = "Colour"), x = 11, 
                y = 60, `in` = frameB2)
            labelB3 <- tklabel(frameB2, background = local.SampleGroupMeans.label.col.var[[WhichGroup]], 
                relief = "groove", borderwidth = "1.5p")
            tkplace(labelB3, relx = 0.95, y = 60, height = 18, 
                relwidth = 0.125, `in` = frameB2, anchor = "ne")
            tkbind(labelB3, "<Button-1>", function() {
                temp1 <- tkchooseColor(initialcolor = local.SampleGroupMeans.label.col.var[[WhichGroup]])
                if (!(tclvalue(temp1) == "")) {
                  temp1 <- tclvalue(temp1)
                  local.SampleGroupMeans.label.col.var[[WhichGroup]] <<- temp1
                  tkconfigure(labelB3, background = local.SampleGroupMeans.label.col.var[[WhichGroup]])
                  if (WhichGroup == 1) 
                    for (temp1 in 2:(g + 1)) local.SampleGroupMeans.label.col.var[[temp1]] <<- local.SampleGroupMeans.label.col.var[[1]]
                }
            })
            tkplace(tk2label(frameB2, text = "Horizontal offset"), 
                x = 11, y = 80, `in` = frameB2)
            entryB3 <- tk2entry(frameB2, textvariable = local.SampleGroupMeans.label.HorizOffset.var[[WhichGroup]], 
                justify = "right", takefocus = FALSE)
            tkplace(entryB3, relx = 0.95, y = 80, height = 18, 
                relwidth = 0.125, `in` = frameB2, anchor = "ne")
            tkplace(tk2label(frameB2, text = "Vertical offset"), 
                x = 11, y = 100, `in` = frameB2)
            entryB4 <- tk2entry(frameB2, textvariable = local.SampleGroupMeans.label.VertOffset.var[[WhichGroup]], 
                justify = "right", takefocus = FALSE)
            tkplace(entryB4, relx = 0.95, y = 100, height = 18, 
                relwidth = 0.125, `in` = frameB2, anchor = "ne")
            notebook.C <- tk2frame(notebook)
            tkadd(notebook, notebook.C, text = "Convex hulls / Alpha-bags")
            frameC1 <- tkwidget(notebook.C, "TitleFrame", text = "Region")
            tkplace(frameC1, relx = 0.05, relwidth = 0.9, y = 10, 
                height = 105, `in` = notebook.C)
            tkplace(tk2label(frameC1, text = "Line type"), x = 11, 
                y = 20, `in` = frameC1)
            spinboxC1 <- tkwidget(frameC1, "SpinBox", textvariable = local.ConvexHullAlphaBag.lty.var[[WhichGroup]], 
                editable = FALSE, values = c(" ", 0:6), justify = "right", 
                modifycmd = function() {
                  if (WhichGroup == 1 && tclvalue(local.ConvexHullAlphaBag.lty.var[[1]]) != 
                    " ") 
                    for (temp1 in 2:(g + 1)) local.ConvexHullAlphaBag.lty.var[[temp1]] <<- tclVar(tclvalue(local.ConvexHullAlphaBag.lty.var[[1]]))
                })
            tkplace(spinboxC1, relx = 0.95, y = 20, height = 18, 
                relwidth = 0.125, `in` = frameC1, anchor = "ne")
            tkplace(tk2label(frameC1, text = "Line width"), x = 11, 
                y = 40, `in` = frameC1)
            entryC1 <- tk2entry(frameC1, textvariable = local.ConvexHullAlphaBag.lwd.var[[WhichGroup]], 
                justify = "right", takefocus = FALSE)
            tkplace(entryC1, relx = 0.95, y = 40, height = 18, 
                relwidth = 0.125, `in` = frameC1, anchor = "ne")
            tkplace(tk2label(frameC1, text = "Foreground colour"), 
                x = 11, y = 60, `in` = frameC1)
            labelC1 <- tklabel(frameC1, background = local.ConvexHullAlphaBag.col.fg.var[[WhichGroup]], 
                relief = "groove", borderwidth = "1.5p")
            tkplace(labelC1, relx = 0.95, y = 60, height = 18, 
                relwidth = 0.125, `in` = frameC1, anchor = "ne")
            tkbind(labelC1, "<Button-1>", function() {
                temp1 <- tkchooseColor(initialcolor = local.ConvexHullAlphaBag.col.fg.var[[WhichGroup]])
                if (!(tclvalue(temp1) == "")) {
                  temp1 <- tclvalue(temp1)
                  local.ConvexHullAlphaBag.col.fg.var[[WhichGroup]] <<- temp1
                  tkconfigure(labelC1, background = local.ConvexHullAlphaBag.col.fg.var[[WhichGroup]])
                  if (WhichGroup == 1) 
                    for (temp1 in 2:(g + 1)) local.ConvexHullAlphaBag.col.fg.var[[temp1]] <<- local.ConvexHullAlphaBag.col.fg.var[[1]]
                }
            })
            tkplace(tk2label(frameC1, text = "Background colour"), 
                x = 11, y = 80, `in` = frameC1)
            labelC2 <- tklabel(frameC1, background = local.ConvexHullAlphaBag.col.bg.var[[WhichGroup]], 
                relief = "groove", borderwidth = "1.5p")
            tkplace(labelC2, relx = 0.95, y = 80, height = 18, 
                relwidth = 0.125, `in` = frameC1, anchor = "ne")
            tkbind(labelC2, "<Button-1>", function() {
                temp1 <- tkchooseColor(initialcolor = local.ConvexHullAlphaBag.col.bg.var[[WhichGroup]])
                if (!(tclvalue(temp1) == "")) {
                  temp1 <- tclvalue(temp1)
                  local.ConvexHullAlphaBag.col.bg.var[[WhichGroup]] <<- temp1
                  tkconfigure(labelC2, background = local.ConvexHullAlphaBag.col.bg.var[[WhichGroup]])
                  if (WhichGroup == 1) 
                    for (temp1 in 2:(g + 1)) local.ConvexHullAlphaBag.col.bg.var[[temp1]] <<- local.ConvexHullAlphaBag.col.bg.var[[1]]
                }
            })
            frameC2 <- tkwidget(notebook.C, "TitleFrame", text = "Tukey median: plotting character")
            tkplace(frameC2, relx = 0.05, relwidth = 0.9, y = 130, 
                height = 105, `in` = notebook.C)
            tkplace(tk2label(frameC2, text = "Symbol"), x = 11, 
                y = 20, `in` = frameC2)
            spinboxC2 <- tkwidget(frameC2, "SpinBox", textvariable = local.ConvexHullAlphaBag.TukeyMedian.pch.var[[WhichGroup]], 
                editable = FALSE, values = c(" ", "NA", 0:25), 
                justify = "right", modifycmd = function() {
                  if (WhichGroup == 1 && tclvalue(local.ConvexHullAlphaBag.TukeyMedian.pch.var[[1]]) != 
                    " ") 
                    for (temp1 in 2:(g + 1)) local.ConvexHullAlphaBag.TukeyMedian.pch.var[[temp1]] <<- tclVar(tclvalue(local.ConvexHullAlphaBag.TukeyMedian.pch.var[[1]]))
                })
            tkplace(spinboxC2, relx = 0.95, y = 20, height = 18, 
                relwidth = 0.125, `in` = frameC2, anchor = "ne")
            tkplace(tk2label(frameC2, text = "Size"), x = 11, 
                y = 40, `in` = frameC2)
            entryC2 <- tk2entry(frameC2, textvariable = local.ConvexHullAlphaBag.TukeyMedian.cex.var[[WhichGroup]], 
                justify = "right", takefocus = FALSE)
            tkplace(entryC2, relx = 0.95, y = 40, height = 18, 
                relwidth = 0.125, `in` = frameC2, anchor = "ne")
            tkplace(tk2label(frameC2, text = "Foreground colour"), 
                x = 11, y = 60, `in` = frameC2)
            labelC3 <- tklabel(frameC2, background = local.ConvexHullAlphaBag.TukeyMedian.col.fg.var[[WhichGroup]], 
                relief = "groove", borderwidth = "1.5p")
            tkplace(labelC3, relx = 0.95, y = 60, height = 18, 
                relwidth = 0.125, `in` = frameC2, anchor = "ne")
            tkbind(labelC3, "<Button-1>", function() {
                temp1 <- tkchooseColor(initialcolor = local.ConvexHullAlphaBag.TukeyMedian.col.fg.var[[WhichGroup]])
                if (!(tclvalue(temp1) == "")) {
                  temp1 <- tclvalue(temp1)
                  local.ConvexHullAlphaBag.TukeyMedian.col.fg.var[[WhichGroup]] <<- temp1
                  tkconfigure(labelC3, background = local.ConvexHullAlphaBag.TukeyMedian.col.fg.var[[WhichGroup]])
                  if (WhichGroup == 1) 
                    for (temp1 in 2:(g + 1)) local.ConvexHullAlphaBag.TukeyMedian.col.fg.var[[temp1]] <<- local.ConvexHullAlphaBag.TukeyMedian.col.fg.var[[1]]
                }
            })
            tkplace(tk2label(frameC2, text = "Background colour"), 
                x = 11, y = 80, `in` = frameC2)
            labelC4 <- tklabel(frameC2, background = local.ConvexHullAlphaBag.TukeyMedian.col.bg.var[[WhichGroup]], 
                relief = "groove", borderwidth = "1.5p")
            tkplace(labelC4, relx = 0.95, y = 80, height = 18, 
                relwidth = 0.125, `in` = frameC2, anchor = "ne")
            tkbind(labelC4, "<Button-1>", function() {
                temp1 <- tkchooseColor(initialcolor = local.ConvexHullAlphaBag.TukeyMedian.col.bg.var[[WhichGroup]])
                if (!(tclvalue(temp1) == "")) {
                  temp1 <- tclvalue(temp1)
                  local.ConvexHullAlphaBag.TukeyMedian.col.bg.var[[WhichGroup]] <<- temp1
                  tkconfigure(labelC4, background = local.ConvexHullAlphaBag.TukeyMedian.col.bg.var[[WhichGroup]])
                  if (WhichGroup == 1) 
                    for (temp1 in 2:(g + 1)) local.ConvexHullAlphaBag.TukeyMedian.col.bg.var[[temp1]] <<- local.ConvexHullAlphaBag.TukeyMedian.col.bg.var[[1]]
                }
            })
            frameC3 <- tkwidget(notebook.C, "TitleFrame", text = "Tukey median: label")
            tkplace(frameC3, relx = 0.05, relwidth = 0.9, y = 250, 
                height = 125, `in` = notebook.C)
            tkplace(tk2label(frameC3, text = "Font"), x = 11, 
                y = 20, `in` = frameC3)
            spinboxC3 <- tkwidget(frameC3, "SpinBox", textvariable = local.ConvexHullAlphaBag.TukeyMedian.label.font.var[[WhichGroup]], 
                editable = FALSE, values = c(" ", 1:4), justify = "right", 
                modifycmd = function() {
                  if (WhichGroup == 1 && tclvalue(local.ConvexHullAlphaBag.TukeyMedian.label.font.var[[1]]) != 
                    " ") 
                    for (temp1 in 2:(g + 1)) local.ConvexHullAlphaBag.TukeyMedian.label.font.var[[temp1]] <<- tclVar(tclvalue(local.ConvexHullAlphaBag.TukeyMedian.label.font.var[[1]]))
                })
            tkplace(spinboxC3, relx = 0.95, y = 20, height = 18, 
                relwidth = 0.125, `in` = frameC3, anchor = "ne")
            tkplace(tk2label(frameC3, text = "Size"), x = 11, 
                y = 40, `in` = frameC3)
            entryC3 <- tk2entry(frameC3, textvariable = local.ConvexHullAlphaBag.TukeyMedian.label.cex.var[[WhichGroup]], 
                justify = "right", takefocus = FALSE)
            tkplace(entryC3, relx = 0.95, y = 40, height = 18, 
                relwidth = 0.125, `in` = frameC3, anchor = "ne")
            tkplace(tk2label(frameC3, text = "Colour"), x = 11, 
                y = 60, `in` = frameC3)
            labelC5 <- tklabel(frameC3, background = local.ConvexHullAlphaBag.TukeyMedian.label.col.var[[WhichGroup]], 
                relief = "groove", borderwidth = "1.5p")
            tkplace(labelC5, relx = 0.95, y = 60, height = 18, 
                relwidth = 0.125, `in` = frameC3, anchor = "ne")
            tkbind(labelC5, "<Button-1>", function() {
                temp1 <- tkchooseColor(initialcolor = local.ConvexHullAlphaBag.TukeyMedian.label.col.var[[WhichGroup]])
                if (!(tclvalue(temp1) == "")) {
                  temp1 <- tclvalue(temp1)
                  local.ConvexHullAlphaBag.TukeyMedian.label.col.var[[WhichGroup]] <<- temp1
                  tkconfigure(labelC5, background = local.ConvexHullAlphaBag.TukeyMedian.label.col.var[[WhichGroup]])
                  if (WhichGroup == 1) 
                    for (temp1 in 2:(g + 1)) local.ConvexHullAlphaBag.TukeyMedian.label.col.var[[temp1]] <<- local.ConvexHullAlphaBag.TukeyMedian.label.col.var[[1]]
                }
            })
            tkplace(tk2label(frameC3, text = "Horizontal offset"), 
                x = 11, y = 80, `in` = frameC3)
            entryC4 <- tk2entry(frameC3, textvariable = local.ConvexHullAlphaBag.TukeyMedian.label.HorizOffset.var[[WhichGroup]], 
                justify = "right", takefocus = FALSE)
            tkplace(entryC4, relx = 0.95, y = 80, height = 18, 
                relwidth = 0.125, `in` = frameC3, anchor = "ne")
            tkplace(tk2label(frameC3, text = "Vertical offset"), 
                x = 11, y = 100, `in` = frameC3)
            entryC5 <- tk2entry(frameC3, textvariable = local.ConvexHullAlphaBag.TukeyMedian.label.VertOffset.var[[WhichGroup]], 
                justify = "right", takefocus = FALSE)
            tkplace(entryC5, relx = 0.95, y = 100, height = 18, 
                relwidth = 0.125, `in` = frameC3, anchor = "ne")
            notebook.D <- tk2frame(notebook)
            tkadd(notebook, notebook.D, text = "Classification regions")
            frameD1 <- tkwidget(notebook.D, "TitleFrame", text = "Region")
            tkplace(frameD1, relx = 0.05, relwidth = 0.9, y = 10, 
                height = 45, `in` = notebook.D)
            tkplace(tk2label(frameD1, text = "Background colour"), 
                x = 11, y = 20, `in` = frameD1)
            labelD1 <- tklabel(frameD1, background = local.ClassificationRegion.col.bg.var[[WhichGroup]], 
                relief = "groove", borderwidth = "1.5p")
            tkplace(labelD1, relx = 0.95, y = 20, height = 18, 
                relwidth = 0.125, `in` = frameD1, anchor = "ne")
            tkbind(labelD1, "<Button-1>", function() {
                temp1 <- tkchooseColor(initialcolor = local.ClassificationRegion.col.bg.var[[WhichGroup]])
                if (!(tclvalue(temp1) == "")) {
                  temp1 <- tclvalue(temp1)
                  local.ClassificationRegion.col.bg.var[[WhichGroup]] <<- temp1
                  tkconfigure(labelD1, background = local.ClassificationRegion.col.bg.var[[WhichGroup]])
                  if (WhichGroup == 1) 
                    for (temp1 in 2:(g + 1)) local.ClassificationRegion.col.bg.var[[temp1]] <<- local.ClassificationRegion.col.bg.var[[1]]
                }
            })
            tkplace(listbox1, relx = 0.05, rely = 0.49, relwidth = 0.23, 
                relheight = 0.88, `in` = top, anchor = "w")
            tkplace(listbox1.scry, relx = 1, relheight = 1, `in` = listbox1, 
                anchor = "ne")
            tkplace(notebook, relx = 0.3, rely = 0.05, relwidth = 0.67, 
                relheight = 0.88, `in` = top)
            tkselect(notebook, WhichTabInitially - 1)
            button1 <- tk2button(top, text = "OK", width = 10, 
                command = onOK)
            button2 <- tk2button(top, text = "Cancel", width = 10, 
                command = onCancel)
            button3 <- tk2button(top, text = "Defaults", width = 10, 
                command = onDefaults)
            tkplace(button1, relx = 0.84, rely = 0.99, anchor = "se")
            tkplace(button2, relx = 0.965, rely = 0.99, anchor = "se")
            tkplace(button3, relx = 0.05, rely = 0.99, anchor = "sw")
            tkbind(listbox1, "<<ListboxSelect>>", ChangeGroup)
            tkbind(top, "<Escape>", onCancel)
            tkbind(top, "<Destroy>", function() {
                tkgrab.release(top)
                tkfocus(ReturnToWindow)
            })
            tkwm.focusmodel(top, "active")
            tkwm.geometry(top, paste("640x475", "+", round(GUI.AvailableScreenWidth/2 - 
                640/2, 0), "+", round(GUI.AvailableScreenHeight/2 - 
                475/2, 0), sep = ""))
            tkwm.resizable(top, "0", "0")
            tkwm.deiconify(top)
            tkwm.title(top, "By group")
            tkgrab.set(top)
            Rico <- tk2ico.load(res = "question")
            tk2ico.set(top, Rico)
            tk2ico.destroy(Rico)
            rm(Rico)
            tkfocus(top)
            tkwait.window(top)
        }
        local.GUI.func()
    }
    Format.Axes.cmd <- function(WhichAxisInitially = 1) {
        local.GUI.func <- function() {
            ReturnToWindow <- tkfocus()
            top <- tktoplevel()
            tkwm.withdraw(top)
            WhichAxis <- WhichAxisInitially
            UpdateEntryBoxes <- function() {
                if (WhichAxis == 1 && tclvalue(local.axes.lwd.var[[1]]) != 
                  " ") 
                  for (temp1 in 2:(p + 1)) local.axes.lwd.var[[temp1]] <<- tclVar(tclvalue(local.axes.lwd.var[[1]]))
                if (WhichAxis == 1 && tclvalue(local.axes.tick.n.var[[1]]) != 
                  " ") 
                  for (temp1 in 2:(p + 1)) local.axes.tick.n.var[[temp1]] <<- tclVar(tclvalue(local.axes.tick.n.var[[1]]))
                if (WhichAxis == 1 && tclvalue(local.axes.tick.lwd.var[[1]]) != 
                  " ") 
                  for (temp1 in 2:(p + 1)) local.axes.tick.lwd.var[[temp1]] <<- tclVar(tclvalue(local.axes.tick.lwd.var[[1]]))
                if (WhichAxis == 1 && tclvalue(local.axes.tick.RelLength.var[[1]]) != 
                  " ") 
                  for (temp1 in 2:(p + 1)) local.axes.tick.RelLength.var[[temp1]] <<- tclVar(tclvalue(local.axes.tick.RelLength.var[[1]]))
                if (WhichAxis == 1 && tclvalue(local.axes.marker.cex.var[[1]]) != 
                  " ") 
                  for (temp1 in 2:(p + 1)) local.axes.marker.cex.var[[temp1]] <<- tclVar(tclvalue(local.axes.marker.cex.var[[1]]))
                if (WhichAxis == 1 && tclvalue(local.axes.marker.RelOffset.var[[1]]) != 
                  " ") 
                  for (temp1 in 2:(p + 1)) local.axes.marker.RelOffset.var[[temp1]] <<- tclVar(tclvalue(local.axes.marker.RelOffset.var[[1]]))
                if (WhichAxis == 1 && tclvalue(local.axes.label.cex.var[[1]]) != 
                  " ") 
                  for (temp1 in 2:(p + 1)) local.axes.label.cex.var[[temp1]] <<- tclVar(tclvalue(local.axes.label.cex.var[[1]]))
            }
            ChangeGroup <- function() {
                UpdateEntryBoxes()
                temp <- as.numeric(tclvalue(tkcurselection(listbox1))) + 
                  1
                if (!is.na(temp)) 
                  WhichAxis <<- temp
                local.axes.lty.var[[1]] <<- if (all(unlist(lapply(local.axes.lty.var[-1], 
                  tclvalue)) == tclvalue(local.axes.lty.var[[2]]))) 
                  local.axes.lty.var[[2]]
                else tclVar(" ")
                tkconfigure(spinboxA1, textvariable = local.axes.lty.var[[WhichAxis]])
                local.axes.lwd.var[[1]] <<- if (all(unlist(lapply(local.axes.lwd.var[-1], 
                  tclvalue)) == tclvalue(local.axes.lwd.var[[2]]))) 
                  local.axes.lwd.var[[2]]
                else tclVar(" ")
                tkconfigure(entryA1, textvariable = local.axes.lwd.var[[WhichAxis]])
                local.axes.col.var[[1]] <<- if (all(unlist(local.axes.col.var[-1]) == 
                  local.axes.col.var[[2]])) 
                  local.axes.col.var[[2]]
                else text2hex("SystemButtonFace")
                tkconfigure(labelA1, background = local.axes.col.var[[WhichAxis]])
                local.axes.tick.n.var[[1]] <<- if (all(unlist(lapply(local.axes.tick.n.var[-1], 
                  tclvalue)) == tclvalue(local.axes.tick.n.var[[2]]))) 
                  local.axes.tick.n.var[[2]]
                else tclVar(" ")
                tkconfigure(entryA2, textvariable = local.axes.tick.n.var[[WhichAxis]])
                local.axes.tick.lty.var[[1]] <<- if (all(unlist(lapply(local.axes.tick.lty.var[-1], 
                  tclvalue)) == tclvalue(local.axes.tick.lty.var[[2]]))) 
                  local.axes.tick.lty.var[[2]]
                else tclVar(" ")
                tkconfigure(spinboxA2, textvariable = local.axes.tick.lty.var[[WhichAxis]])
                local.axes.tick.lwd.var[[1]] <<- if (all(unlist(lapply(local.axes.tick.lwd.var[-1], 
                  tclvalue)) == tclvalue(local.axes.tick.lwd.var[[2]]))) 
                  local.axes.tick.lwd.var[[2]]
                else tclVar(" ")
                tkconfigure(entryA3, textvariable = local.axes.tick.lwd.var[[WhichAxis]])
                local.axes.tick.col.var[[1]] <<- if (all(unlist(local.axes.tick.col.var[-1]) == 
                  local.axes.tick.col.var[[2]])) 
                  local.axes.tick.col.var[[2]]
                else text2hex("SystemButtonFace")
                tkconfigure(labelA2, background = local.axes.tick.col.var[[WhichAxis]])
                local.axes.tick.RelLength.var[[1]] <<- if (all(unlist(lapply(local.axes.tick.RelLength.var[-1], 
                  tclvalue)) == tclvalue(local.axes.tick.RelLength.var[[2]]))) 
                  local.axes.tick.RelLength.var[[2]]
                else tclVar(" ")
                tkconfigure(entryA4, textvariable = local.axes.tick.RelLength.var[[WhichAxis]])
                local.axes.marker.font.var[[1]] <<- if (all(unlist(lapply(local.axes.marker.font.var[-1], 
                  tclvalue)) == tclvalue(local.axes.marker.font.var[[2]]))) 
                  local.axes.marker.font.var[[2]]
                else tclVar(" ")
                tkconfigure(spinboxA3, textvariable = local.axes.marker.font.var[[WhichAxis]])
                local.axes.marker.cex.var[[1]] <<- if (all(unlist(lapply(local.axes.marker.cex.var[-1], 
                  tclvalue)) == tclvalue(local.axes.marker.cex.var[[2]]))) 
                  local.axes.marker.cex.var[[2]]
                else tclVar(" ")
                tkconfigure(entryA5, textvariable = local.axes.marker.cex.var[[WhichAxis]])
                local.axes.marker.col.var[[1]] <<- if (all(unlist(local.axes.marker.col.var[-1]) == 
                  local.axes.marker.col.var[[2]])) 
                  local.axes.marker.col.var[[2]]
                else text2hex("SystemButtonFace")
                tkconfigure(labelA3, background = local.axes.marker.col.var[[WhichAxis]])
                local.axes.marker.RelOffset.var[[1]] <<- if (all(unlist(lapply(local.axes.marker.RelOffset.var[-1], 
                  tclvalue)) == tclvalue(local.axes.marker.RelOffset.var[[2]]))) 
                  local.axes.marker.RelOffset.var[[2]]
                else tclVar(" ")
                tkconfigure(entryA6, textvariable = local.axes.marker.RelOffset.var[[WhichAxis]])
                local.axes.label.font.var[[1]] <<- if (all(unlist(lapply(local.axes.label.font.var[-1], 
                  tclvalue)) == tclvalue(local.axes.label.font.var[[2]]))) 
                  local.axes.label.font.var[[2]]
                else tclVar(" ")
                tkconfigure(spinboxA4, textvariable = local.axes.label.font.var[[WhichAxis]])
                local.axes.label.cex.var[[1]] <<- if (all(unlist(lapply(local.axes.label.cex.var[-1], 
                  tclvalue)) == tclvalue(local.axes.label.cex.var[[2]]))) 
                  local.axes.label.cex.var[[2]]
                else tclVar(" ")
                tkconfigure(entryA7, textvariable = local.axes.label.cex.var[[WhichAxis]])
                local.axes.label.las.var[[1]] <<- if (all(unlist(lapply(local.axes.label.las.var[-1], 
                  tclvalue)) == tclvalue(local.axes.label.las.var[[2]]))) 
                  local.axes.label.las.var[[2]]
                else tclVar(" ")
                tkconfigure(spinboxA5, textvariable = local.axes.label.las.var[[WhichAxis]])
                local.axes.label.col.var[[1]] <<- if (all(unlist(local.axes.label.col.var[-1]) == 
                  local.axes.label.col.var[[2]])) 
                  local.axes.label.col.var[[2]]
                else text2hex("SystemButtonFace")
                tkconfigure(labelA4, background = local.axes.label.col.var[[WhichAxis]])
            }
            onDefaults <- function() {
                bpar.initialise2.func()
                initialise()
                ChangeGroup()
            }
            onOK <- function() {
                UpdateEntryBoxes()
                bpar$axes.lty <<- as.numeric(lapply(local.axes.lty.var[-1], 
                  tclvalue))
                bpar$axes.lwd <<- as.numeric(lapply(local.axes.lwd.var[-1], 
                  tclvalue))
                bpar$axes.col <<- unlist(local.axes.col.var[-1])
                bpar$axes.tick.n <<- as.numeric(lapply(local.axes.tick.n.var[-1], 
                  tclvalue))
                bpar$axes.tick.lty <<- as.numeric(lapply(local.axes.tick.lty.var[-1], 
                  tclvalue))
                bpar$axes.tick.lwd <<- as.numeric(lapply(local.axes.tick.lwd.var[-1], 
                  tclvalue))
                bpar$axes.tick.col <<- unlist(local.axes.tick.col.var[-1])
                bpar$axes.tick.RelLength <<- as.numeric(lapply(local.axes.tick.RelLength.var[-1], 
                  tclvalue))
                bpar$axes.marker.font <<- as.numeric(lapply(local.axes.marker.font.var[-1], 
                  tclvalue))
                bpar$axes.marker.cex <<- as.numeric(lapply(local.axes.marker.cex.var[-1], 
                  tclvalue))
                bpar$axes.marker.col <<- unlist(local.axes.marker.col.var[-1])
                bpar$axes.marker.RelOffset <<- as.numeric(lapply(local.axes.marker.RelOffset.var[-1], 
                  tclvalue))
                bpar$axes.label.font <<- as.numeric(lapply(local.axes.label.font.var[-1], 
                  tclvalue))
                bpar$axes.label.cex <<- as.numeric(lapply(local.axes.label.cex.var[-1], 
                  tclvalue))
                bpar$axes.label.las <<- as.numeric(lapply(local.axes.label.las.var[-1], 
                  tclvalue))
                bpar$axes.label.col <<- unlist(local.axes.label.col.var[-1])
                Biplot.replot()
                if (tclvalue(Biplot.Axes.var) %in% c("0", "2")) 
                  AxesTab.replot()
                if (p.in < p) 
                  Kraal.replot()
                tkdestroy(top)
            }
            onCancel <- function() tkdestroy(top)
            local.axes.lty.var <- NULL
            local.axes.lwd.var <- NULL
            local.axes.col.var <- NULL
            local.axes.tick.n.var <- NULL
            local.axes.tick.lty.var <- NULL
            local.axes.tick.lwd.var <- NULL
            local.axes.tick.col.var <- NULL
            local.axes.tick.RelLength.var <- NULL
            local.axes.marker.font.var <- NULL
            local.axes.marker.cex.var <- NULL
            local.axes.marker.col.var <- NULL
            local.axes.marker.RelOffset.var <- NULL
            local.axes.label.font.var <- NULL
            local.axes.label.cex.var <- NULL
            local.axes.label.las.var <- NULL
            local.axes.label.col.var <- NULL
            initialise <- function() {
                local.axes.lty.var <<- lapply(c(if (identical(bpar$axes.lty, 
                  rep(bpar$axes.lty[1], p))) bpar$axes.lty[1] else " ", 
                  as.character(bpar$axes.lty)), tclVar)
                local.axes.lwd.var <<- lapply(c(if (identical(bpar$axes.lwd, 
                  rep(bpar$axes.lwd[1], p))) bpar$axes.lwd[1] else " ", 
                  as.character(bpar$axes.lwd)), tclVar)
                local.axes.col.var <<- lapply(c(if (identical(bpar$axes.col, 
                  rep(bpar$axes.col[1], p))) bpar$axes.col[1] else "SystemButtonFace", 
                  as.character(bpar$axes.col)), text2hex)
                local.axes.tick.n.var <<- lapply(c(if (identical(bpar$axes.tick.n, 
                  rep(bpar$axes.tick.n[1], p))) bpar$axes.tick.n[1] else " ", 
                  as.character(bpar$axes.tick.n)), tclVar)
                local.axes.tick.lty.var <<- lapply(c(if (identical(bpar$axes.tick.lty, 
                  rep(bpar$axes.tick.lty[1], p))) bpar$axes.tick.lty[1] else " ", 
                  as.character(bpar$axes.tick.lty)), tclVar)
                local.axes.tick.lwd.var <<- lapply(c(if (identical(bpar$axes.tick.lwd, 
                  rep(bpar$axes.tick.lwd[1], p))) bpar$axes.tick.lwd[1] else " ", 
                  as.character(bpar$axes.tick.lwd)), tclVar)
                local.axes.tick.col.var <<- lapply(c(if (identical(bpar$axes.tick.col, 
                  rep(bpar$axes.tick.col[1], p))) bpar$axes.tick.col[1] else "SystemButtonFace", 
                  as.character(bpar$axes.tick.col)), text2hex)
                local.axes.tick.RelLength.var <<- lapply(c(if (identical(bpar$axes.tick.RelLength, 
                  rep(bpar$axes.tick.RelLength[1], p))) bpar$axes.tick.RelLength[1] else " ", 
                  as.character(bpar$axes.tick.RelLength)), tclVar)
                local.axes.marker.font.var <<- lapply(c(if (identical(bpar$axes.marker.font, 
                  rep(bpar$axes.marker.font[1], p))) bpar$axes.marker.font[1] else " ", 
                  as.character(bpar$axes.marker.font)), tclVar)
                local.axes.marker.cex.var <<- lapply(c(if (identical(bpar$axes.marker.cex, 
                  rep(bpar$axes.marker.cex[1], p))) bpar$axes.marker.cex[1] else " ", 
                  as.character(bpar$axes.marker.cex)), tclVar)
                local.axes.marker.col.var <<- lapply(c(if (identical(bpar$axes.marker.col, 
                  rep(bpar$axes.marker.col[1], p))) bpar$axes.marker.col[1] else "SystemButtonFace", 
                  as.character(bpar$axes.marker.col)), text2hex)
                local.axes.marker.RelOffset.var <<- lapply(c(if (identical(bpar$axes.marker.RelOffset, 
                  rep(bpar$axes.marker.RelOffset[1], p))) bpar$axes.marker.RelOffset[1] else " ", 
                  as.character(bpar$axes.marker.RelOffset)), 
                  tclVar)
                local.axes.label.font.var <<- lapply(c(if (identical(bpar$axes.label.font, 
                  rep(bpar$axes.label.font[1], p))) bpar$axes.label.font[1] else " ", 
                  as.character(bpar$axes.label.font)), tclVar)
                local.axes.label.cex.var <<- lapply(c(if (identical(bpar$axes.label.cex, 
                  rep(bpar$axes.label.cex[1], p))) bpar$axes.label.cex[1] else " ", 
                  as.character(bpar$axes.label.cex)), tclVar)
                local.axes.label.las.var <<- lapply(c(if (identical(bpar$axes.label.las, 
                  rep(bpar$axes.label.las[1], p))) bpar$axes.label.las[1] else " ", 
                  as.character(bpar$axes.label.las)), tclVar)
                local.axes.label.col.var <<- lapply(c(if (identical(bpar$axes.label.col, 
                  rep(bpar$axes.label.col[1], p))) bpar$axes.label.col[1] else "SystemButtonFace", 
                  as.character(bpar$axes.label.col)), text2hex)
            }
            initialise()
            listbox1 <- tkwidget(top, "listbox", bg = "white", 
                relief = "groove", borderwidth = "1.5p", yscrollcommand = function(...) tkset(listbox1.scry, 
                  ...))
            listbox1.scry <- tkscrollbar(top, repeatinterval = 5, 
                command = function(...) tkyview(listbox1, ...))
            tkinsert(listbox1, "end", "All axes")
            if (p > 1) 
                for (i in bpar$axes.label.text) tkinsert(listbox1, 
                  "end", i)
            tkselect(listbox1, "set", WhichAxisInitially - 1)
            frameA <- tk2frame(top, relief = "groove", borderwidth = "1.5p")
            frameA1 <- tkwidget(top, "TitleFrame", text = "Axis")
            tkplace(frameA1, relx = 0.05, relwidth = 0.9, y = 10, 
                height = 85, `in` = frameA)
            tkplace(tk2label(frameA1, text = "Line type"), x = 11, 
                y = 20, `in` = frameA1)
            spinboxA1 <- tkwidget(frameA1, "SpinBox", textvariable = local.axes.lty.var[[WhichAxis]], 
                editable = FALSE, values = c(" ", 0:6), justify = "right", 
                modifycmd = function() {
                  if (WhichAxis == 1 && tclvalue(local.axes.lty.var[[1]]) != 
                    " ") 
                    for (temp1 in 2:(p + 1)) local.axes.lty.var[[temp1]] <<- tclVar(tclvalue(local.axes.lty.var[[1]]))
                })
            tkplace(spinboxA1, relx = 0.95, y = 20, height = 18, 
                relwidth = 0.125, `in` = frameA1, anchor = "ne")
            tkplace(tk2label(frameA1, text = "Line width"), x = 11, 
                y = 40, `in` = frameA1)
            entryA1 <- tk2entry(frameA1, textvariable = local.axes.lwd.var[[WhichAxis]], 
                justify = "right", takefocus = FALSE)
            tkplace(entryA1, relx = 0.95, y = 40, height = 18, 
                relwidth = 0.125, `in` = frameA1, anchor = "ne")
            tkplace(tk2label(frameA1, text = "Colour"), x = 11, 
                y = 60, `in` = frameA1)
            labelA1 <- tklabel(frameA1, background = local.axes.col.var[[WhichAxis]], 
                relief = "groove", borderwidth = "1.5p")
            tkplace(labelA1, relx = 0.95, y = 60, height = 18, 
                relwidth = 0.125, `in` = frameA1, anchor = "ne")
            tkbind(labelA1, "<Button-1>", function() {
                temp1 <- tkchooseColor(initialcolor = local.axes.col.var[[WhichAxis]])
                if (!(tclvalue(temp1) == "")) {
                  temp1 <- tclvalue(temp1)
                  local.axes.col.var[[WhichAxis]] <<- temp1
                  tkconfigure(labelA1, background = local.axes.col.var[[WhichAxis]])
                  if (WhichAxis == 1) 
                    for (temp1 in 2:(p + 1)) local.axes.col.var[[temp1]] <<- local.axes.col.var[[1]]
                }
            })
            frameA2 <- tkwidget(top, "TitleFrame", text = "Ticks")
            tkplace(frameA2, relx = 0.05, relwidth = 0.9, y = 105, 
                height = 125, `in` = frameA)
            tkplace(tk2label(frameA2, text = "Desired number"), 
                x = 11, y = 20, `in` = frameA2)
            entryA2 <- tk2entry(frameA2, textvariable = local.axes.tick.n.var[[WhichAxis]], 
                justify = "right", takefocus = FALSE)
            tkplace(entryA2, relx = 0.95, y = 20, height = 18, 
                relwidth = 0.125, `in` = frameA2, anchor = "ne")
            tkplace(tk2label(frameA2, text = "Line type"), x = 11, 
                y = 40, `in` = frameA2)
            spinboxA2 <- tkwidget(frameA2, "SpinBox", textvariable = local.axes.tick.lty.var[[WhichAxis]], 
                editable = FALSE, values = c(" ", 0:6), justify = "right", 
                modifycmd = function() {
                  if (WhichAxis == 1 && tclvalue(local.axes.tick.lty.var[[1]]) != 
                    " ") 
                    for (temp1 in 2:(p + 1)) local.axes.tick.lty.var[[temp1]] <<- tclVar(tclvalue(local.axes.tick.lty.var[[1]]))
                })
            tkplace(spinboxA2, relx = 0.95, y = 40, height = 18, 
                relwidth = 0.125, `in` = frameA2, anchor = "ne")
            tkplace(tk2label(frameA2, text = "Line width"), x = 11, 
                y = 60, `in` = frameA2)
            entryA3 <- tk2entry(frameA2, textvariable = local.axes.tick.lwd.var[[WhichAxis]], 
                justify = "right", takefocus = FALSE)
            tkplace(entryA3, relx = 0.95, y = 60, height = 18, 
                relwidth = 0.125, `in` = frameA2, anchor = "ne")
            tkplace(tk2label(frameA2, text = "Colour"), x = 11, 
                y = 80, `in` = frameA2)
            labelA2 <- tklabel(frameA2, background = local.axes.tick.col.var[[WhichAxis]], 
                relief = "groove", borderwidth = "1.5p")
            tkplace(labelA2, relx = 0.95, y = 80, height = 18, 
                relwidth = 0.125, `in` = frameA2, anchor = "ne")
            tkbind(labelA2, "<Button-1>", function() {
                temp1 <- tkchooseColor(initialcolor = local.axes.tick.col.var[[WhichAxis]])
                if (!(tclvalue(temp1) == "")) {
                  temp1 <- tclvalue(temp1)
                  local.axes.tick.col.var[[WhichAxis]] <<- temp1
                  tkconfigure(labelA2, background = local.axes.tick.col.var[[WhichAxis]])
                  if (WhichAxis == 1) 
                    for (temp1 in 2:(p + 1)) local.axes.tick.col.var[[temp1]] <<- local.axes.tick.col.var[[1]]
                }
            })
            tkplace(tk2label(frameA2, text = "Relative length"), 
                x = 11, y = 100, `in` = frameA2)
            entryA4 <- tk2entry(frameA2, textvariable = local.axes.tick.RelLength.var[[WhichAxis]], 
                justify = "right", takefocus = FALSE)
            tkplace(entryA4, relx = 0.95, y = 100, height = 18, 
                relwidth = 0.125, `in` = frameA2, anchor = "ne")
            frameA3 <- tkwidget(top, "TitleFrame", text = "Markers")
            tkplace(frameA3, relx = 0.05, relwidth = 0.9, y = 240, 
                height = 105, `in` = frameA)
            tkplace(tk2label(frameA3, text = "Font"), x = 11, 
                y = 20, `in` = frameA3)
            spinboxA3 <- tkwidget(frameA3, "SpinBox", textvariable = local.axes.marker.font.var[[WhichAxis]], 
                editable = FALSE, values = c(" ", 1:4), justify = "right", 
                modifycmd = function() {
                  if (WhichAxis == 1 && tclvalue(local.axes.marker.font.var[[1]]) != 
                    " ") 
                    for (temp1 in 2:(p + 1)) local.axes.marker.font.var[[temp1]] <<- tclVar(tclvalue(local.axes.marker.font.var[[1]]))
                })
            tkplace(spinboxA3, relx = 0.95, y = 20, height = 18, 
                relwidth = 0.125, `in` = frameA3, anchor = "ne")
            tkplace(tk2label(frameA3, text = "Size"), x = 11, 
                y = 40, `in` = frameA3)
            entryA5 <- tk2entry(frameA3, textvariable = local.axes.marker.cex.var[[WhichAxis]], 
                justify = "right", takefocus = FALSE)
            tkplace(entryA5, relx = 0.95, y = 40, height = 18, 
                relwidth = 0.125, `in` = frameA3, anchor = "ne")
            tkplace(tk2label(frameA3, text = "Colour"), x = 11, 
                y = 60, `in` = frameA3)
            labelA3 <- tklabel(frameA3, background = local.axes.marker.col.var[[WhichAxis]], 
                relief = "groove", borderwidth = "1.5p")
            tkplace(labelA3, relx = 0.95, y = 60, height = 18, 
                relwidth = 0.125, `in` = frameA3, anchor = "ne")
            tkbind(labelA3, "<Button-1>", function() {
                temp1 <- tkchooseColor(initialcolor = local.axes.marker.col.var[[WhichAxis]])
                if (!(tclvalue(temp1) == "")) {
                  temp1 <- tclvalue(temp1)
                  local.axes.marker.col.var[[WhichAxis]] <<- temp1
                  tkconfigure(labelA3, background = local.axes.marker.col.var[[WhichAxis]])
                  if (WhichAxis == 1) 
                    for (temp1 in 2:(p + 1)) local.axes.marker.col.var[[temp1]] <<- local.axes.marker.col.var[[1]]
                }
            })
            tkplace(tk2label(frameA3, text = "Relative offset"), 
                x = 11, y = 80, `in` = frameA3)
            entryA6 <- tk2entry(frameA3, textvariable = local.axes.marker.RelOffset.var[[WhichAxis]], 
                justify = "right", takefocus = FALSE)
            tkplace(entryA6, relx = 0.95, y = 80, height = 18, 
                relwidth = 0.125, `in` = frameA3, anchor = "ne")
            frameA4 <- tkwidget(top, "TitleFrame", text = "Label")
            tkplace(frameA4, relx = 0.05, relwidth = 0.9, y = 355, 
                height = 105, `in` = frameA)
            tkplace(tk2label(frameA4, text = "Font"), x = 11, 
                y = 20, `in` = frameA4)
            spinboxA4 <- tkwidget(frameA4, "SpinBox", textvariable = local.axes.label.font.var[[WhichAxis]], 
                editable = FALSE, values = c(" ", 1:4), justify = "right", 
                modifycmd = function() {
                  if (WhichAxis == 1 && tclvalue(local.axes.label.font.var[[1]]) != 
                    " ") 
                    for (temp1 in 2:(p + 1)) local.axes.label.font.var[[temp1]] <<- tclVar(tclvalue(local.axes.label.font.var[[1]]))
                })