lab <- paste(tax$Genus, tax$Species, sep = "_")#
lab <- sub("_\\>", "", lab) #
lab <- as.character(lab)#
Ythan$nodes$lab <- lab#
no.nodes <- length(lab)#
Ythan$nodes$size <- rep(1, no.nodes)#
Ythan$nodes$id <- 1:no.nodes
links <- read.csv("/Users/bryanhanson/Documents/Research/MetabolomicsProjects/ChemometricsStuff/BAHpackages/HiveR Misc/Food Web Networks/Unified Networks Chiu/ChiuWestveld-Modified/XYZ/ythan-y-cannibals.csv",#
	header = FALSE)#
links <- as.matrix(links)#
require(NetIndices)#
TL <- TrophInd(links)#
TL <- TL[,1]#
#
#
Ythan$nodes$radius <- TL
install.packages("NetIndices")
library("NetIndices")
TL <- TrophInd(links)#
TL <- TL[,1]#
#
#
Ythan$nodes$radius <- TL
isSymmetric(links)
dim(links)
pred <- prey <- both <- c()#
dm <- dim(links)[1] #
for (n in 1:dm) if (any(links[n,] == 1)) prey <- c(prey, n)#
for (n in 1:dm) if (any(links[,n] == 1)) pred <- c(pred, n)
length(pred)
length(prey)
both <- intersect(pred, prey)
length(both)
color <- rep(NA, no.nodes)#
color[pred] <- "red"#
color[prey] <- "blue"#
color[both] <- "green"#
Ythan$nodes$color <- color
zij <- read.csv("/Users/bryanhanson/Documents/Research/MetabolomicsProjects/ChemometricsStuff/BAHpackages/HiveR Misc/Food Web Networks/Unified Networks Chiu/ChiuWestveld-Modified/XYZ/ythan-z.csv", header = FALSE)
zij <- read.csv("/Users/bryanhanson/Documents/Research/MetabolomicsProjects/ChemometricsStuff/BAHpackages/HiveR Misc/Food Web Networks/Unified Networks Chiu/ChiuWestveld-Modified/XYZ/ythan-z.csv", header = FALSE)#
#
#
zij <- as.matrix(zij) #
dimnames(zij) <- list(lab, lab)
id1 <- id2 <- cl() <- c()#
for (i in 1:dm) { #
	for (j in 1:dm) {#
		if (links[i,j] == 1) {#
			id1 <- c(id1, i)#
			id2 <- c(id2, j)#
			cl <- c(cl, zij[i,j])#
			}#
		}	#
	}
id1 <- id2 <- cl <- c()#
for (i in 1:dm) { #
	for (j in 1:dm) {#
		if (links[i,j] == 1) {#
			id1 <- c(id1, i)#
			id2 <- c(id2, j)#
			cl <- c(cl, zij[i,j])#
			}#
		}	#
	}
Ythan$edges$id1 <- id1#
Ythan$edges$id2 <- id2#
Ythan$edges$weight <- rep(1, length(id1))
str(Ythan)
dimnames(links) <- list(lab, lab)
str(links)
links[,1]
#
#
manipAxis <- function(HPD, method, mult = NULL) {#
	#
	#
	#
	#
#
	chkHPD(HPD)#
	nodes <- HPD[[1]]#
	nx <- length(unique(nodes$axis))#
#
	if (nx == 2) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		}#
#
	if (nx == 3) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		}#
#
	if (nx == 4) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		n4 <- which(nodes$axis == 4)#
		}#
#
	if (nx == 5) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		n4 <- which(nodes$axis == 4)#
		n5 <- which(nodes$axis == 5)#
		}#
#
	if (nx == 6) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		n4 <- which(nodes$axis == 4)#
		n5 <- which(nodes$axis == 5)#
		n6 <- which(nodes$axis == 6)#
		}#
	#
	if (method == "rank") {#
		#
		if (nx == 2) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			}#
#
		if (nx == 3) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			}#
#
		if (nx == 4) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			nodes$radius[n4] <- rank(nodes$radius[n4], ties.method = "first")			#
			}#
#
		if (nx == 5) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			nodes$radius[n4] <- rank(nodes$radius[n4], ties.method = "first")			#
			nodes$radius[n5] <- rank(nodes$radius[n5], ties.method = "first")			#
			}#
#
		if (nx == 6) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			nodes$radius[n4] <- rank(nodes$radius[n4], ties.method = "first")			#
			nodes$radius[n5] <- rank(nodes$radius[n5], ties.method = "first")			#
			nodes$radius[n6] <- rank(nodes$radius[n6], ties.method = "first")			#
			}#
#
		} #
#
	if (method == "norm") {#
		#
		if (nx == 2) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
#
			nodes$radius[n1] <- (nodes$radius[n1]-min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2]-min2)/(max2 - min2)#
			}#
#
		if (nx == 3) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			}#
#
		if (nx == 4) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
			min4 <- min(nodes$radius[n4])#
			max4 <- max(nodes$radius[n4])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			nodes$radius[n4] <- (nodes$radius[n4] - min4)/(max4 - min4)#
			}#
#
		if (nx == 5) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
			min4 <- min(nodes$radius[n4])#
			max4 <- max(nodes$radius[n4])#
			min5 <- min(nodes$radius[n5])#
			max5 <- max(nodes$radius[n5])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			nodes$radius[n4] <- (nodes$radius[n4] - min4)/(max4 - min4)#
			nodes$radius[n5] <- (nodes$radius[n5] - min5)/(max5 - min5)#
			}#
#
		if (nx == 6) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
			min4 <- min(nodes$radius[n4])#
			max4 <- max(nodes$radius[n4])#
			min5 <- min(nodes$radius[n5])#
			max5 <- max(nodes$radius[n5])#
			min6 <- min(nodes$radius[n6])#
			max6 <- max(nodes$radius[n6])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			nodes$radius[n4] <- (nodes$radius[n4] - min4)/(max4 - min4)#
			nodes$radius[n5] <- (nodes$radius[n5] - min5)/(max5 - min5)#
			nodes$radius[n6] <- (nodes$radius[n6] - min6)/(max6 - min6)#
			}#
#
		} #
	#
	if (method == "scale") {#
	#
		if (is.null(mult)) stop("You must supply mult")	#
		if (!length(mult) == length(unique(nodes$axis))) stop("length(mult) did not match no. axes")#
		#
		if (nx == 2) {#
			nodes$radius[n1] <- nodes$radius[n1]*mult[1]#
			nodes$radius[n2] <- nodes$radius[n2]*mult[2]#
			}#
#
		if (nx == 3) {#
			nodes$radius[n1] <- nodes$radius[n1]*mult[1]#
			nodes$radius[n2] <- nodes$radius[n2]*mult[2]#
			nodes$radius[n3] <- nodes$radius[n3]*mult[3]#
			}#
#
		if (nx == 4) {#
			nodes$radius[n1] <- nodes$radius[n1]*mult[1]#
			nodes$radius[n2] <- nodes$radius[n2]*mult[2]#
			nodes$radius[n3] <- nodes$radius[n3]*mult[3]#
			nodes$radius[n4] <- nodes$radius[n4]*mult[4]#
			}#
#
		if (nx == 5) {#
			nodes$radius[n1] <- nodes$radius[n1]*mult[1]#
			nodes$radius[n2] <- nodes$radius[n2]*mult[2]#
			nodes$radius[n3] <- nodes$radius[n3]*mult[3]#
			nodes$radius[n4] <- nodes$radius[n4]*mult[4]#
			nodes$radius[n5] <- nodes$radius[n5]*mult[5]#
			}#
#
		if (nx == 6) {#
			nodes$radius[n1] <- nodes$radius[n1]*mult[1]#
			nodes$radius[n2] <- nodes$radius[n2]*mult[2]#
			nodes$radius[n3] <- nodes$radius[n3]*mult[3]#
			nodes$radius[n4] <- nodes$radius[n4]*mult[4]#
			nodes$radius[n5] <- nodes$radius[n5]*mult[5]#
			nodes$radius[n6] <- nodes$radius[n6]*mult[6]#
			}#
#
		} #
#
	if (method == "ranknorm") { #
	#
		HPD <- manipAxis(method = "rank")#
		HPD <- manipAxis(method = "norm")#
		#
		} #
#
	HPD[[1]] <- nodes#
	chkHPD(HPD)#
	HPD#
	}
tst <- manipAxis(t4, method = "norm")
tst <- manipAxis(t4, method = "rank")
#
#
manipAxis <- function(HPD, method, mult = NULL) {#
	#
	#
	#
	#
#
	chkHPD(HPD)#
	nodes <- HPD[[1]]#
	nx <- length(unique(nodes$axis))#
#
	if (nx == 2) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		}#
#
	if (nx == 3) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		}#
#
	if (nx == 4) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		n4 <- which(nodes$axis == 4)#
		}#
#
	if (nx == 5) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		n4 <- which(nodes$axis == 4)#
		n5 <- which(nodes$axis == 5)#
		}#
#
	if (nx == 6) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		n4 <- which(nodes$axis == 4)#
		n5 <- which(nodes$axis == 5)#
		n6 <- which(nodes$axis == 6)#
		}#
	#
	if (method == "rank") {#
		#
		if (nx == 2) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			}#
#
		if (nx == 3) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			}#
#
		if (nx == 4) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			nodes$radius[n4] <- rank(nodes$radius[n4], ties.method = "first")			#
			}#
#
		if (nx == 5) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			nodes$radius[n4] <- rank(nodes$radius[n4], ties.method = "first")			#
			nodes$radius[n5] <- rank(nodes$radius[n5], ties.method = "first")			#
			}#
#
		if (nx == 6) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			nodes$radius[n4] <- rank(nodes$radius[n4], ties.method = "first")			#
			nodes$radius[n5] <- rank(nodes$radius[n5], ties.method = "first")			#
			nodes$radius[n6] <- rank(nodes$radius[n6], ties.method = "first")			#
			}#
#
		} #
#
	if (method == "norm") {#
		#
		if (nx == 2) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
#
			nodes$radius[n1] <- (nodes$radius[n1]-min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2]-min2)/(max2 - min2)#
			}#
#
		if (nx == 3) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			}#
#
		if (nx == 4) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
			min4 <- min(nodes$radius[n4])#
			max4 <- max(nodes$radius[n4])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			nodes$radius[n4] <- (nodes$radius[n4] - min4)/(max4 - min4)#
			}#
#
		if (nx == 5) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
			min4 <- min(nodes$radius[n4])#
			max4 <- max(nodes$radius[n4])#
			min5 <- min(nodes$radius[n5])#
			max5 <- max(nodes$radius[n5])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			nodes$radius[n4] <- (nodes$radius[n4] - min4)/(max4 - min4)#
			nodes$radius[n5] <- (nodes$radius[n5] - min5)/(max5 - min5)#
			}#
#
		if (nx == 6) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
			min4 <- min(nodes$radius[n4])#
			max4 <- max(nodes$radius[n4])#
			min5 <- min(nodes$radius[n5])#
			max5 <- max(nodes$radius[n5])#
			min6 <- min(nodes$radius[n6])#
			max6 <- max(nodes$radius[n6])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			nodes$radius[n4] <- (nodes$radius[n4] - min4)/(max4 - min4)#
			nodes$radius[n5] <- (nodes$radius[n5] - min5)/(max5 - min5)#
			nodes$radius[n6] <- (nodes$radius[n6] - min6)/(max6 - min6)#
			}#
#
		} #
	#
	if (method == "scale") {#
	#
		if (is.null(mult)) stop("You must supply mult")	#
		if (!length(mult) == length(unique(nodes$axis))) stop("length(mult) did not match no. axes")#
		#
		if (nx == 2) {#
			nodes$radius[n1] <- nodes$radius[n1]*mult[1]#
			nodes$radius[n2] <- nodes$radius[n2]*mult[2]#
			}#
#
		if (nx == 3) {#
			nodes$radius[n1] <- nodes$radius[n1]*mult[1]#
			nodes$radius[n2] <- nodes$radius[n2]*mult[2]#
			nodes$radius[n3] <- nodes$radius[n3]*mult[3]#
			}#
#
		if (nx == 4) {#
			nodes$radius[n1] <- nodes$radius[n1]*mult[1]#
			nodes$radius[n2] <- nodes$radius[n2]*mult[2]#
			nodes$radius[n3] <- nodes$radius[n3]*mult[3]#
			nodes$radius[n4] <- nodes$radius[n4]*mult[4]#
			}#
#
		if (nx == 5) {#
			nodes$radius[n1] <- nodes$radius[n1]*mult[1]#
			nodes$radius[n2] <- nodes$radius[n2]*mult[2]#
			nodes$radius[n3] <- nodes$radius[n3]*mult[3]#
			nodes$radius[n4] <- nodes$radius[n4]*mult[4]#
			nodes$radius[n5] <- nodes$radius[n5]*mult[5]#
			}#
#
		if (nx == 6) {#
			nodes$radius[n1] <- nodes$radius[n1]*mult[1]#
			nodes$radius[n2] <- nodes$radius[n2]*mult[2]#
			nodes$radius[n3] <- nodes$radius[n3]*mult[3]#
			nodes$radius[n4] <- nodes$radius[n4]*mult[4]#
			nodes$radius[n5] <- nodes$radius[n5]*mult[5]#
			nodes$radius[n6] <- nodes$radius[n6]*mult[6]#
			}#
#
		} #
#
	if (method == "ranknorm") { #
	#
		HPD <- manipAxis(HPD, method = "rank")#
		HPD <- manipAxis(HPD, method = "norm")#
		#
		} #
#
	HPD[[1]] <- nodes#
	chkHPD(HPD)#
	HPD#
	}
tst <- manipAxis(t4, method = "ranknorm")
data(Arroyo)
str(Arroyo)
#
chkHPD <-#
function(HPD, confirm = FALSE) {#
#
#
#
#
#
	if (missing(HPD)) stop("Nothing to check")#
	w <- FALSE#
	#
	if (!class(HPD) == "HivePlotData") { warning("The object provided was not of class HivePlotData"); w <- TRUE }#
#
	if (!class(HPD$nodes) == "data.frame") { warning("The nodes data appear to be corrupt"); w <- TRUE }#
	if (!class(HPD$nodes$id) == "integer") { warning("nodes$id appears to be corrupt"); w <- TRUE }#
	if (!class(HPD$nodes$radius) == "numeric") { warning("nodes$radius appears to be corrupt"); w <- TRUE }#
	if (!class(HPD$nodes$lab) == "character") { warning("nodes$lab appears to be corrupt"); w <- TRUE }#
	if (!class(HPD$nodes$axis) == "integer") { warning("nodes$axis appears to be corrupt"); w <- TRUE }#
	if (!class(HPD$nodes$color) == "character") { warning("nodes$color appears to be corrupt"); w <- TRUE }#
#
	if (!class(HPD$edges) == "data.frame") { warning("The edges data appear to be corrupt"); w <- TRUE }#
	if (!class(HPD$edges$id1) == "integer") { warning("edges$id1 appears to be corrupt"); w <- TRUE }#
	if (!class(HPD$edges$id2) == "integer") { warning("edges$id2 appears to be corrupt"); w <- TRUE }#
	if (!class(HPD$edges$weight) == "numeric") { warning("edges$weight appears to be corrupt"); w <- TRUE }#
	if (!class(HPD$edges$color) == "character") { warning("edges$color appears to be corrupt"); w <- TRUE }#
#
#
	if (!class(HPD$desc) == "character") { warning("The description appears to be corrupt"); w <- TRUE }#
	if (!class(HPD$axis.cols) == "character") { warning("axis.cols appears to be corrupt"); w <- TRUE }#
#
	if (!((HPD$type == "2D") | (HPD$type == "3D"))) { warning("Type must be 2D or 3D"); w <- TRUE }#
#
	if ((!w) && (confirm)) cat("You must be awesome: This hive plot data looks dandy!")#
	if (w) {#
		cat("*** There seem to be one or more problems with this hive plot data!\n")#
		stop("Sorry, we can't continue this way: It's not me, it's you!\n")#
		}#
#
	return(w)#
	}
#
#
#
#
#
require(bipartite)#
data(vazarr) #
#
Arroyo <- list()#
#
#
#
#
lab <- unlist(c(dimnames(vazarr)[1], dimnames(vazarr)[2]))#
lab <- as.character(lab)#
no.nodes <- length(lab)#
size <- rep(1, no.nodes)#
id <- 1:no.nodes#
axis <- as.integer(c(rep(1,10), rep(2, 29))) #
color <- as.character(rep("black", no.nodes))#
#
#
dp1 <- dfun(vazarr) #
dp1 <- dp1$dprime#
dp2 <- dfun(t(vazarr)) #
dp2 <- dp2$dprime#
radius <- c(dp1, dp2)#
#
Arroyo$nodes <- data.frame(id, lab, radius, axis, size, color)#
Arroyo$nodes$lab <- as.character(Arroyo$nodes$lab)#
Arroyo$nodes$color <- as.character(Arroyo$nodes$color)#
Arroyo$nodes$radius <- as.numeric(Arroyo$nodes$radius)#
#
#
#
id1 <- id2 <- v <- c() #
for (i in 1:10) { #
	for (j in 1:29) {#
		if (!vazarr[i,j] == 0) {#
			id1 <- c(id1, i)#
			id2 <- c(id2, j)#
			v <- c(v, vazarr[i,j])#
			}#
		}	#
	}#
#
#
#
hc <- c("white", "yellow", "orange", "red")#
cl <- cut(v, breaks = c(0, 2.5, 15, 175, 700), include.lowest = TRUE, right = FALSE, labels = FALSE)#
color <- hc[cl]#
	#
weight <- sqrt(v*500/sum(v))#
#
id2 <- as.integer(id2 + 10) #
#
Arroyo$edges <- data.frame(id1, id2, weight, color)#
Arroyo$edges$color <- as.character(Arroyo$edges$color)#
#
#
Arroyo$type <- "2D"#
Arroyo$desc <- "Modified Arroyoland Data Set"#
Arroyo$axis.cols <- rep("gray", 2)#
Arroyo$axes <- 2#
class(Arroyo) <- "HivePlotData"#
#
#
#
#
for (n in seq(1, 39, by = 2)) {#
	a <- Arroyo$edges$id1[n]#
	b <- Arroyo$edges$id2[n]#
	Arroyo$edges$id1[n] <- b#
	Arroyo$edges$id2[n] <- a#
	}#
	#
Arroyo$edges <- Arroyo$edges[do.call(order, list(weight)),]#
#
chkHPD(Arroyo)
getwd()
save(Arroyo, file = "Arroyo.RData")
#
#
#
#
#
require(bipartite)#
data(Safariland) #
#
Safari <- list()#
#
#
#
#
lab <- unlist(c(dimnames(Safariland)[1], dimnames(Safariland)[2]))#
lab <- as.character(lab)#
no.nodes <- length(lab)#
size <- rep(1, no.nodes)#
id <- 1:no.nodes#
axis <- as.integer(c(rep(1,9), rep(2, 27))) #
color <- as.character(rep("black", no.nodes))#
#
#
dp1 <- dfun(Safariland) #
dp1 <- dp1$dprime#
dp2 <- dfun(t(Safariland)) #
dp2 <- dp2$dprime#
radius <- c(dp1, dp2)#
#
Safari$nodes <- data.frame(id, lab, radius, axis, size, color)#
Safari$nodes$lab <- as.character(Safari$nodes$lab)#
Safari$nodes$color <- as.character(Safari$nodes$color)#
Safari$nodes$radius <- as.numeric(Safari$nodes$radius)#
#
#
#
id1 <- id2 <- v <- c() #
for (i in 1:9) { #
	for (j in 1:27) {#
		if (!Safariland[i,j] == 0) {#
			id1 <- c(id1, i)#
			id2 <- c(id2, j)#
			v <- c(v, Safariland[i,j])#
			}#
		}	#
	}#
#
#
#
#
#
#
#
#
hc <- c("white", "yellow", "orange", "red")#
cl <- cut(v, breaks = c(0, 2, 10, 175, 700), include.lowest = TRUE, right = FALSE, labels = FALSE)#
color <- hc[cl]#
	#
weight <- sqrt(v*500/sum(v))#
#
id2 <- as.integer(id2 + 9) #
#
Safari$edges <- data.frame(id1, id2, weight, color)#
Safari$edges$color <- as.character(Safari$edges$color)#
#
#
Safari$desc <- "Modified Safariland Data Set"#
Safari$type <- "2D"#
Safari$axis.cols <- rep("gray", 2)#
Safari$axes <- 2#
class(Safari) <- "HivePlotData"#
#
#
#
#
for (n in seq(1, 39, by = 2)) {#
	a <- Safari$edges$id1[n]#
	b <- Safari$edges$id2[n]#
	Safari$edges$id1[n] <- b#
	Safari$edges$id2[n] <- a#
	}#
	#
Safari$edges <- Safari$edges[do.call(order, list(weight)),]
chkHPD(Safari)
save(Safari, file = "Safari.RData")
?invert
findFn("invert")
#
#
manipAxis <- function(HPD, method, action = NULL) {#
	#
	#
	#
	#
#
	chkHPD(HPD)#
	nodes <- HPD[[1]]#
	nx <- length(unique(nodes$axis))#
#
	if (nx == 2) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		}#
#
	if (nx == 3) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		}#
#
	if (nx == 4) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		n4 <- which(nodes$axis == 4)#
		}#
#
	if (nx == 5) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		n4 <- which(nodes$axis == 4)#
		n5 <- which(nodes$axis == 5)#
		}#
#
	if (nx == 6) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		n4 <- which(nodes$axis == 4)#
		n5 <- which(nodes$axis == 5)#
		n6 <- which(nodes$axis == 6)#
		}#
	#
	if (method == "rank") {#
		#
		if (nx == 2) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			}#
#
		if (nx == 3) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			}#
#
		if (nx == 4) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			nodes$radius[n4] <- rank(nodes$radius[n4], ties.method = "first")			#
			}#
#
		if (nx == 5) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			nodes$radius[n4] <- rank(nodes$radius[n4], ties.method = "first")			#
			nodes$radius[n5] <- rank(nodes$radius[n5], ties.method = "first")			#
			}#
#
		if (nx == 6) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			nodes$radius[n4] <- rank(nodes$radius[n4], ties.method = "first")			#
			nodes$radius[n5] <- rank(nodes$radius[n5], ties.method = "first")			#
			nodes$radius[n6] <- rank(nodes$radius[n6], ties.method = "first")			#
			}#
#
		} #
#
	if (method == "norm") {#
		#
		if (nx == 2) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
#
			nodes$radius[n1] <- (nodes$radius[n1]-min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2]-min2)/(max2 - min2)#
			}#
#
		if (nx == 3) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			}#
#
		if (nx == 4) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
			min4 <- min(nodes$radius[n4])#
			max4 <- max(nodes$radius[n4])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			nodes$radius[n4] <- (nodes$radius[n4] - min4)/(max4 - min4)#
			}#
#
		if (nx == 5) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
			min4 <- min(nodes$radius[n4])#
			max4 <- max(nodes$radius[n4])#
			min5 <- min(nodes$radius[n5])#
			max5 <- max(nodes$radius[n5])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			nodes$radius[n4] <- (nodes$radius[n4] - min4)/(max4 - min4)#
			nodes$radius[n5] <- (nodes$radius[n5] - min5)/(max5 - min5)#
			}#
#
		if (nx == 6) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
			min4 <- min(nodes$radius[n4])#
			max4 <- max(nodes$radius[n4])#
			min5 <- min(nodes$radius[n5])#
			max5 <- max(nodes$radius[n5])#
			min6 <- min(nodes$radius[n6])#
			max6 <- max(nodes$radius[n6])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			nodes$radius[n4] <- (nodes$radius[n4] - min4)/(max4 - min4)#
			nodes$radius[n5] <- (nodes$radius[n5] - min5)/(max5 - min5)#
			nodes$radius[n6] <- (nodes$radius[n6] - min6)/(max6 - min6)#
			}#
#
		} #
	#
	if (method == "scale") {#
	#
		if (is.null(action)) stop("You must supply action")	#
		if (!length(action) == length(unique(nodes$axis))) stop("length(action) did not match no. axes")#
		#
		if (nx == 2) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1]#
			nodes$radius[n2] <- nodes$radius[n2]*action[2]#
			}#
#
		if (nx == 3) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1]#
			nodes$radius[n2] <- nodes$radius[n2]*action[2]#
			nodes$radius[n3] <- nodes$radius[n3]*action[3]#
			}#
#
		if (nx == 4) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1]#
			nodes$radius[n2] <- nodes$radius[n2]*action[2]#
			nodes$radius[n3] <- nodes$radius[n3]*action[3]#
			nodes$radius[n4] <- nodes$radius[n4]*action[4]#
			}#
#
		if (nx == 5) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1]#
			nodes$radius[n2] <- nodes$radius[n2]*action[2]#
			nodes$radius[n3] <- nodes$radius[n3]*action[3]#
			nodes$radius[n4] <- nodes$radius[n4]*action[4]#
			nodes$radius[n5] <- nodes$radius[n5]*action[5]#
			}#
#
		if (nx == 6) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1]#
			nodes$radius[n2] <- nodes$radius[n2]*action[2]#
			nodes$radius[n3] <- nodes$radius[n3]*action[3]#
			nodes$radius[n4] <- nodes$radius[n4]*action[4]#
			nodes$radius[n5] <- nodes$radius[n5]*action[5]#
			nodes$radius[n6] <- nodes$radius[n6]*action[6]#
			}#
#
		} #
#
	if (method == "invert") {#
	#
		if (is.null(action)) stop("You must supply action")	#
		if (!length(action) == length(unique(nodes$axis))) stop("length(action) did not match no. axes")#
		#
		if (nx == 2) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1] + min(nodes$radius[n1])*2 + diff(range(nodes$radius[n1]))#
			nodes$radius[n2] <- nodes$radius[n2]*action[2] + min(nodes$radius[n2])*2 + diff(range(nodes$radius[n2]))#
			}#
#
		if (nx == 3) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1] + min(nodes$radius[n1])*2 + diff(range(nodes$radius[n1]))#
			nodes$radius[n2] <- nodes$radius[n2]*action[2] + min(nodes$radius[n2])*2 + diff(range(nodes$radius[n2]))#
			nodes$radius[n3] <- nodes$radius[n3]*action[3] + min(nodes$radius[n3])*2 + diff(range(nodes$radius[n3]))#
			}#
#
		if (nx == 4) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1] + min(nodes$radius[n1])*2 + diff(range(nodes$radius[n1]))#
			nodes$radius[n2] <- nodes$radius[n2]*action[2] + min(nodes$radius[n2])*2 + diff(range(nodes$radius[n2]))#
			nodes$radius[n3] <- nodes$radius[n3]*action[3] + min(nodes$radius[n3])*2 + diff(range(nodes$radius[n3]))#
			nodes$radius[n4] <- nodes$radius[n4]*action[4] + min(nodes$radius[n4])*2 + diff(range(nodes$radius[n4]))#
			}#
#
		if (nx == 5) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1] + min(nodes$radius[n1])*2 + diff(range(nodes$radius[n1]))#
			nodes$radius[n2] <- nodes$radius[n2]*action[2] + min(nodes$radius[n2])*2 + diff(range(nodes$radius[n2]))#
			nodes$radius[n3] <- nodes$radius[n3]*action[3] + min(nodes$radius[n3])*2 + diff(range(nodes$radius[n3]))#
			nodes$radius[n4] <- nodes$radius[n4]*action[4] + min(nodes$radius[n4])*2 + diff(range(nodes$radius[n4]))#
			nodes$radius[n5] <- nodes$radius[n5]*action[5] + min(nodes$radius[n5])*2 + diff(range(nodes$radius[n5]))#
			}#
#
		if (nx == 6) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1] + min(nodes$radius[n1])*2 + diff(range(nodes$radius[n1]))#
			nodes$radius[n2] <- nodes$radius[n2]*action[2] + min(nodes$radius[n2])*2 + diff(range(nodes$radius[n2]))#
			nodes$radius[n3] <- nodes$radius[n3]*action[3] + min(nodes$radius[n3])*2 + diff(range(nodes$radius[n3]))#
			nodes$radius[n4] <- nodes$radius[n4]*action[4] + min(nodes$radius[n4])*2 + diff(range(nodes$radius[n4]))#
			nodes$radius[n5] <- nodes$radius[n5]*action[5] + min(nodes$radius[n5])*2 + diff(range(nodes$radius[n5]))#
			nodes$radius[n6] <- nodes$radius[n6]*action[6] + min(nodes$radius[n6])*2 + diff(range(nodes$radius[n6]))#
			}#
#
		} #
#
	if (method == "ranknorm") { #
	#
		HPD <- manipAxis(HPD, method = "rank")#
		HPD <- manipAxis(HPD, method = "norm")#
		#
		} #
#
	HPD[[1]] <- nodes#
	chkHPD(HPD)#
	HPD#
	}
t4 <- ranHiveData()
tst <- manipAxis(t4, method = "invert", action = c(1, -1, 1))
plotHive(tst)
#
#
manipAxis <- function(HPD, method, action = NULL) {#
	#
	#
	#
	#
#
	chkHPD(HPD)#
	nodes <- HPD[[1]]#
	nx <- length(unique(nodes$axis))#
#
	if (nx == 2) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		}#
#
	if (nx == 3) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		}#
#
	if (nx == 4) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		n4 <- which(nodes$axis == 4)#
		}#
#
	if (nx == 5) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		n4 <- which(nodes$axis == 4)#
		n5 <- which(nodes$axis == 5)#
		}#
#
	if (nx == 6) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		n4 <- which(nodes$axis == 4)#
		n5 <- which(nodes$axis == 5)#
		n6 <- which(nodes$axis == 6)#
		}#
	#
	if (method == "rank") {#
		#
		if (nx == 2) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			}#
#
		if (nx == 3) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			}#
#
		if (nx == 4) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			nodes$radius[n4] <- rank(nodes$radius[n4], ties.method = "first")			#
			}#
#
		if (nx == 5) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			nodes$radius[n4] <- rank(nodes$radius[n4], ties.method = "first")			#
			nodes$radius[n5] <- rank(nodes$radius[n5], ties.method = "first")			#
			}#
#
		if (nx == 6) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			nodes$radius[n4] <- rank(nodes$radius[n4], ties.method = "first")			#
			nodes$radius[n5] <- rank(nodes$radius[n5], ties.method = "first")			#
			nodes$radius[n6] <- rank(nodes$radius[n6], ties.method = "first")			#
			}#
#
		} #
#
	if (method == "norm") {#
		#
		if (nx == 2) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
#
			nodes$radius[n1] <- (nodes$radius[n1]-min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2]-min2)/(max2 - min2)#
			}#
#
		if (nx == 3) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			}#
#
		if (nx == 4) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
			min4 <- min(nodes$radius[n4])#
			max4 <- max(nodes$radius[n4])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			nodes$radius[n4] <- (nodes$radius[n4] - min4)/(max4 - min4)#
			}#
#
		if (nx == 5) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
			min4 <- min(nodes$radius[n4])#
			max4 <- max(nodes$radius[n4])#
			min5 <- min(nodes$radius[n5])#
			max5 <- max(nodes$radius[n5])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			nodes$radius[n4] <- (nodes$radius[n4] - min4)/(max4 - min4)#
			nodes$radius[n5] <- (nodes$radius[n5] - min5)/(max5 - min5)#
			}#
#
		if (nx == 6) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
			min4 <- min(nodes$radius[n4])#
			max4 <- max(nodes$radius[n4])#
			min5 <- min(nodes$radius[n5])#
			max5 <- max(nodes$radius[n5])#
			min6 <- min(nodes$radius[n6])#
			max6 <- max(nodes$radius[n6])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			nodes$radius[n4] <- (nodes$radius[n4] - min4)/(max4 - min4)#
			nodes$radius[n5] <- (nodes$radius[n5] - min5)/(max5 - min5)#
			nodes$radius[n6] <- (nodes$radius[n6] - min6)/(max6 - min6)#
			}#
#
		} #
	#
	if (method == "scale") {#
	#
		if (is.null(action)) stop("You must supply action")	#
		if (!length(action) == length(unique(nodes$axis))) stop("length(action) did not match no. axes")#
		#
		if (nx == 2) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1]#
			nodes$radius[n2] <- nodes$radius[n2]*action[2]#
			}#
#
		if (nx == 3) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1]#
			nodes$radius[n2] <- nodes$radius[n2]*action[2]#
			nodes$radius[n3] <- nodes$radius[n3]*action[3]#
			}#
#
		if (nx == 4) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1]#
			nodes$radius[n2] <- nodes$radius[n2]*action[2]#
			nodes$radius[n3] <- nodes$radius[n3]*action[3]#
			nodes$radius[n4] <- nodes$radius[n4]*action[4]#
			}#
#
		if (nx == 5) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1]#
			nodes$radius[n2] <- nodes$radius[n2]*action[2]#
			nodes$radius[n3] <- nodes$radius[n3]*action[3]#
			nodes$radius[n4] <- nodes$radius[n4]*action[4]#
			nodes$radius[n5] <- nodes$radius[n5]*action[5]#
			}#
#
		if (nx == 6) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1]#
			nodes$radius[n2] <- nodes$radius[n2]*action[2]#
			nodes$radius[n3] <- nodes$radius[n3]*action[3]#
			nodes$radius[n4] <- nodes$radius[n4]*action[4]#
			nodes$radius[n5] <- nodes$radius[n5]*action[5]#
			nodes$radius[n6] <- nodes$radius[n6]*action[6]#
			}#
#
		} #
#
	if (method == "invert") {#
	#
		if (is.null(action)) stop("You must supply action")	#
		if (!length(action) == length(unique(nodes$axis))) stop("length(action) did not match no. axes")#
	#
		for (n in 1:length(action)) {#
			#
			if (action[n] == -1) {#
				xx <- which(nodes$axis == n)#
				print(xx)#
				nodes$radius[xx] <- nodes$radius[xx]*-1 + min(nodes$radius[xx])*2 + diff(range(nodes$radius[xx]))#
				}#
			}	#
		} #
#
	if (method == "ranknorm") { #
	#
		HPD <- manipAxis(HPD, method = "rank")#
		HPD <- manipAxis(HPD, method = "norm")#
		#
		} #
#
	HPD[[1]] <- nodes#
	chkHPD(HPD)#
	HPD#
	}
#
#
manipAxis <- function(HPD, method, action = NULL) {#
	#
	#
	#
	#
#
	chkHPD(HPD)#
	nodes <- HPD[[1]]#
	nx <- length(unique(nodes$axis))#
#
	if (nx == 2) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		}#
#
	if (nx == 3) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		}#
#
	if (nx == 4) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		n4 <- which(nodes$axis == 4)#
		}#
#
	if (nx == 5) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		n4 <- which(nodes$axis == 4)#
		n5 <- which(nodes$axis == 5)#
		}#
#
	if (nx == 6) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		n4 <- which(nodes$axis == 4)#
		n5 <- which(nodes$axis == 5)#
		n6 <- which(nodes$axis == 6)#
		}#
	#
	if (method == "rank") {#
		#
		if (nx == 2) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			}#
#
		if (nx == 3) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			}#
#
		if (nx == 4) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			nodes$radius[n4] <- rank(nodes$radius[n4], ties.method = "first")			#
			}#
#
		if (nx == 5) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			nodes$radius[n4] <- rank(nodes$radius[n4], ties.method = "first")			#
			nodes$radius[n5] <- rank(nodes$radius[n5], ties.method = "first")			#
			}#
#
		if (nx == 6) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			nodes$radius[n4] <- rank(nodes$radius[n4], ties.method = "first")			#
			nodes$radius[n5] <- rank(nodes$radius[n5], ties.method = "first")			#
			nodes$radius[n6] <- rank(nodes$radius[n6], ties.method = "first")			#
			}#
#
		} #
#
	if (method == "norm") {#
		#
		if (nx == 2) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
#
			nodes$radius[n1] <- (nodes$radius[n1]-min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2]-min2)/(max2 - min2)#
			}#
#
		if (nx == 3) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			}#
#
		if (nx == 4) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
			min4 <- min(nodes$radius[n4])#
			max4 <- max(nodes$radius[n4])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			nodes$radius[n4] <- (nodes$radius[n4] - min4)/(max4 - min4)#
			}#
#
		if (nx == 5) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
			min4 <- min(nodes$radius[n4])#
			max4 <- max(nodes$radius[n4])#
			min5 <- min(nodes$radius[n5])#
			max5 <- max(nodes$radius[n5])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			nodes$radius[n4] <- (nodes$radius[n4] - min4)/(max4 - min4)#
			nodes$radius[n5] <- (nodes$radius[n5] - min5)/(max5 - min5)#
			}#
#
		if (nx == 6) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
			min4 <- min(nodes$radius[n4])#
			max4 <- max(nodes$radius[n4])#
			min5 <- min(nodes$radius[n5])#
			max5 <- max(nodes$radius[n5])#
			min6 <- min(nodes$radius[n6])#
			max6 <- max(nodes$radius[n6])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			nodes$radius[n4] <- (nodes$radius[n4] - min4)/(max4 - min4)#
			nodes$radius[n5] <- (nodes$radius[n5] - min5)/(max5 - min5)#
			nodes$radius[n6] <- (nodes$radius[n6] - min6)/(max6 - min6)#
			}#
#
		} #
	#
	if (method == "scale") {#
	#
		if (is.null(action)) stop("You must supply action")	#
		if (!length(action) == length(unique(nodes$axis))) stop("length(action) did not match no. axes")#
		#
		if (nx == 2) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1]#
			nodes$radius[n2] <- nodes$radius[n2]*action[2]#
			}#
#
		if (nx == 3) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1]#
			nodes$radius[n2] <- nodes$radius[n2]*action[2]#
			nodes$radius[n3] <- nodes$radius[n3]*action[3]#
			}#
#
		if (nx == 4) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1]#
			nodes$radius[n2] <- nodes$radius[n2]*action[2]#
			nodes$radius[n3] <- nodes$radius[n3]*action[3]#
			nodes$radius[n4] <- nodes$radius[n4]*action[4]#
			}#
#
		if (nx == 5) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1]#
			nodes$radius[n2] <- nodes$radius[n2]*action[2]#
			nodes$radius[n3] <- nodes$radius[n3]*action[3]#
			nodes$radius[n4] <- nodes$radius[n4]*action[4]#
			nodes$radius[n5] <- nodes$radius[n5]*action[5]#
			}#
#
		if (nx == 6) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1]#
			nodes$radius[n2] <- nodes$radius[n2]*action[2]#
			nodes$radius[n3] <- nodes$radius[n3]*action[3]#
			nodes$radius[n4] <- nodes$radius[n4]*action[4]#
			nodes$radius[n5] <- nodes$radius[n5]*action[5]#
			nodes$radius[n6] <- nodes$radius[n6]*action[6]#
			}#
#
		} #
#
	if (method == "invert") {#
	#
		if (is.null(action)) stop("You must supply action")	#
		if (!length(action) == length(unique(nodes$axis))) stop("length(action) did not match no. axes")#
	#
		for (n in 1:length(action)) {#
			#
			if (action[n] == -1) {#
				xx <- which(nodes$axis == n)#
				print(xx)#
				print(nodes$radis[xx])#
				nodes$radius[xx] <- nodes$radius[xx]*-1 + min(nodes$radius[xx])*2 + diff(range(nodes$radius[xx]))#
				print(nodes$radis[xx])#
				}#
			}	#
		} #
#
	if (method == "ranknorm") { #
	#
		HPD <- manipAxis(HPD, method = "rank")#
		HPD <- manipAxis(HPD, method = "norm")#
		#
		} #
#
	HPD[[1]] <- nodes#
	chkHPD(HPD)#
	HPD#
	}
#
#
manipAxis <- function(HPD, method, action = NULL) {#
	#
	#
	#
	#
#
	chkHPD(HPD)#
	nodes <- HPD[[1]]#
	nx <- length(unique(nodes$axis))#
#
	if (nx == 2) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		}#
#
	if (nx == 3) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		}#
#
	if (nx == 4) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		n4 <- which(nodes$axis == 4)#
		}#
#
	if (nx == 5) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		n4 <- which(nodes$axis == 4)#
		n5 <- which(nodes$axis == 5)#
		}#
#
	if (nx == 6) {#
		n1 <- which(nodes$axis == 1)#
		n2 <- which(nodes$axis == 2)#
		n3 <- which(nodes$axis == 3)#
		n4 <- which(nodes$axis == 4)#
		n5 <- which(nodes$axis == 5)#
		n6 <- which(nodes$axis == 6)#
		}#
	#
	if (method == "rank") {#
		#
		if (nx == 2) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			}#
#
		if (nx == 3) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			}#
#
		if (nx == 4) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			nodes$radius[n4] <- rank(nodes$radius[n4], ties.method = "first")			#
			}#
#
		if (nx == 5) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			nodes$radius[n4] <- rank(nodes$radius[n4], ties.method = "first")			#
			nodes$radius[n5] <- rank(nodes$radius[n5], ties.method = "first")			#
			}#
#
		if (nx == 6) {#
			nodes$radius[n1] <- rank(nodes$radius[n1], ties.method = "first")#
			nodes$radius[n2] <- rank(nodes$radius[n2], ties.method = "first")			#
			nodes$radius[n3] <- rank(nodes$radius[n3], ties.method = "first")			#
			nodes$radius[n4] <- rank(nodes$radius[n4], ties.method = "first")			#
			nodes$radius[n5] <- rank(nodes$radius[n5], ties.method = "first")			#
			nodes$radius[n6] <- rank(nodes$radius[n6], ties.method = "first")			#
			}#
#
		} #
#
	if (method == "norm") {#
		#
		if (nx == 2) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
#
			nodes$radius[n1] <- (nodes$radius[n1]-min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2]-min2)/(max2 - min2)#
			}#
#
		if (nx == 3) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			}#
#
		if (nx == 4) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
			min4 <- min(nodes$radius[n4])#
			max4 <- max(nodes$radius[n4])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			nodes$radius[n4] <- (nodes$radius[n4] - min4)/(max4 - min4)#
			}#
#
		if (nx == 5) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
			min4 <- min(nodes$radius[n4])#
			max4 <- max(nodes$radius[n4])#
			min5 <- min(nodes$radius[n5])#
			max5 <- max(nodes$radius[n5])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			nodes$radius[n4] <- (nodes$radius[n4] - min4)/(max4 - min4)#
			nodes$radius[n5] <- (nodes$radius[n5] - min5)/(max5 - min5)#
			}#
#
		if (nx == 6) {#
			min1 <- min(nodes$radius[n1])#
			max1 <- max(nodes$radius[n1])#
			min2 <- min(nodes$radius[n2])#
			max2 <- max(nodes$radius[n2])#
			min3 <- min(nodes$radius[n3])#
			max3 <- max(nodes$radius[n3])#
			min4 <- min(nodes$radius[n4])#
			max4 <- max(nodes$radius[n4])#
			min5 <- min(nodes$radius[n5])#
			max5 <- max(nodes$radius[n5])#
			min6 <- min(nodes$radius[n6])#
			max6 <- max(nodes$radius[n6])#
#
			nodes$radius[n1] <- (nodes$radius[n1] - min1)/(max1 - min1)#
			nodes$radius[n2] <- (nodes$radius[n2] - min2)/(max2 - min2)#
			nodes$radius[n3] <- (nodes$radius[n3] - min3)/(max3 - min3)#
			nodes$radius[n4] <- (nodes$radius[n4] - min4)/(max4 - min4)#
			nodes$radius[n5] <- (nodes$radius[n5] - min5)/(max5 - min5)#
			nodes$radius[n6] <- (nodes$radius[n6] - min6)/(max6 - min6)#
			}#
#
		} #
	#
	if (method == "scale") {#
	#
		if (is.null(action)) stop("You must supply action")	#
		if (!length(action) == length(unique(nodes$axis))) stop("length(action) did not match no. axes")#
		#
		if (nx == 2) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1]#
			nodes$radius[n2] <- nodes$radius[n2]*action[2]#
			}#
#
		if (nx == 3) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1]#
			nodes$radius[n2] <- nodes$radius[n2]*action[2]#
			nodes$radius[n3] <- nodes$radius[n3]*action[3]#
			}#
#
		if (nx == 4) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1]#
			nodes$radius[n2] <- nodes$radius[n2]*action[2]#
			nodes$radius[n3] <- nodes$radius[n3]*action[3]#
			nodes$radius[n4] <- nodes$radius[n4]*action[4]#
			}#
#
		if (nx == 5) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1]#
			nodes$radius[n2] <- nodes$radius[n2]*action[2]#
			nodes$radius[n3] <- nodes$radius[n3]*action[3]#
			nodes$radius[n4] <- nodes$radius[n4]*action[4]#
			nodes$radius[n5] <- nodes$radius[n5]*action[5]#
			}#
#
		if (nx == 6) {#
			nodes$radius[n1] <- nodes$radius[n1]*action[1]#
			nodes$radius[n2] <- nodes$radius[n2]*action[2]#
			nodes$radius[n3] <- nodes$radius[n3]*action[3]#
			nodes$radius[n4] <- nodes$radius[n4]*action[4]#
			nodes$radius[n5] <- nodes$radius[n5]*action[5]#
			nodes$radius[n6] <- nodes$radius[n6]*action[6]#
			}#
#
		} #
#
	if (method == "invert") {#
	#
		if (is.null(action)) stop("You must supply action")	#
		if (!length(action) == length(unique(nodes$axis))) stop("length(action) did not match no. axes")#
	#
		for (n in 1:length(action)) {#
			#
			if (action[n] == -1) {#
				xx <- which(nodes$axis == n)#
				print(xx)#
				print(nodes$radius[xx])#
				nodes$radius[xx] <- nodes$radius[xx]*-1 + min(nodes$radius[xx])*2 + diff(range(nodes$radius[xx]))#
				print(nodes$radius[xx])#
				}#
			}	#
		} #
#
	if (method == "ranknorm") { #
	#
		HPD <- manipAxis(HPD, method = "rank")#
		HPD <- manipAxis(HPD, method = "norm")#
		#
		} #
#
	HPD[[1]] <- nodes#
	chkHPD(HPD)#
	HPD#
	}
tst <- manipAxis(t4, method = "invert", action = c(1, -1, 1, 1))
plotHive(t4)
plotHive(t4, method = "scale", action = c(0.5, 1, 1))
#
#
plotHive <- function(HPD, ch = 1, dr.nodes = TRUE,#
	method = "abs", ...) {#
	#
	#
	#
	#
	#
	#
	#
	#
#
#
#
	if (!HPD$type == "2D") stop("This is not a 2D hive data set: use plot3dHive instead")		#
	chkHPD(HPD)#
	nx <- length(unique(HPD$nodes$axis))#
#
	if (nx == 1) stop("Something is wrong: only one axis seems to be present")#
#
	#
	#
	if (!method == "abs") HPD <- manipAxis(HPD, method, ...)#
#
	nodes <- HPD$nodes#
	edges <- HPD$edges#
	axis.cols <- HPD$axis.cols#
#
	#
	#
	nodes$radius <- nodes$radius + ch#
	HPD$nodes$radius <- nodes$radius#
#
	p2cX <- function(r, theta) x <- r*cos(theta*2*pi/360)#
	p2cY <- function(r, theta) y <- r*sin(theta*2*pi/360)#
#
#
#
	#
	#
	if (nx == 2) {#
		#
		n1 <- subset(nodes, axis == 1)#
		n2 <- subset(nodes, axis == 2)#
		max1 <- max(n1$radius)#
		max2 <- max(n2$radius)#
		min1 <- min(n1$radius)#
		min2 <- min(n2$radius)#
	#
		r.st <- c(min1, min2) #
		axst <- c(0, 180)#
		x0a = p2cX(r.st, axst)#
		y0a = p2cY(r.st, axst)#
#
		r.end <- c(max1, max2)#
		axend <- c(0, 180)#
		x1a = p2cX(r.end, axend)#
		y1a = p2cY(r.end, axend)#
	#
	#
		#
		md <- max(abs(c(x0a, y0a, x1a, y1a)))*1.2 #
		#
		grid.newpage()#
		grid.rect(gp=gpar(fill="black"))#
		vp <- viewport(x = 0.5, y = 0.5, width = 1, height = 1,#
			xscale = c(-md, md), yscale = c(-md, md),#
			name = "3DHivePlot")#
#
		pushViewport(vp)#
#
#
	#
#
	#
	#
		#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if (nodes$axis[id1] == 1) { #
				th.st <- c(th.st, 0)#
				r.st <- c(r.st, nodes$radius[id1])#
				}#
			if (nodes$axis[id1] == 2) {#
				th.st <- c(th.st, 180)#
				r.st <- c(r.st, nodes$radius[id1])#
				}#
#
			if (nodes$axis[id2] == 1) { #
				th.end <- c(th.end, 0)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
			if (nodes$axis[id2] == 2) {#
				th.end <- c(th.end, 180)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
				#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
		#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = -0.5)#
			}#
#
	#
	#
		grid.segments(x0a, y0a, x1a, y1a,#
			gp = gpar(col = HPD$axis.cols, lwd = 8),#
			default.units = "native")#
	#
	#
	#
		if (dr.nodes) {#
			r <- c(n1$radius, n2$radius) #
			theta <- c(rep(0, length(n1$radius)),#
				rep(180, length(n2$radius)))#
			x = p2cX(r, theta)#
			y = p2cY(r, theta)#
			grid.points(x, y, pch = 20, gp = gpar(cex = nodes$size, col = nodes$color))#
			}#
#
		} #
	#
#
#
	#
	#
	if (nx == 3) {#
		#
		n1 <- subset(nodes, axis == 1)#
		n2 <- subset(nodes, axis == 2)#
		n3 <- subset(nodes, axis == 3)#
		max1 <- max(n1$radius)#
		max2 <- max(n2$radius)#
		max3 <- max(n3$radius)#
		min1 <- min(n1$radius)#
		min2 <- min(n2$radius)#
		min3 <- min(n3$radius)#
#
		r.st <- c(min1, min2, min3) #
		axst <- c(90, 210, 330)#
		x0a = p2cX(r.st, axst)#
		y0a = p2cY(r.st, axst)#
#
		r.end <- c(max1, max2, max3)#
		axend <- c(90, 210, 330)#
		x1a = p2cX(r.end, axend)#
		y1a = p2cY(r.end, axend)#
	#
	#
	#
		md <- max(abs(c(x0a, y0a, x1a, y1a)))*1.2 #
		grid.newpage()#
		grid.rect(gp=gpar(fill="black"))#
		vp <- viewport(x = 0.5, y = 0.5, width = 1, height = 1,#
			xscale = c(-md, md), yscale = c(-md, md), name = "3DHivePlot")#
		pushViewport(vp)#
#
#
	#
#
#
	#
		#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 1) & (nodes$axis[id2] == 2)) {#
				th.st <- c(th.st, 90)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 210)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
				#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = 0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 2) & (nodes$axis[id2] == 3)) {#
				th.st <- c(th.st, 210)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 330)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
		#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = 0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 3) & (nodes$axis[id2] == 1)) {#
				th.st <- c(th.st, 330)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 90)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = 0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 1) & (nodes$axis[id2] == 3)) {#
				th.st <- c(th.st, 90)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 330)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = -0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 3) & (nodes$axis[id2] == 2)) {#
				th.st <- c(th.st, 330)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 210)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
		#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = -0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 2) & (nodes$axis[id2] == 1)) {#
				th.st <- c(th.st, 210)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 90)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
				#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = -0.5)#
			}#
	#
	#
		grid.segments(x0a, y0a, x1a, y1a,#
			gp = gpar(col = HPD$axis.cols, lwd = 3),#
			default.units = "native")#
	#
	#
	#
		if (dr.nodes) {#
			r <- c(n1$radius, n2$radius, n3$radius) #
			theta <- c(rep(90, length(n1$radius)),#
				rep(210, length(n2$radius)),#
				rep(330, length(n3$radius)))#
			x = p2cX(r, theta)#
			y = p2cY(r, theta)#
			grid.points(x, y, pch = 20, gp = gpar(cex = nodes$size, col = nodes$color))#
			}#
#
		} #
	#
#
#
#
	#
	#
	if (nx == 4) {#
		#
		n1 <- subset(nodes, axis == 1)#
		n2 <- subset(nodes, axis == 2)#
		n3 <- subset(nodes, axis == 3)#
		n4 <- subset(nodes, axis == 4)#
		max1 <- max(n1$radius)#
		max2 <- max(n2$radius)#
		max3 <- max(n3$radius)#
		max4 <- max(n4$radius)#
		min1 <- min(n1$radius)#
		min2 <- min(n2$radius)#
		min3 <- min(n3$radius)#
		min4 <- min(n4$radius)#
#
		r.st <- c(min1, min2, min3, min4) #
		axst <- c(90, 180, 270, 0)#
		x0a = p2cX(r.st, axst)#
		y0a = p2cY(r.st, axst)#
#
		r.end <- c(max1, max2, max3, max4)#
		axend <- c(90, 180, 270, 0)#
		x1a = p2cX(r.end, axend)#
		y1a = p2cY(r.end, axend)#
	#
	#
	#
		md <- max(abs(c(x0a, y0a, x1a, y1a)))*1.2 #
		grid.newpage()#
		grid.rect(gp=gpar(fill="black"))#
		vp <- viewport(x = 0.5, y = 0.5, width = 1, height = 1,#
			xscale = c(-md, md), yscale = c(-md, md), name = "3DHivePlot")#
		pushViewport(vp)#
#
	#
#
#
	#
		#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 1) & (nodes$axis[id2] == 2)) {#
				th.st <- c(th.st, 90)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 180)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
				#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = 0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 2) & (nodes$axis[id2] == 3)) {#
				th.st <- c(th.st, 180)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 270)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
		#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = 0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 3) & (nodes$axis[id2] == 4)) {#
				th.st <- c(th.st, 270)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 0)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
		#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = 0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 4) & (nodes$axis[id2] == 1)) {#
				th.st <- c(th.st, 0)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 90)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = 0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 1) & (nodes$axis[id2] == 4)) {#
				th.st <- c(th.st, 90)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 0)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = -0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 4) & (nodes$axis[id2] == 3)) {#
				th.st <- c(th.st, 0)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 270)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
		#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = -0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 3) & (nodes$axis[id2] == 2)) {#
				th.st <- c(th.st, 270)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 180)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
				#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = -0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 2) & (nodes$axis[id2] == 1)) {#
				th.st <- c(th.st, 180)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 90)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
				#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = -0.5)#
			}#
#
	#
	#
		grid.segments(x0a, y0a, x1a, y1a,#
			gp = gpar(col = HPD$axis.cols, lwd = 3),#
			default.units = "native")#
	#
	#
	#
		if (dr.nodes) {#
			r <- c(n1$radius, n2$radius, n3$radius, n4$radius) #
			theta <- c(rep(90, length(n1$radius)),#
				rep(180, length(n2$radius)),#
				rep(270, length(n3$radius)),#
				rep(0, length(n4$radius)))#
			x = p2cX(r, theta)#
			y = p2cY(r, theta)#
			grid.points(x, y, pch = 20, gp = gpar(cex = nodes$size, col = nodes$color))#
			}#
#
		} #
	#
#
#
	#
	#
	if (nx == 5) {#
		#
		n1 <- subset(nodes, axis == 1)#
		n2 <- subset(nodes, axis == 2)#
		n3 <- subset(nodes, axis == 3)#
		n4 <- subset(nodes, axis == 4)#
		n5 <- subset(nodes, axis == 5)#
		max1 <- max(n1$radius)#
		max2 <- max(n2$radius)#
		max3 <- max(n3$radius)#
		max4 <- max(n4$radius)#
		max5 <- max(n5$radius)#
		min1 <- min(n1$radius)#
		min2 <- min(n2$radius)#
		min3 <- min(n3$radius)#
		min4 <- min(n4$radius)#
		min5 <- min(n5$radius)#
#
		r.st <- c(min1, min2, min3, min4, min5) #
		axst <- c(90, 162, 234, 306, 18)#
		x0a = p2cX(r.st, axst)#
		y0a = p2cY(r.st, axst)#
#
		r.end <- c(max1, max2, max3, max4, max5)#
		axend <- c(90, 162, 234, 306, 18)#
		x1a = p2cX(r.end, axend)#
		y1a = p2cY(r.end, axend)#
	#
	#
	#
		md <- max(abs(c(x0a, y0a, x1a, y1a)))*1.2 #
		grid.newpage()#
		grid.rect(gp=gpar(fill="black"))#
		vp <- viewport(x = 0.5, y = 0.5, width = 1, height = 1,#
			xscale = c(-md, md), yscale = c(-md, md), name = "3DHivePlot")#
		pushViewport(vp)#
#
	#
#
#
	#
		#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 1) & (nodes$axis[id2] == 2)) {#
				th.st <- c(th.st, 90)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 162)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
				#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = 0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 2) & (nodes$axis[id2] == 3)) {#
				th.st <- c(th.st, 162)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 234)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
		#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = 0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 3) & (nodes$axis[id2] == 4)) {#
				th.st <- c(th.st, 234)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 306)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
		#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = 0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 4) & (nodes$axis[id2] == 5)) {#
				th.st <- c(th.st, 306)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 18)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
		#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = 0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 5) & (nodes$axis[id2] == 1)) {#
				th.st <- c(th.st, 18)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 90)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
		#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = 0.5)#
			}#
#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 1) & (nodes$axis[id2] == 5)) {#
				th.st <- c(th.st, 90)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 18)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = -0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 5) & (nodes$axis[id2] == 4)) {#
				th.st <- c(th.st, 18)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 306)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = -0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 4) & (nodes$axis[id2] == 3)) {#
				th.st <- c(th.st, 306)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 234)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
		#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = -0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 3) & (nodes$axis[id2] == 2)) {#
				th.st <- c(th.st, 234)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 162)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
				#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = -0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 2) & (nodes$axis[id2] == 1)) {#
				th.st <- c(th.st, 162)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 90)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
				#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = -0.5)#
			}#
#
	#
	#
		grid.segments(x0a, y0a, x1a, y1a,#
			gp = gpar(col = HPD$axis.cols, lwd = 3),#
			default.units = "native")#
	#
	#
	#
		if (dr.nodes) {#
			r <- c(n1$radius, n2$radius, n3$radius, n4$radius, n5$radius) #
			theta <- c(rep(90, length(n1$radius)),#
				rep(162, length(n2$radius)),#
				rep(234, length(n3$radius)),#
				rep(306, length(n4$radius)),#
				rep(18, length(n5$radius)))#
			x = p2cX(r, theta)#
			y = p2cY(r, theta)#
			grid.points(x, y, pch = 20, gp = gpar(cex = nodes$size, col = nodes$color))#
			}#
#
		} #
#
#
#
	#
	#
	if (nx == 6) {#
		#
		n1 <- subset(nodes, axis == 1)#
		n2 <- subset(nodes, axis == 2)#
		n3 <- subset(nodes, axis == 3)#
		n4 <- subset(nodes, axis == 4)#
		n5 <- subset(nodes, axis == 5)#
		n6 <- subset(nodes, axis == 6)#
		max1 <- max(n1$radius)#
		max2 <- max(n2$radius)#
		max3 <- max(n3$radius)#
		max4 <- max(n4$radius)#
		max5 <- max(n5$radius)#
		max6 <- max(n6$radius)#
		min1 <- min(n1$radius)#
		min2 <- min(n2$radius)#
		min3 <- min(n3$radius)#
		min4 <- min(n4$radius)#
		min5 <- min(n5$radius)#
		min6 <- min(n6$radius)#
#
		r.st <- c(min1, min2, min3, min4, min5, min6) #
		axst <- c(90, 150, 210, 270, 330, 390)#
		x0a = p2cX(r.st, axst)#
		y0a = p2cY(r.st, axst)#
#
		r.end <- c(max1, max2, max3, max4, max5, max6)#
		axend <- c(90, 150, 210, 270, 330, 390)#
		x1a = p2cX(r.end, axend)#
		y1a = p2cY(r.end, axend)#
	#
	#
	#
		md <- max(abs(c(x0a, y0a, x1a, y1a)))*1.2 #
		grid.newpage()#
		grid.rect(gp=gpar(fill="black"))#
		vp <- viewport(x = 0.5, y = 0.5, width = 1, height = 1,#
			xscale = c(-md, md), yscale = c(-md, md), name = "3DHivePlot")#
		pushViewport(vp)#
#
	#
#
#
	#
		#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 1) & (nodes$axis[id2] == 2)) {#
				th.st <- c(th.st, 90)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 150)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
				#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = 0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 2) & (nodes$axis[id2] == 3)) {#
				th.st <- c(th.st, 150)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 210)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
		#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = 0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 3) & (nodes$axis[id2] == 4)) {#
				th.st <- c(th.st, 210)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 270)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
		#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = 0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 4) & (nodes$axis[id2] == 5)) {#
				th.st <- c(th.st, 270)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 330)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
		#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = 0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 5) & (nodes$axis[id2] == 6)) {#
				th.st <- c(th.st, 330)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 390)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
		#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = 0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 6) & (nodes$axis[id2] == 1)) {#
				th.st <- c(th.st, 390)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 90)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
		#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = 0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 1) & (nodes$axis[id2] == 6)) {#
				th.st <- c(th.st, 90)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 390)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
		#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = -0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 6) & (nodes$axis[id2] == 5)) {#
				th.st <- c(th.st, 390)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 330)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = -0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 5) & (nodes$axis[id2] == 4)) {#
				th.st <- c(th.st, 330)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 270)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = -0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 4) & (nodes$axis[id2] == 3)) {#
				th.st <- c(th.st, 270)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 210)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
		#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = -0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 3) & (nodes$axis[id2] == 2)) {#
				th.st <- c(th.st, 210)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 150)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
				#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = -0.5)#
			}#
#
	#
	#
		r.st <- r.end <- th.st <- th.end <- ecol <- ewt <- c()#
			#
		for (n in 1:nrow(edges)) {#
			#
			pat1 <- paste("\\b", edges$id1[n], "\\b", sep = "") #
			pat2 <- paste("\\b", edges$id2[n], "\\b", sep = "")#
			id1 <- grep(pat1, nodes$id)#
			id2 <- grep(pat2, nodes$id)#
			#
			if ((nodes$axis[id1] == 2) & (nodes$axis[id2] == 1)) {#
				th.st <- c(th.st, 150)#
				r.st <- c(r.st, nodes$radius[id1])#
				th.end <- c(th.end, 90)#
				r.end <- c(r.end, nodes$radius[id2])#
				}#
				#
			ecol <- c(ecol, edges$color[n])#
			ewt <- c(ewt, edges$weight[n])#
			}#
		#
		x0 = p2cX(r.st, th.st)#
		y0 = p2cY(r.st, th.st)#
		x1 = p2cX(r.end, th.end)#
		y1 = p2cY(r.end, th.end)#
#
		if (!length(x0) == 0) {#
			grid.curve(x0, y0, x1, y1,#
				default.units = "native", ncp = 5, square = FALSE,#
				gp = gpar(col = ecol, lwd = ewt), curvature = -0.5)#
			}#
#
	#
	#
		#
			#
			#
#
		grid.segments(x0a, y0a, x1a, y1a,#
			gp = gpar(col = HPD$axis.cols, lwd = 3),#
			default.units = "native")#
	#
	#
	#
		if (dr.nodes) {#
			r <- c(n1$radius, n2$radius, n3$radius, n4$radius,#
				n5$radius, n6$radius) #
			theta <- c(rep(90, length(n1$radius)),#
				rep(150, length(n2$radius)),#
				rep(210, length(n3$radius)),#
				rep(270, length(n4$radius)),#
				rep(330, length(n5$radius)),#
				rep(390, length(n6$radius)))#
			x = p2cX(r, theta)#
			y = p2cY(r, theta)#
			grid.points(x, y, pch = 20, gp = gpar(cex = nodes$size, col = nodes$color))#
			}#
#
		} #
#
	#
	}
plotHive(t4, method = "scale", action = c(0.5, 1, 1, 1))
