adegraphics/ 0000755 0001762 0000144 00000000000 14774713152 012537 5 ustar ligges users adegraphics/tests/ 0000755 0001762 0000144 00000000000 14511210167 013664 5 ustar ligges users adegraphics/tests/s1d.match.R 0000644 0001762 0000144 00000000271 13742303021 015566 0 ustar ligges users library(adegraphics)
pdf("s1d.match.pdf")
g1 <- s1d.match(-5:5, 2 * (-5:5))
g2 <- s1d.match(rnorm(10), runif(10), p1d.hor = FALSE)
g3 <- s1d.match(1:5, 7:11, p1d.hor = F, p1d.rev = T)
adegraphics/tests/s1d.hist.R 0000644 0001762 0000144 00000005656 13742303021 015455 0 ustar ligges users library(ade4)
library(adegraphics)
pdf("s1d.hist.pdf")
set.seed(40)
x1 <- rnorm(1000)
g11 <- s1d.hist(x1)
g12 <- s1d.hist(x1, col = 1:10)
g13 <- s1d.hist(x1, col = FALSE, ppoly.col = 1:10)
g14 <- s1d.hist(x1, col = TRUE, ppoly.col = "blue")
set.seed(50)
x1 <- rnorm(1000)
g21 <- s1d.hist(x1) # p1d.hori = TRUE and p1d.reverse = FALSE by default
# g22 <- s1d.hist(x1, p1d.hori = TRUE, p1d.rev = TRUE)
g23 <- s1d.hist(x1, p1d.hori = FALSE, p1d.rev = FALSE)
# g24 <- s1d.hist(x1, p1d.hori = FALSE, p1d.rev = TRUE)
# randtest.pcaiv
data(rpjdl, package = "ade4")
millog <- log(rpjdl$mil + 1)
coa1 <- dudi.coa(rpjdl$fau, scann = FALSE)
caiv1 <- pcaiv(coa1, millog, scan = FALSE)
set.seed(50)
rd11 <- randtest(caiv1)
plot(rd11)
set.seed(50)
rd12 <- randtest(caiv1, output = "full")
plot(rd12, nclass = 15) # must be the same output as rd11
set.seed(50)
rd13 <- randtest(caiv1, output = "full")
plot(rd13, nclass = 8)
plot(rd13, nclass = 8, plines.col = "red")
plot(rd13, nclass = 8, obs.plines.col = "red")
plot(rd13, nclass = 8, sim.plines.col = "red")
# randtest.dpcoa
data(humDNAm, package = "ade4")
dpcoahum <- dpcoa(data.frame(t(humDNAm$samples)), sqrt(humDNAm$distances), scan = FALSE, nf = 2)
set.seed(50)
rd21 <- randtest(dpcoahum)
plot(rd21)
rd22 <- randtest(dpcoahum, output = "full")
plot(rd22)
# randtest.amova (plot.krandtest)
amovahum <- amova(humDNAm$samples, sqrt(humDNAm$distances), humDNAm$structures)
set.seed(50)
rd31 <- randtest(amovahum, 49)
plot(rd31)
plot(rd31, plines.col = "red")
plot(rd31, g1.plines.col = "red")
set.seed(50)
rd32 <- randtest(amovahum, 49, output = "full")
plot(rd32)
plot(rd32, plines.col = "red")
plot(rd32, g1.plines.col = "red")
plot(rd32, nclass = 30, g2.pback.col = "lightblue")
# randtest.coinertia
data(doubs, package = "ade4")
dudi1 <- dudi.pca(doubs$env, scale = TRUE, scan = FALSE, nf = 3)
dudi2 <- dudi.pca(doubs$fish, scale = FALSE, scan = FALSE, nf = 2)
coin1 <- coinertia(dudi1,dudi2, scan = FALSE, nf = 2)
set.seed(50)
rd4 <- randtest(coin1)
plot(rd4)
# randtest.pcaivortho
data(rpjdl, package = "ade4")
millog <- log(rpjdl$mil + 1)
coa1 <- dudi.coa(rpjdl$fau, scann = FALSE)
caiv1 <- pcaiv(coa1, millog, scan = FALSE)
set.seed(50)
rd5 <- randtest(caiv1)
plot(rd5)
# randtest.rlq (plot.krandtest)
data(aviurba, package = "ade4")
coa1 <- dudi.coa(aviurba$fau, scannf = FALSE, nf = 2)
dudimil <- dudi.hillsmith(aviurba$mil, scannf = FALSE, nf = 2, row.w = coa1$lw)
duditrait <- dudi.hillsmith(aviurba$traits, scannf = FALSE, nf = 2, row.w = coa1$cw)
rlq1 <- rlq(dudimil, coa1, duditrait, scannf = FALSE, nf = 2)
set.seed(50)
rd6 <- randtest(rlq1)
plot(rd6)
# randtest.between
data(meaudret, package = "ade4")
pca1 <- dudi.pca(meaudret$env, scan = FALSE, nf = 3)
set.seed(50)
rd7 <- randtest(bca(pca1, meaudret$design$season, scan = FALSE), 99)
plot(rd7, main = "Monte-Carlo test")
# randtest.discrimin
set.seed(50)
rd8 <- randtest(discrimin(pca1, meaudret$design$season, scan = FALSE), 99)
plot(rd8, main = "Monte-Carlo test")
adegraphics/tests/adegraphics.R 0000644 0001762 0000144 00000002565 13742303021 016266 0 ustar ligges users library(adegraphics)
pdf("adegraphics.pdf")
xy <- cbind.data.frame(runif(7), runif(7))
g1 <- s.label(xy)
data(olympic, package = "ade4")
pca <- ade4::dudi.pca(olympic$tab, scan = FALSE)
g2 <- s.corcircle(pca$co, lab = names(olympic$tab))
g3 <- ADEgS(list(g1, g2), rbind(c(0, 0, 0.5, 1), c(0.5, 0, 1, 1)))
g4 <- ADEgS(list(g1, g2), layout = c(1, 2)) ## the same as g3
g4b <- ADEgS(list(g1, g2)) ## the same as g3
g5 <- s.label(xy, plabels.cex = 0, paxes.draw = TRUE, ppoints.col = "red")
g6 <- superpose(g1, g5, plot = TRUE)
g6b <- s.density(xy)
g7 <- superpose(s.density(xy), g5, plot = TRUE)
g8 <- superpose(s.label(xy, plabels.boxes.col = "orange", plot = FALSE),
s.label(xy, plabels.cex = 0, paxes.draw = TRUE, ppoints.col = "red", plot = FALSE),
plot = TRUE)
g9 <- g8[1, drop = TRUE]
class(g9)
g10 <- g8[1, drop = FALSE]
class(g10)
g11 <- ADEgS(list(g8, g3), positions = rbind(c(0, 0, 0.5, 1), c(0.5, 0, 1, 1)))
## cbindADEgS - rbindADEgS
g12 <- cbindADEg(g1, g2, plot = TRUE) ## the same as g3
g13 <- cbindADEg(g8, g3, plot = TRUE) ## the same as g11
g14 <- rbindADEg(g8, g3, plot = TRUE)
data(banque, package = "ade4")
banque.acm <- ade4::dudi.acm(banque, scann = FALSE, nf = 3)
g15 <- score(banque.acm, which = which(banque.acm$cr[, 1] > 0.2), plot = FALSE)
g15 <- g15[[1]]
cbindADEg(g15[[1]], g15[[2]], plot = TRUE) ## work on trellis object
adegraphics/tests/s.class.R 0000644 0001762 0000144 00000002410 13742303021 015347 0 ustar ligges users library(adegraphics)
pdf("s.class.pdf")
xy0 <- cbind.data.frame(x = runif(20, -1, 1), y = runif(20, -1, 6))
basic <- s.class(xy0, fac = factor(rep(c("A", "B"), le = 20)), chull = 0, star = 0)
xy1 <- cbind.data.frame(x = runif(200, -1, 1), y = runif(200, -1, 6))
fac1 <- factor(xy1$x > 0) : factor(xy1$y > 0)
g1 <- s.class(xy1, fac = fac1, storeData = F, col = 1:4, pbackground.box = T, pbackground.col = grey(0.85), paxes.draw = T, ell = 0)
## multiaxis
xy2 <- cbind.data.frame(x = runif(200, -1, 1), y = runif(200, -2, 2), y2 = runif(200, -0.5, .5))
fac2 <- factor(xy2$x > 0)
g2 <- s.class(xy2, fac = fac2, xax = 1, yax = 2:3, storeData = F, plot = F)
print(g2)
## insertion
print(ADEgS(list(g1, g2), posi = rbind(c(0, 0, 1, 1), c(0.7, 0.5, 1, 0.9))))
## color test
g3 <- s.class(xy1, fac = fac2, psub.text = "Graphic 3", "ppoints.col" = 1:5, plabels.boxes = list(col = "white", alpha = 0.8), pellipses.col = 1:5, col = 1:5)
## test convex hull and parameters
xy4 <- cbind.data.frame(x = runif(200, -1, 1), y = runif(200, -1, 1))
fac4 <- factor(xy4$x > 0) : factor(xy4$y > 0)
col <- c("black", "red", "green", "blue")
g4 <- s.class(xy4, fac4, ppoints.cex = 1.5, chull = T, ellipseSize = 0, starSize = 0, ppolygon = list(border = 4:1, col = 1:4, lty = 1:4, lwd = 2, alpha = 0.4))
adegraphics/tests/s.corcircle.R 0000644 0001762 0000144 00000000670 13742303021 016215 0 ustar ligges users library(adegraphics)
pdf("s.corcircle.pdf")
data(olympic, package = "ade4")
dudi1 <- ade4::dudi.pca(olympic$tab, scan = FALSE) # a normed PCA
g1 <- s.corcircle(dudi1$co, lab = names(olympic$tab))
g2 <- s.corcircle(dudi1$co, lab = names(olympic$tab), fullcircle = T)
g3 <- s.corcircle(dudi1$co, lab = names(olympic$tab), fullcircle = FALSE)
g4 <- s.corcircle(dudi1$co, lab = names(olympic$tab), pback.col = "red", pbackground.box = FALSE)
adegraphics/tests/s.match.R 0000644 0001762 0000144 00000000727 13742303021 015347 0 ustar ligges users library(adegraphics)
pdf("s.match.pdf")
X <- data.frame(x = runif(50, -1, 2), y = runif(50, -1, 2))
Y <- X + rnorm(100, sd = 0.3)
g1 <- s.match(X, Y, ppoints.cex = 0, col = c("blue", "red"))
g2 <- s.match(X, Y, arr = FALSE, ppoints.cex = 2, ppoints.col = c("blue", "green"))
g3 <- s.match(X, Y, arr = FALSE)
g4 <- s.match(X, Y, arrows = TRUE, plabels = list(alpha = 1, col = "black", cex = 1), plines = list(col = "red"), panel.background = list(col = "antiquewhite"))
adegraphics/tests/s1d.boxplot.R 0000644 0001762 0000144 00000002161 13742303021 016161 0 ustar ligges users library(adegraphics)
pdf("s1d.boxplot.pdf")
## ex1
x <- c(rnorm(10), rnorm(10))
fact <- factor(rep(c("A", "B"), 10))
g11 <- s1d.boxplot(x, fact)
g12 <- s1d.boxplot(x, fact, col = TRUE)
g12 <- s1d.boxplot(x, fact, col = 2:3)
g12 <- s1d.boxplot(x, fact, col = TRUE, plines.col = "black")
g2 <- s1d.boxplot(x, fact, ppolygon.border = c("red", "blue"), box.rectangle = list(alpha = 1, fill = "green"))
## ex2
w1 <- rnorm(100, -1)
w2 <- rnorm(100)
w3 <- rnorm(100, 1)
f1 <- gl(3, 100)
f2 <- gl(30, 10)
g3 <- s1d.boxplot(c(w1, w2, w3), f1)
g4 <- s1d.boxplot(c(w1, w2, w3), f2)
g5 <- s1d.boxplot(c(w1, w2, w3), f2, p1d.rug.draw = FALSE)
mat <- matrix(0, ncol = 1, nrow = 8)
mat[c(2), ] <- 1
mat[c(3:8), ] <- 2
mat[1, ] <- 3
g6 <- ADEgS(c(g3, g4, s1d.label(c(w1, w2, w3), p1d = list(rug = list(tck = 0.8), rev = TRUE), ppoints.cex = 0, plabels.cex = 0, plot = F, pgrid.draw = F)),
layout = matrix((rev(mat)), ncol = 1))
g7 <- s1d.boxplot(c(w1, w2, w3), data.frame(f1, f2))
## ex3
data(banque, package = "ade4")
banque.acm <- ade4::dudi.acm(banque, scan = FALSE, nf = 4)
s1d.boxplot(banque.acm$l1[, 1], banque[, 1:7], plabels.cex = 1.8)
adegraphics/tests/s.logo.R 0000644 0001762 0000144 00000001416 13742303021 015207 0 ustar ligges users library(adegraphics)
pdf("s.logo.pdf")
## ex1
data(ggtortoises, package = "ade4")
ico <- ggtortoises$ico[as.character(ggtortoises$pop$carap)]
g1 <- s.logo(ggtortoises$pop, ico, pori.incl = FALSE)
g2 <- s.label(ggtortoises$pop, add = TRUE, plabels = list(boxes = list(alpha = 0.4, border = "transparent")))
## ex2
data(capitales, package = "ade4")
index <- unlist(lapply(1:15, function(i) which(names(capitales$logo) == tolower(rownames(capitales$xy)[i]))), use.names = FALSE)
g3 <- s.logo(capitales$xy, capitales$logo[index])
x <- c(0, max(capitales$area$x))
y <- c(0, max(capitales$area$y))
#g4 <- s.image(cbind(x, y), z = c(1, 2), outsideLimits = capitales$area, grid = 500, regions = list(col = "yellow", alpha = 0.9))
#s.logo(capitales$xy, capitales$logo[index], add = TRUE)
adegraphics/tests/s1d.density.R 0000644 0001762 0000144 00000002642 13742303021 016155 0 ustar ligges users library(adegraphics)
pdf("s1d.density.pdf")
set.seed(40)
x1 <- rnorm(1000)
g11 <- s1d.density(x1)
g12 <- s1d.density(x1, col = FALSE, ppoly.col = "blue", p1d.rev = TRUE)
g13 <- s1d.density(x1, col = TRUE, ppoly.col = "blue", p1d.hori = FALSE)
g14 <- s1d.density(x1, col = TRUE, p1d.hori = FALSE, p1d.rev = TRUE)
update(g11, ppolygons.border = "red")
update(g11, col = FALSE, ppolygons.col = "black")
update(g11, ppolygons.lwd = 3, ppolygons.lty = 3, ppolygons.alpha = 1)
update(g11, ylim = c(-0.04, 0.5))
set.seed(50)
x2 <- c(rnorm(1000, mean = -0.5, sd = 0.5), rnorm(1000, mean = 1))
fact <- rep(c("A", "B"), each = 1000)
g21 <- s1d.density(x2, fact, col = c("red", "blue"))
g22 <- s1d.density(x2, fact, col = FALSE, ppoly.col = 2:3)
g23 <- s1d.density(x2, fact, col = FALSE, ppoly.col = 2:3, p1d.rev = TRUE)
g24 <- s1d.density(x2, fact, col = FALSE, ppoly.col = 2:3, p1d.horizontal = FALSE)
g25 <- s1d.density(x2, fact, col = FALSE, ppoly.col = 2:3, p1d.horizontal = FALSE, p1d.rev = TRUE)
set.seed(60)
x3 <- rnorm(1000)
g31 <- s1d.density(x3)
g32 <- s1d.density(x3, p1d.rug.draw = FALSE)
g33 <- s1d.density(x3, p1d.rug.draw = FALSE, p1d.rev = TRUE)
g34 <- s1d.density(x3, p1d.rug.draw = FALSE, p1d.hori = FALSE)
g35 <- s1d.density(x3, p1d.rug.draw = FALSE, p1d.hori = FALSE, p1d.rev = TRUE)
update(g31, p1d.rev = TRUE)
update(g32, p1d.rev = TRUE)
update(g33, p1d.rev = FALSE)
update(g34, p1d.rev = TRUE)
update(g35, p1d.rev = FALSE)
adegraphics/tests/add.R 0000644 0001762 0000144 00000022314 14413500612 014537 0 ustar ligges users library(adegraphics)
pdf("add.pdf")
set.seed(40)
########################### add.ADEg ##############################
data(granulo, package = "ade4")
df <- data.frame(t(apply(granulo$tab, 1, function(x) x / sum(x))))
pca <- ade4::dudi.pca(df, scal = FALSE, scan = FALSE)
g1 <- s.arrow(ade4::dudi.pca(data.frame(df), scan = F, nf = 2)$co)
g2 <- s.label(pca$li, plabels.cex = 0.5, plabels.col = "blue", plot = F)
g3 <- add.ADEg(g2)
g4 <- s.label(pca$c1, plabels.col = "red", add = T)
g5 <- s.arrow(pca$c1, plabels.cex = 1.5, plot = FALSE)
g6 <- ADEgS(list(g1 = g1, g5 = g5), layout = c(1, 2))
update(g6, pback.col = "lightblue", g1.plabels.cex = 2, g5.plabels.col = "red")
############################## addhist ##############################
dfxy1 <- matrix(rnorm(200), ncol = 2)
gh1 <- s.label(dfxy1)
gh2 <- addhist(gh1)
dfxy2 <- dfxy1
dfxy2[, 2] <- dfxy2[, 2] + rnorm(100, 2)
gh3 <- s.label(dfxy2)
gh4 <- addhist(gh3, plot.polygon = list(col = "red"))
data(rpjdl, package = "ade4")
coa1 <- ade4::dudi.coa(rpjdl$fau, scannf = FALSE, nf = 4)
gh5 <- s.label(coa1$li)
gh6 <- addhist(gh5)
############################## addtext ##############################
# on a ADEg
addtext(g1, -1, 1, "Data Granulo", plabels.cex = 1.5, plabels.col = "red")
addtext(g1, -1, 1, c("Data", "Granulo"), plabels.cex = 1.5, plabels.col = c("red", "blue")) # the two labels are superposed
addtext(g1, -1, 1, c("Data", "Granulo"), plabels.cex = 1.5, plabels.col = "red") # the two labels are superposed
addtext(g1, c(-1, -0.5), 1, "Data Granulo", plabels.cex = 1.5, plabels.col = c("red", "blue"))
addtext(g1, c(-1, -0.5), 1, c("Data", "Granulo"), plabels.cex = 1.5, plabels.col = c("red", "blue"))
addtext(g1, -1, c(1, 0.9), c("Data", "Granulo"), plabels.cex = 1.5, plabels.col = "red")
addtext(g1, -1, c(1, 0.9), c("Data", "Granulo"), plabels.cex = c(1.5, 2), plabels.col = "red")
data(dunedata, package = "ade4")
afc1 <- ade4::dudi.coa(dunedata$veg, scannf = FALSE)
g7 <- table.value(dunedata$veg, symbol = "circle", ppoints.cex = 0.5, plot = FALSE)
addtext(g7, 1, 20, "A", plabels.srt = 45, plabels.boxes.draw = FALSE)
# on a ADEgS: juxtaposition
addtext(g6, 0.5, 0.5, "Text added", plabels.col = "blue", which = 1)
addtext(g6, 0.5, 0.5, "Text added", plabels.col = c("blue", "green"), which = 2)
addtext(g6, 0.5, 0.5, "Text added", plabels.col = c("green4", "blue"), which = 2)
addtext(g6, 0.5, 0.5, "Text added", plabels.col = "blue", which = 1:2)
addtext(g6, 0.5, 0.5, "Text added", plabels.col = c("green4", "blue"))
addtext(g6, c(0.7, -0.5), c(0.2, -0.4), "Text added", plabels.col = "blue", plabels.cex = 1.2, which = 1:2)
addtext(g6, c(0.7, -0.5), c(0.2, -0.4), "Text added", plabels.cex = c(0.5, 1.5), plabels.col = c("blue", "green4"))
xy2 <- cbind.data.frame(x = runif(200, -1, 1), y = runif(200, -2, 2), y2 = runif(200, -0.5, 0.5))
fac2 <- factor(xy2$x > 0)
g9 <- s.class(xy2, fac = fac2, xax = 1, yax = 2:3, plot = FALSE)
addtext(g9, 0, 0, "A", plabels.col = "red", plabels.cex = 2)
addtext(g9, c(-2.1, -1.07), c(2, 1), c("A", "B"), plabels.col ="red", plabels.cex = 2, which = 1:2)
addtext(g9, c(-2.1, -1.07), c(2, 1), c("A", "B"), plabels.col = c("green4", "red"), plabels.cex = c(3, 2), which = 1:2)
# on a ADEgS: facets
xy <- cbind.data.frame(x = runif(200, -1, 1), y = runif(200, -1, 1))
posi <- factor(xy$x > 0) : factor(xy$y > 0)
g10 <- s.class(xy, fac = posi, facets = posi, pellipses.col = 1:4, plabels.cex = 0, plegend.drawKey = FALSE, psub.cex = 0, plot = FALSE)
addtext(g10, c(0.5, 0.5, -0.5, -0.5), c(0.5, -0.5), levels(posi), plabels.cex = 2, plabels.col = 1:4)
############################## addline ##############################
# on a 2D plot
g11 <- s.label(cbind(rnorm(100), rnorm(100)), plot = FALSE)
addline(g11, 0, 1, plines = list(col = "red", lwd = 2, lty = 2))
addline(g11, h = 1, plines.col = "chartreuse4", plines.lwd = 3)
addline(g11, v = c(-1, 1), plines.col = "cadetblue", plines.lwd = 3)
# on a 1D plot
g12 <- s1d.label(rnorm(10), plot = FALSE)
addline(g12, v = 1, plines.col = "chartreuse4", plines.lwd = 3)
# on a ADEgS: juxtaposition
g13 <- ADEgS(c(g11, g11), plot = FALSE)
addline(g13, 0, 1, which = 1, plines.col = "red")
addline(g13, 0, 1, which = 2, plines.col = "red")
addline(g13, 0, 1, which = 1:2, plines.col = "red")
addline(g13, 0, 1, plines.col = "red")
addline(g13, h = 1, plines.col = "red")
addline(g13, h = c(1, -1), plines.col = "red")
addline(g13, v = c(-1, 1), plines.col = "red")
addline(g13, v = c(-1, 1), plines.col = 2:3)
addline(g13, c(0.7, -0.5), c(0.2, -0.4), which = 1:2, plines.col = "red")
addline(g13, c(0.7, -0.5), c(0.2, -0.4), which = 1, plines.col = "red")
addline(g13, 0.7, 0.2, which = 1, plines.col = "red")
addline(g13, 0.7, -0.5, which = 1, plines.col = "red")
xy2 <- cbind.data.frame(x = runif(200, -1, 1), y = runif(200, -2, 2), y2 = runif(200, -0.5, 0.5))
fac2 <- factor(xy2$x > 0)
g9 <- s.class(xy2, fac = fac2, xax = 1, yax = 2:3, plot = FALSE)
addline(g9, 1, 0, "A", plines.col = "red", plabels.cex = 2)
addline(g9, c(-2.1, -1.07), c(2, 1), plines.col ="red", which = 1:2)
addline(g9, c(-2.1, -1.07), c(2, 1), plines.col = c("green4", "red"))
# on a ADEgS: facets
xy <- cbind.data.frame(x = runif(200, -1, 1), y = runif(200, -1, 1))
posi <- factor(xy$x > 0) : factor(xy$y > 0)
g10 <- s.class(xy, fac = posi, facets = posi, pellipses.col = 1:4, plabels.cex = 0, plegend.drawKey = FALSE, psub.cex = 0, plot = FALSE)
addline(g10, 0, c(0.5, -0.5), plines.col = 1:4)
############################## addpoint ##############################
# on a 2D plot
g11 <- s.label(cbind(rnorm(100), rnorm(100)), ylab = "y axis label",
paxes.draw = TRUE, plot = FALSE)
addpoint(g11, 2, 2, ppoints.col = "coral", ppoints.pch = "*", ppoints.cex = 4)
addpoint(g11, c(1, 2), c(1, 2), ppoints.col = "brown2")
addpoint(g11, 1, c(1, 2), ppoints.col = "cyan3")
# on a 1D plot
g12 <- s1d.density(rnorm(1000), paxes.draw = TRUE, plot = FALSE)
addpoint(g12, 2, 0, ppoints.col = "brown4", ppoints.cex = 3)
g12 <- s1d.density(rnorm(1000), plot = FALSE, ylab = "y axis label")
addpoint(g12, 2, 0, ppoints.col = "brown4", ppoints.cex = 3)
# on a ADEgS: juxtaposition
g13 <- ADEgS(c(g11, g11), plot = FALSE)
addpoint(g13, 2, 2, which = 1, ppoints.col = "cyan3")
addpoint(g13, 2, 2, which = 2, ppoints.col = "cyan3")
addpoint(g13, 2, 2, which = 1:2, ppoints.col = "cyan3")
addpoint(g13, 2, 2, ppoints.col = "cyan3")
addpoint(g13, c(1, 2), 2, ppoints.col = "cyan3")
addpoint(g13, 2, c(1, 2), ppoints.col = "cyan3")
xy2 <- cbind.data.frame(x = runif(200, -1, 1), y = runif(200, -2, 2), y2 = runif(200, -0.5, 0.5))
fac2 <- factor(xy2$x > 0)
g9 <- s.class(xy2, fac = fac2, xax = 1, yax = 2:3, plot = FALSE)
addpoint(g9, 1, 0, ppoints.col = "red", ppoints.cex = 2)
addpoint(g9, c(1, -1), 0, ppoints.col = "red", ppoints.cex = 2)
addpoint(g9, 0, c(1, -1), ppoints.col = "red", ppoints.cex = 2)
# on a ADEgS: facets
xy <- cbind.data.frame(x = runif(200, -1, 1), y = runif(200, -1, 1))
posi <- factor(xy$x > 0) : factor(xy$y > 0)
g10 <- s.class(xy, fac = posi, facets = posi, pellipses.col = 1:4, plabels.cex = 0, plegend.drawKey = FALSE, psub.cex = 0, plot = FALSE)
addpoint(g10, 0, c(0.5, -0.5), ppoints.col = 1:4, ppoints.cex = 3)
############################## addsegment ##############################
# on a 2D plot
g11 <- s.label(cbind(rnorm(100), rnorm(100)), paxes.draw = TRUE, plot = FALSE)
addsegment(g11, 0, 2, 0, -2, plines = list(col = "brown2", lwd = 3, lty = 2))
addsegment(g11, c(0, 1), 2, 0, -2, plines = list(col = "brown2", lwd = 3, lty = 2))
addsegment(g11, c(0, 1), 2, c(0, 1), -2, plines = list(col = c("cyan3", "brown2"), lwd = 3, lty = 2))
addsegment(g11, -2, -2, 2, 2, plines = list(col = "brown2", lwd = 3, lty = 2))
addsegment(g11, -2, 2, 2, -2, plines = list(col = "cyan3", lwd = 3, lty = 2))
g12 <- s.label(cbind(rnorm(100), rnorm(100)), ylab = "y axis label", plot = FALSE)
addsegment(g12, 0, 2, 0, -2, plines = list(col = "brown2", lwd = 3, lty = 2))
addsegment(g12, -2, -2, 2, 2, plines = list(col = "brown2", lwd = 3, lty = 2))
addsegment(g12, -2, 2, 2, -2, plines = list(col = "cyan3", lwd = 3, lty = 2))
# on a 1D plot
g13 <- s1d.density(rnorm(1000), paxes.draw = TRUE, ylab = "ylab", plot = FALSE)
addsegment(g13, 2, 0, 2, 0.2, plines.col = 1, plines.lwd = 3)
# on a ADEgS: juxtaposition
g14 <- ADEgS(c(g11, g11), plot = FALSE)
addsegment(g14, 1, 2, 1, -2, which = 1, plines.col = "brown2")
addsegment(g14, 1, 2, 1, -2, which = 2, plines.col = "brown2")
addsegment(g14, c(0, 1), 2, c(0, 1), -2, which = 1:2, plines.col = "brown2")
addsegment(g14, 1, 2, c(0, 1), -2, which = 1:2, plines.col = "brown2")
addsegment(g14, 1, 2, 1, -2, plines.col = "brown2")
xy2 <- cbind.data.frame(x = runif(200, -1, 1), y = runif(200, -2, 2), y2 = runif(200, -0.5, 0.5))
fac2 <- factor(xy2$x > 0)
g9 <- s.class(xy2, fac = fac2, xax = 1, yax = 2:3, plot = FALSE)
addsegment(g9, 1, 0, 1, 0.5, plines.col = "red", plines.lwd = 2)
addsegment(g9, 1, -1, 0, 1, plines.col = "red", plines.lwd = 2)
addsegment(g9, 0, 1, -1, 1, plines.col = "red", plines.lwd = 2)
# on a ADEgS: facets
xy <- cbind.data.frame(x = runif(200, -1, 1), y = runif(200, -1, 1))
posi <- factor(xy$x > 0) : factor(xy$y > 0)
g10 <- s.class(xy, fac = posi, facets = posi, pellipses.col = 1:4, plabels.cex = 0, plegend.drawKey = FALSE, psub.cex = 0, plot = FALSE)
addsegment(g10, c(-0.5, 0.5), c(0.5, -0.5), c(-0.5, 0.5), 1, plines.col = 1:4, plines.lwd = 3)
adegraphics/tests/s.distri.R 0000644 0001762 0000144 00000003513 13742303021 015545 0 ustar ligges users library(adegraphics)
pdf("s.distri.pdf")
xy5 <- cbind.data.frame(x = runif(200, -1, 1), y = runif(200, -1, 1))
w1 <- as.numeric((xy5$x > 0) & (xy5$y > 0))
w2 <- ((xy5$x > 0) & (xy5$y < 0)) * (1 - xy5$y) * xy5$x
w3 <- ((xy5$x < 0) & (xy5$y > 0)) * (1 - xy5$x) * xy5$y
w4 <- ((xy5$x < 0) & (xy5$y < 0)) * xy5$y * xy5$x
distri <- data.frame(a = w1 / sum(w1), b = w2 / sum(w2), c = w3 / sum(w3), d = w4 / sum(w4))
g5 <- s.distri(xy5, distri, plabels.boxes = list(col = "white", alpha = 1), plabels.cex = 2, plabels.col = 1:5)
data(rpjdl, package = "ade4")
xy6 <- ade4::dudi.coa(rpjdl$fau, scan = FALSE)$li + 3
g6 <- s.distri(xy6, rpjdl$fau[, 5], ellipseSize = 1.5, psub = list(text = rpjdl$frlab[5], cex = 2, pos = c(0.2, 0.1)))
g7 <- s.distri(xy6, rpjdl$fau[, 5], ellipseSize = 1.5, psub = list(text = rpjdl$frlab[5], cex = 2, pos = c(0.2, 0.1)), porigin = list(include = FALSE), pellipses.axes.col = "blue")
## test add
g8 <- s.distri(xy6, rpjdl$fau[, 5], ellipseSize = 1.5, psub = list(text = rpjdl$frlab[5], cex = 2, pos = c(0.2, 0.1)), porigin.include = FALSE, pellipses = list(col = "blue"))
g9 <- s.distri(xy6, rpjdl$fau[, 12], ellipseSize = 1.5, psub = list(text = rpjdl$frlab[5], cex = 2, pos = c(0.2, 0.1)), porigin.include = FALSE, pellipses = list(col = "red"), add = TRUE)
show(g9) ## g8 is a superposition, an ADEgS object
## add
index <- c(1, 5, 8, 20, 21, 23, 26, 33, 36, 44, 47, 49)
col <- colorRampPalette(c("blue", "red", "orange"))(49)
s.distri(xy6, rpjdl$fau[, 1], ellipseSize = 1, starSize = 0, porigin.include = FALSE, pellipses = list(col = col[1], alpha = 0.3))
for(i in index[-1])
s.distri(xy6, rpjdl$fau[, i], ellipseSize = 1, starSize = 0, porigin.include = FALSE, pellipses = list(col = col[i], alpha = 0.3), add = TRUE)
current <- get("currentadeg", env = adegraphics:::.ADEgEnv)
print(current[[6]])
length(current) == length(index) adegraphics/tests/s.density.R 0000644 0001762 0000144 00000002110 13742303021 015716 0 ustar ligges users library(adegraphics)
pdf("s.density.pdf")
xx1 <- rnorm(1000, 1, 2)
yy1 <- rnorm(1000, 1, 2)
g1 <- s.density(cbind(xx1, yy1), paxes.draw = T, gridsize = c(40, 40))
g2 <- s.density(cbind(xx1, yy1), paxes.draw = T, gridsize = c(80, 80), col = colorRampPalette(c("red", "blue"))(58), storeData = FALSE, region = TRUE)
g3 <- s.density(cbind(yy1 + 3, xx1 + 3), gridsize = c(400, 400))
g4 <- s.density(cbind(xx1, yy1), paxes.draw = T, gridsize = c(200, 200), add = TRUE)
g5 <- s.density(cbind(c(rnorm(50000, 1, 1), rnorm(50000, -1, 1)), c(rnorm(50000, -1, 0.5), rnorm(50000, 1, 0.5))), paxes.draw = T, gridsize = c(200, 200), region = TRUE, contour = TRUE, plabels.cex = 1, plabels.srt = "vertial")
g6 <- s.density(cbind(rnorm(300, 3, 0.3), rnorm(300, -2, 0.5)), gridsize = c(500, 500), thres = 0.01, nr = 10, regions = list(alpha = 0.5), col = colorRampPalette(c("red", "blue"))(108))
g7 <- s.density(cbind(c(rnorm(50000, 1, 1), rnorm(50000, -1, 1)), c(rnorm(50000, -1, 0.5), rnorm(50000, 1, 0.5))), paxes.draw = T, gridsize = c(100, 100), region = TRUE, contour = TRUE, plabels.cex = 1, nclass = 5)
adegraphics/tests/s.traject.R 0000644 0001762 0000144 00000001013 13742303021 015674 0 ustar ligges users library(adegraphics)
pdf("s.traject.pdf")
rw <- function(a){
x <- 0
for(i in 1:49)
x <- c(x, x[length(x)] + runif(1, -1, 1))
x
}
x <- unlist(lapply(1:5, rw), use.names = FALSE)
y <- unlist(lapply(1:5, rw), use.names = FALSE)
z <- gl(5, 50)
g1 <- s.traject(data.frame(x, y), z, ppoints.pch = 19:23, plines.col = rainbow(5))
x <- unlist(lapply(1:2, rw), use.names = FALSE)
y <- unlist(lapply(1:2, rw), use.names = FALSE)
z <- gl(2, 50)
g2 <- s.traject(data.frame(x, y), z, ppoints.pch = 21:20, plines.col = 1:2)
adegraphics/tests/s1d.class.R 0000644 0001762 0000144 00000002461 13742303021 015602 0 ustar ligges users library(adegraphics)
pdf("s1d.class.pdf")
data(meau, package = "ade4")
## ex1
envpca <- ade4::dudi.pca(meau$env, scannf = FALSE)
g1 <- s1d.class(envpca$li[, 1], poslab = "value", meau$design$season, col = 1:6)
update(g1, p1d.horizontal = FALSE)
update(g1, p1d.reverse = TRUE)
g2 <- s1d.class(envpca$li[, 1], meau$design$season, col = 1:6, p1d.reverse = TRUE)
g3 <- s1d.class(envpca$li[, 1], meau$design$season, col = 1:6, p1d.hori = F)
## ex2
set.seed(0)
score1 <- c(rnorm(3, mean = 0, sd = 0.5), rnorm(3, mean = 1, sd = 0.5), rnorm(5, mean = 2, sd = 0.5))
factor1 <- factor(rep(LETTERS[1:3], times = c(3, 3, 5)))
g41 <- s1d.class(score1, factor1)
g42 <- s1d.class(score1, factor1, col = 1:3)
g43 <- s1d.class(score1, factor1, col = TRUE)
g44 <- s1d.class(score1, factor1, col = FALSE)
g45 <- s1d.class(score1, factor1, plines.col = "grey")
g46 <- s1d.class(score1, factor1, plines.col = "grey", col = TRUE)
## ex3
score2 <- c(rnorm(10, mean = 0, sd = 0.5), rnorm(15, mean = -1, sd = 0.2), rnorm(10, mean = 2, sd = 0.5))
factor2 <- factor(rep(c(1, 3, 2), times = c(10, 15, 10)))
levels(factor2) <- c("mean0", "mean2", "mean-1")
g5 <- s1d.class(score2, factor2, col = 1:3)
update(g5, posla = "value")
indx <- rank(rnorm(35))
factor2 <- factor2[rank(indx)]
s1d.class(score2[indx], factor2[indx], col = 1:3, posla = "regular")
adegraphics/tests/panelSpatial.R 0000644 0001762 0000144 00000010263 14516703533 016437 0 ustar ligges users library(ade4)
library(adegraphics)
library(sp)
pdf("panelSpatial.pdf")
## ex1
data(mafragh, package = "ade4")
dfxy1 <- coordinates(mafragh$Spatial)
g1 <- s.label(dfxy1, Sp = mafragh$Spatial, pSp.col = colorRampPalette(c("yellow", "blue"))(97), pgrid.draw = FALSE, plabels.cex = 0)
## ex2
data(meuse, package = "sp")
coordinates(meuse) <- ~ x + y
data(meuse.grid, package = "sp")
m <- SpatialPixelsDataFrame(points = meuse.grid[c("x", "y")], data = meuse.grid)
data(meuse.riv)
meuse.sr <- SpatialPolygons(list(Polygons(list(Polygon(meuse.riv)), "meuse.riv")))
scale1 <- list("SpatialPolygonsRescale", offset = c(179900, 329600), scale = 500, fill = c("transparent", "black"), layout.scale.bar())
text11 <- list("sp.text", c(179900, 329700), "0")
text21 <- list("sp.text", c(180400, 329700), "500 m")
arrow1 <- list("SpatialPolygonsRescale", offset = c(178750, 332500), scale = 400, layout.north.arrow())
river <- list("sp.polygons", meuse.sr, fill = "lightblue")
dfxy2 <- as.data.frame(coordinates(meuse))
g2 <- s.value(dfxy2, z = meuse[, 1]$cadmium, sp.layout = list(scale1, text11, text21, arrow1, river), Sp = m)
fac <- meuse@data$ffreq
levels(fac)[1] <- "1 in 2 years"
levels(fac)[2] <- "1 in 10 years"
levels(fac)[3] <- "1 in 50 years"
arrow2 <- list("SpatialPolygonsRescale", layout.north.arrow(), offset = c(181750, 330000), scale = 400)
scale2 <- list("SpatialPolygonsRescale", layout.scale.bar(), offset = c(178050, 333600), scale = 500, fill = c("transparent", "black"))
text12 <- list("sp.text", c(178050, 333700), "0")
text22 <- list("sp.text", c(178550, 333700), "500 m")
g3 <- s.class(dfxy2, fac = fac, sp.layout = list(scale2, text12, text22, arrow2, river), starSize = 1, col = c(1, 2, 4), pellipses.col = c(1, 2, 4),
pellipses.alpha = 0.7, plines.lty = 3, psub.text = "Flooding frequency \n near the Meuse river", psub.pos = c(0.2, 0.88), pgrid.text.cex = 0,
porigin.include = FALSE, Sp = meuse.sr)
## ex3
if(require(Guerry)) {
data(gfrance85)
dfxy4 <- coordinates(gfrance85)
region.names <- data.frame(gfrance85)[, 5]
col.region <- colors()[c(149, 254, 468, 552, 26)]
g4 <- s.class(dfxy4, region.names, ellip = 0, star = 0, col = col.region, Sp = gfrance85, pSp.col = col.region[region.names], porig.inclu = F)
}
## ex4
library(sp)
library(lattice)
data(elec88, package = "ade4")
sp <- elec88$Spatial
g5 <- xyplot(1 ~ 1, xlim = bbox(sp)[1, ], ylim = bbox(sp)[2, ], panel = function(...) {adeg.panel.Spatial(SpObject = sp, col = "black", border = "black")})
g6 <- xyplot(1 ~ 1, xlim = bbox(sp)[1, ], ylim = bbox(sp)[2, ], panel = function(...) {adeg.panel.Spatial(sp, col = 1:14, border = "black")})
g7 <- xyplot(1 ~ 1, xlim = bbox(sp)[1, ], ylim = bbox(sp)[2, ], aspect = "iso", panel = function(...) {sp.polygons(sp, col = "black", fill = 1:5)})
g8 <- xyplot(1 ~ 1, xlim = bbox(sp)[1, ], ylim = bbox(sp)[2, ], panel = function(...) {adeg.panel.Spatial(SpObject = sp, col = "black", border = "blue")})
g9 <- xyplot(1 ~ 1, xlim = bbox(sp)[1, ], ylim = bbox(sp)[2, ], panel = function(...) {adeg.panel.Spatial(SpObject = sp, col = "black", border = "blue")})
#g10 <- s.label(cbind(-80, 35), Sp = nc)
#g11 <- s.label(cbind(-80, 35), Sp = sp)
## ex5
data(jv73, package = "ade4")
g12 <- s.label(jv73$xy, Sp = jv73$Spatial)
g13 <- s.label(jv73$xy, Sp = jv73$Spatial, pSp.col = "red")
spoints <- SpatialPoints(jv73$xy)
g14 <- s.label(jv73$xy, Sp = spoints, plab.cex = 0, ppoin.cex = 0, pSp.col = 1)
sgrid <- SpatialGrid(GridTopology(c(0, 0), c(1, 1), c(3, 5)))
xyplot(0:5 ~ 0:3, panel = function(...) sp.grid(sgrid, col = 1:2))
nc <- SpatialGridDataFrame(getGridTopology(sgrid), data = data.frame(matrix(1:15, ncol = 1)))
xyplot(0:5 ~ 0:3, panel = function(...) sp.grid(nc, col = 1, at = pretty(rnorm(15), 2), col.region = 2:3))
xyplot(0:5 ~ 0:3, panel = function(...) adeg.panel.Spatial(nc, col = 1:3))
xyplot(0:5 ~ 0:3, panel = function(...) adeg.panel.Spatial(nc, col = 1:2))
## ex6
mysp <- SpatialPointsDataFrame(matrix(rnorm(20), 10), data.frame(matrix(rnorm(20), 10)))
s.Spatial(mysp)
s.Spatial(mysp, col = c("red", "blue"))
s.Spatial(mysp, ppoints.cex = 2)
s.Spatial(mysp, ppoints.alpha = 0.5)
s.Spatial(mysp, symbol = "circle")
s.Spatial(mysp, method = "color", ppalette.quanti = colorRampPalette(c("red", "white", "blue"))) adegraphics/tests/s.value.R 0000644 0001762 0000144 00000003575 13742303021 015373 0 ustar ligges users library(adegraphics)
pdf("s.value.pdf")
## ex1
xy <- cbind.data.frame(x = runif(50, -1, 1), y = runif(50, 0, 2))
z <- rnorm(50)
z <- sapply(z, function(X) max(X, -3))
z <- sapply(z, function(X) min(X, 3))
val1 <- s.value(xy, z, method = "size", symbol = "square", plot = F)
val2 <- s.value(xy, z, method = "color", symbol = "square", plot = F)
val3 <- s.value(xy, z, method = "size", symbol = "circle", plot = F)
val4 <- s.value(xy, z, method = "color", symbol = "circle", plot = F)
g1 <- ADEgS(c(val1, val2, val3, val4), positions = layout2position(matrix(c(1, 2, 3, 4), 2, 2)), add = matrix(0, ncol = 4, nrow = 4))
g2 <- s.value(xy, z, method = "color", symbol = "square", breaks = c(-3, -1, -0.5, 0, 0.5, 1, 3))
g3 <- s.value(xy, z, method = "color", col = colorRampPalette(c("yellow", "blue"))(6))
g4 <- s.value(xy, z, method = "size", symbol = "circle", paxes.draw = FALSE)
## ex2
xx <- runif(100) * 100
yy <- 1:100
zz <- 1:100
breaks <- c(0, 25, 50, 75, 100)
g5 <- s.value(data.frame(xx, yy), zz, breaks = breaks, method = "color", paxes.draw = TRUE, porigin.include = FALSE)
g6 <- s.value(data.frame(xx, yy), cbind(zz, rev(zz)), breaks = breaks, method = "color", col = c("blue", "red", "green", "yellow"), paxes.draw = TRUE)
g7 <- s.value(data.frame(xx, yy), cbind(zz, rev(zz)), nclass = c(2, 6), method = "color", col = c("blue", "red", "pink", "green", "yellow"), paxes.draw = TRUE)
## ex3
data(rpjdl, package = "ade4")
fau.coa <- ade4::dudi.coa(rpjdl$fau, scan = FALSE, nf = 3)
val5 <- s.value(fau.coa$li, fau.coa$li[,3], plot = FALSE)
val6 <- s.value(fau.coa$li, fau.coa$li[, 3], center = 0, method = "size", symbol = "circle", col = c("yellow", "red"), plot = FALSE)
g8 <- ADEgS(c(val5, val6), positions = layout2position(matrix(c(1, 2), 1, 2)), add = matrix(0, ncol = 2, nrow = 2))
## ex3
data(doubs, package = "ade4")
g9 <- s.value(doubs$xy, doubs$env[, 1:2])
g10 <- s.value(doubs$xy, doubs$env)
adegraphics/tests/s1d.barchart.R 0000644 0001762 0000144 00000001756 13742303021 016271 0 ustar ligges users library(ade4)
library(adegraphics)
pdf("s1d.barchart.pdf")
## 1 : reverse and horizontal
set.seed(40)
x1 <- rnorm(10)
g11 <- s1d.barchart(x1)
g12 <- s1d.barchart(x1, ppoly.col = "blue")
g21 <- s1d.barchart(x1, p1d.hori = FALSE, p1d.rev = TRUE)
g23 <- s1d.barchart(x1, p1d.hori = FALSE, p1d.rev = FALSE)
g24 <- s1d.barchart(x1, p1d.hori = TRUE, p1d.rev = TRUE)
g24 <- s1d.barchart(x1, p1d.hori = TRUE, p1d.rev = FALSE)
## 2 : at and sort
data(rpjdl, package = "ade4")
rpjdl.coa <- ade4::dudi.coa(rpjdl$fau, scannf = FALSE, nf = 4)
nam <- rownames(rpjdl.coa$co)
gg1 <- s1d.barchart(rpjdl.coa$co[, 1])
gg2 <- s1d.barchart(rpjdl.coa$co[, 1], labels = nam, at = 51:1)
gg3 <- s1d.barchart(rpjdl.coa$co[, 1], labels = nam, sort = TRUE)
gg4 <- s1d.barchart(rpjdl.coa$co[, 1], labels = nam, sort = TRUE, at = 51:1) # 'at' is ignored
gg5 <- s1d.barchart(rpjdl.coa$co, labels = nam, sort = TRUE)
gg6 <- s1d.barchart(rpjdl.coa$co, labels = nam, sort = FALSE)
stopifnot(gg6[[1]]@data$labels == gg6[[2]]@data$labels)
adegraphics/tests/s.image.R 0000644 0001762 0000144 00000001722 13742303021 015331 0 ustar ligges users library(adegraphics)
library(sp)
pdf("s.image.pdf")
## ex1
xy <- data.frame(expand.grid(-3:3, -3:3))
names(xy) <- c("x", "y")
z <- (1 / sqrt(2)) * exp(-(xy$x ^ 2 + xy$y ^ 2) / 2)
s.image(xy, z)
s.image(xy, z, grid = 20)
s.image(xy, z, grid = 500)
## ex2
Sr1 <- Polygon(cbind(c(0, 1, 2, 1, 2, 0 , -2, -1, -2, -1, 0), c(2.5, 1.5, 2, 0, -2, -1, -2, 0, 2, 1.5, 2.5)))
Srs1 <- Polygons(list(Sr1), ID = "stars")
SPp1 <- SpatialPolygons(list(Srs1))
xy1 <- cbind(rnorm(100, 0, 1), rnorm(100, 0, 1.5))
g1 <- s.image(xy1, runif(100), outsideLimits = SPp1)
## ex3
Sr2 <- Polygon(cbind(c(-0.5, 0.5, 0.5, -0.5, -0.5), c(0, 0, 1 ,1, 0)), hole = TRUE)
Srs2 <- Polygons(list(Sr1, Sr2), ID = "hole")
SPp2 <- SpatialPolygons(list(Srs2))
xy2 <- cbind(c(rnorm(2000, 1, 0.25), rnorm(3000, -1, 1.5)), c(rnorm(2000, 1, 0.5), rnorm(3000, -1, 3)))
z <- c(rnorm(2000, 12, 1), rnorm(3000, 1, 2))
g2 <- s.image(xy2, z, outsideLimits = SPp2, grid = 500, xlim = c(-2.5, 2.5), ylim = c(-2, 3))
adegraphics/tests/s.arrow.R 0000644 0001762 0000144 00000002226 13742303021 015401 0 ustar ligges users library(adegraphics)
pdf("s.arrow.pdf")
## ex1 : from tdr641
data(doubs, package = "ade4")
dudi1 <- ade4::dudi.pca(doubs$env, scale = T, scan = F, nf = 3)
dudi2 <- ade4::dudi.pca(doubs$fish, scale = T, scan = F, nf = 2)
coin1 <- ade4::coinertia(dudi1, dudi2, scan = F, nf = 2)
g1 <- s.arrow(coin1$l1, plabels.cex = 0.87)
g2 <- s.arrow(coin1$c1, plabels.cex = 1)
## ex2 : from bs81
data(granulo, package = "ade4")
w <- data.frame(t(apply(granulo$tab, 1, function(x) x / sum(x))))
g3 <- s.arrow(ade4::dudi.pca(data.frame(w), scan = F, nf = 2)$co)
wtr <- data.frame(t(w))
wmoy <- data.frame(matrix(apply(wtr, 1, mean), 1))
dudi3 <- ade4::dudi.pca(w, scal = FALSE, scan = FALSE)
wmoy <- ade4::suprow(dudi3, wmoy)$lisup
g4 <- s.arrow(dudi3$c1, plabels.cex = 1.5)
g4 <- s.distri(dudi3$c1, wtr, starSize = 0.33, ellipseSize = 0, add = TRUE, plabels.cex = 1)
g4 <- s.label(wmoy, ppoint.cex = 5, plabels.cex = 0, add = TRUE)
## ex3
data(deug, package = "ade4")
pca1 <- ade4::dudi.pca(deug$tab, scal = FALSE, center = deug$cent, scan = FALSE)
g5 <- s.arrow(40 * pca1$c1)
## ex4
xy <- cbind(rnorm(50), rnorm(50))
g6 <- s.arrow(xy, plabels.cex = 0.9, parrows = list(angle = 20))
adegraphics/tests/s.label.R 0000644 0001762 0000144 00000001732 13742303021 015327 0 ustar ligges users library(adegraphics)
library(grid)
pdf("s.label.pdf")
x0 <- runif(50, -2, 2)
y0 <- runif(50, -2, 2)
z <- x0 ^ 2 + y0 ^ 2
dfxy1 <- data.frame(x0, y0)
g1 <- s.label(dfxy1, label = as.character(z < 1), paxes.draw = TRUE, axis.text = list(col = "grey"))
g2 <- s.label(dfxy1[1, ])
g3 <- s.label(dfxy1[1, ], pori.incl = FALSE)
g4 <- s.label(dfxy1, labels = c("", "MM", "", NA, "ooo"), plabels.optim = TRUE)
g5 <- s.label(dfxy1, labels = as.character(z < 1), psub = list(text = "Subtitle", col = "blue", position = "topleft"), plabels.col = 1:5, pgrid.text.pos = c(unit(0.95, "npc"), unit(0.94, "npc")))
dfxy2 <- cbind(dfxy1, runif(50, -5, 5))
g6 <- s.label(dfxy2, xax = 1, yax = 2:3, paxes.draw = TRUE, paxes.aspectratio = 1.5, plabels.cex = 0.8)
l <- ls()
x1 <- runif(length(l))
x2 <- runif(100)
y1 <- runif(length(l))
y2 <- runif(100)
g7 <- s.label(cbind(x2, y2), labels = as.character((x2 * x2 + y2 * y2) < 1))
g8 <- s.label(cbind(x1, y1), labels = l, add = TRUE, plabels.col = "blue")
adegraphics/tests/s1d.gauss.R 0000644 0001762 0000144 00000002430 13742303021 015613 0 ustar ligges users library(adegraphics)
pdf("s1d.gauss.pdf")
data(meau, package= "ade4")
envpca <- ade4::dudi.pca(meau$env, scannf = FALSE)
dffac <- cbind.data.frame(meau$design$season, meau$design$site)
g11 <- s1d.gauss(envpca$li[, 1], dffac[, 1])
g12 <- s1d.gauss(envpca$li[, 1], dffac[, 1], p1d.rev = TRUE)
g13 <- s1d.gauss(envpca$li[, 1], dffac[, 1], p1d.hori = FALSE)
g14 <- s1d.gauss(envpca$li[, 1], dffac[, 1], p1d.hori = FALSE, p1d.rev = TRUE)
g2 <- s1d.gauss(envpca$li[, 1], dffac[, 1], ppoly.col = 1:4, fill = TRUE, plines.col = 1:4, col = FALSE)
g31 <- s1d.gauss(envpca$li[, 1], dffac[, 2], ppoly.col = 1:4, paxes.draw = TRUE, ylim = c(0, 2), fill = TRUE, p1d.hori = FALSE)
g32 <- s1d.gauss(envpca$li[, 1], dffac[, 2], ppoly.col = 1:4, paxes.draw = TRUE, fill = TRUE, p1d.hori = FALSE)
g4 <- s1d.gauss(envpca$li[, 1], fac = dffac, fill = TRUE, col = 1:5)
g5 <- s1d.gauss(envpca$li[, 1], fac = dffac, fill = TRUE, col = FALSE, ppoly.col = 1:6)
g6 <- s1d.gauss(envpca$li[, 1], fac = dffac[, 1], fill = TRUE, col = 1:6, ppoly.col = 1:6)
g7 <- s1d.gauss(envpca$li[, 1], fac = dffac, fill = TRUE, col = 1:6, ppoly.col = 1:6, steps = 10)
g8 <- s1d.gauss(envpca$li[, 1], dffac[, 2])
update(g11, p1d.reverse = TRUE)
update(g12, p1d.reverse = FALSE)
update(g13, p1d.reverse = TRUE)
update(g14, p1d.reverse = FALSE)
adegraphics/tests/s1d.distri.R 0000644 0001762 0000144 00000001274 13742303021 015774 0 ustar ligges users library(adegraphics)
pdf("s1d.distri.pdf")
## ex1
score <- rnorm(10)
df <- data.frame(matrix(rep(c(1, 2), 10), ncol = 2))
g1 <- s1d.distri(score, df)
## ex2
set.seed(1)
w <- seq(-1, 1, le = 200)
distri <- data.frame(lapply(1:50, function(x) sample(200:1) * ((w >= (- x / 50)) & (w <= x / 50))))
names(distri) <- paste("w", 1:50, sep = "")
g2 <- s1d.distri(w, distri)
g3 <- s1d.distri(w, distri, yrank = TRUE, sdS = 1.5)
g4 <- s1d.distri(w, distri, p1d.rug.draw = FALSE)
g5 <- s1d.distri(w, distri, p1d.reverse = TRUE)
g6 <- s1d.distri(w, distri, p1d.hori = FALSE)
g7 <- s1d.distri(w, distri, p1d.hori = FALSE, p1d.reverse = TRUE)
update(g2, p1d.rug.draw = FALSE)
update(g5, p1d.rug.draw = FALSE)
adegraphics/tests/nbgraph.R 0000644 0001762 0000144 00000000674 14511210167 015437 0 ustar ligges users library(ade4)
library(adegraphics)
library(sp)
library(lattice)
pdf("nbgraph.pdf")
if(require(spdep)) {
data(elec88, package = "ade4")
coords <- sp::coordinates(elec88$Spatial)
xyplot(coords[, 2] ~ coords[, 1],
panel = function(...) {adeg.panel.nb(elec88$nb, coords)})
g1 <- s.label(coords, nb = elec88$nb, porigin.include = F, plabels.cex = 0.7,
ppoints.cex = 2, Sp = elec88$Spatial, pSp.col = "red", pSp.alpha = 0.5)
} adegraphics/tests/triangle.R 0000644 0001762 0000144 00000003736 13742303021 015622 0 ustar ligges users library(adegraphics)
pdf("triangle.pdf")
## ex1
data(euro123, package = "ade4")
dfxyz1 <- rbind.data.frame(euro123$in78, euro123$in86, euro123$in97)
row.names(dfxyz1) <- paste(row.names(euro123$in78), rep(c(1, 2, 3), rep(12, 3)), sep = "")
g1 <- triangle.label(dfxyz1, label = row.names(dfxyz1))
g2 <- triangle.label(euro123$in86, label = row.names(euro123$in78), plab.cex = 0.8)
g3 <- triangle.match(euro123$in78, euro123$in86)
g4 <- triangle.label(rbind.data.frame(euro123$in78, euro123$in86), plab.cex = 1, addaxes = TRUE, psub = list(text = "Principal axis", cex = 2, pos = "topright"))
g5 <- triangle.label(euro123[[1]], min3 = c(0, 0.2, 0.3), max3 = c(0.5, 0.7, 0.8), plabels.cex = 1, label = row.names(euro123[[1]]), addax = TRUE)
g6 <- triangle.label(euro123[[2]], min3 = c(0, 0.2, 0.3), max3 = c(0.5, 0.7, 0.8), label = row.names(euro123[[1]]), addax = TRUE)
g7 <- triangle.label(euro123[[3]], min3 = c(0, 0.2, 0.3), max3 = c(0.5, 0.7, 0.8), label = row.names(euro123[[1]]), addax = TRUE)
g8 <- triangle.label(rbind.data.frame(euro123[[1]], euro123[[2]], euro123[[3]]))
## ex2
dfxyz2 <- cbind.data.frame(a = runif(100), b = runif(100), c = runif(100, 4, 5))
g9 <- triangle.label(dfxyz2)
## ex3
g10 <- triangle.label(dfxyz1)
g11 <- triangle.class(dfxyz1, as.factor(rep("G", 36)), star = 0.5, ellips = 1)
g12 <- triangle.class(dfxyz1, euro123$plan$an)
g13 <- triangle.class(dfxyz1, euro123$plan$pays)
g14 <- triangle.class(dfxyz1, euro123$plan$an, elli = 1, pell.axe.draw = TRUE)
g15 <- triangle.class(dfxyz1, euro123$plan$an, elli = 0, sta = 0, col = c("red", "green", "blue"), pell.axe.draw = TRUE, plab.cex = 2, ppoi.cex = 2, pell.axe.draw = TRUE)
g16 <- triangle.class(dfxyz1, euro123$plan$an, ell = 2, sta = 0.5, pell.axe.draw = TRUE, plab.cex = 1.5)
g17 <- triangle.class(dfxyz1, euro123$plan$an, ell = 0, sta = 1, adjust = FALSE)
g18 <- triangle.class(dfxyz1, euro123$plan$an, ell = 0, sta = 1, chull =c(0.2, 0.25, 0.5, 0.75, 1), adjust = TRUE, showposi = TRUE, col = 10:13, pgrid.draw = FALSE)
adegraphics/tests/table.image.R 0000644 0001762 0000144 00000001614 13742303021 016156 0 ustar ligges users library(adegraphics)
pdf("table.image.pdf")
## ex1
x <- 1:4
y <- 1:4
df <- data.frame(as.matrix(cbind(x, y)))
g1 <- table.image(df, col = 2:4)
update(g1, plegend.drawColorKey = TRUE)
## ex2
df <- matrix(0, 10, 10)
df[1:3, 1:3] <- 5
g2 <- table.image(df)
g3 <- table.image(df, breaks = c(5, 2, 0))
## ex3
data(rpjdl, package = "ade4")
X <- data.frame(t(rpjdl$fau))
Y <- data.frame(t(rpjdl$mil))
coa1 <- ade4::dudi.coa(X, scan = FALSE)
x <- rank(coa1$co[, 1])
y <- rank(coa1$li[, 1])
g4 <- table.image(Y, coordsx = x, coordsy = 1:8, axis.text = list(alpha = 0), pgrid.col = "black", pgrid.lwd = 0.8, col = c("white", "black"), plegend.drawKey = FALSE)
g5 <- table.image(X, coordsx = x, coordsy = y, ptable = list(x = list(tck = 0), y = list(tck = 4)), pleg.drawKey = FALSE, labelsy = paste(" ", row.names(X), sep = ""))
g6 <- ADEgS(list(g4, g5), positions = rbind(c(0, 0, 1, 0.3), c(0, 0.4, 1, 1)))
adegraphics/tests/s1d.label.R 0000644 0001762 0000144 00000001046 13742303021 015552 0 ustar ligges users library(adegraphics)
pdf("s1d.label.pdf")
data(meau, package= "ade4")
envpca <- ade4::dudi.pca(meau$env, scannf = FALSE)
g1 <- s1d.label(envpca$l1[, 1], row.names(envpca$l1))
g2 <- s1d.label(envpca$l1[, 1], row.names(envpca$l1), p1d.hori = F)
g3 <- s1d.label(envpca$l1[, 1], row.names(envpca$l1), plabels.boxes.draw = FALSE, plab.srt = 45, plabel.boxes = list(draw = FALSE))
g4 <- s1d.label(envpca$co[, 1], row.names(envpca$co), p1d.reverse = TRUE, poslabel = "value")
g5 <- s1d.label(envpca$l1[, 1], row.names(envpca$l1), at = 0, plabel.cex = 0)
adegraphics/tests/parameter.R 0000644 0001762 0000144 00000011356 13742303021 015772 0 ustar ligges users library(ade4)
library(adegraphics)
pdf("parameter.pdf")
adegparold <- adegpar()
b1 <- length(adegraphics:::separation(plines = list(col = "blue"), plab.bo.dra = FALSE, plab = list(orien = F))$rest) == 0
b2 <- length(adegraphics:::separation(plines = list(col = "blue", lwd = c(1:5)), parr.end = NA, plab.boxes.dr = FALSE)$rest) == 0
b3 <- length(adegraphics:::separation(plot.li = list(col = "blue", lwd = c(1:5)), par.end = NA, pl.boxes.draw = FALSE, pattern = 1)$rest) == 2
b4 <- length(adegraphics:::separation(plot.li = list(col = "blue", lwd = c(1:5)), par.end = NA, pl.boxes.draw = FALSE, pattern = 0)$rest) == 2
b5 <- length(adegraphics:::separation()) == 2
b6 <- length(adegraphics:::separation(par.sub.text = list("lineheight" = 5), pattern = 1)$rest) == 0
b7 <- names(adegraphics:::separation(toto = "rienavoir!")$rest) == "toto"
b8 <- names(adegraphics:::separation(toto = "rienavoir!", pattern = 1)$rest) == "toto"
l1 <- list(parrow = list(col = "blue", lwd = c(1:5), end = NA), plboxes.draw = FALSE, pattern = 1)
sep1 <- adegraphics:::separation(l1) ## no recognition of "pattern" in a list
l2 <- list("parrow.lwd", "plboxes.draw")
sep2 <- adegraphics:::separation(l2)
sep3 <- adegraphics:::separation("plboxes" = list("draw" = FALSE, "col"))
sep4 <- adegraphics:::separation("plboxes" = list("draw" = FALSE, "col" = 2))
sep5 <- adegraphics:::separation(pla.box = list(col = 1:5))
sep6 <- adegraphics:::separation(pla.box.col = c(1:5))
sep7 <- adegraphics:::separation(pla = list(box.col = 1:5)) ## don't match
## adegpar test
ad1 <- adegpar()
ad2 <- adegpar("paxes.draw")
ad3 <- adegpar("paxes.draw", "psub.cex")
ad4 <- adegpar("psub.cex" = 5)
ad5 <- adegpar("psub.cex" = 5, paxes.draw = FALSE)
ad6 <- adegpar("psub")
ad7 <- adegpar("psub.cex", "plabe.boxes")
ad8 <- adegpar(ppoints = list(col = "yellow"), pgrid.space = 4, plines = list(lwd = c(1:5)))
ad9 <- adegpar(ppoints = list(col = "red"), pgrid = list(nint = 12), plines = list(lwd = c(1:5)))
ad10 <- adegpar("ppoints.col", "pgrid.nint", "plines")
ad11 <- adegpar(paxes = list("x"), pgrid = list("nint", "col"))
ad12 <- adegpar(list(pellip = list(col = "red"), grid.nint = 8, plines = list(lwd = c(1:5))))
ad13 <- adegpar(paxes = list("x"), pgrid = list("nint", "col"), "plines", "pellipse")
ad14 <- adegpar(plegend.drawKey = FALSE)
ad15 <- adegpar(list(paxes = list(col = "white"), pgrid.nint = 6, plines = list(lwd = c(1:5))))
ad16 <- adegpar(paxes = list(x = list(draw = TRUE)))
adegpar(adegparold)
## merging list
l3 <- list(plabels = list(boxes = list(col = "white", alpha = 1)), plabels = list(cex = 2), plabels = list(col = "red"))
adegraphics:::.mergingList(l3)
adegraphics:::.mergingList(list(plabels = list(cex = 3)))
## update parameters in graphics
cha <- rep(LETTERS, length.out = 100)
xy <- cbind.data.frame(runif(length(cha)), runif(length(cha)))
g1 <- s.label(xy, labels = cha, paxes.draw = TRUE, plabels.cex = runif(length(cha), 0.5, 1.5))
update(g1, paxes = list(aspect = "fill", draw = TRUE, x = list(draw = FALSE)),
pgrid = list(col = "black", lwd = 2, lty = 5),
plabels = list(col = 1:4, alpha = 0.5, cex = 2, boxes = list(border = "blue", col = "antiquewhite", alpha = 0.2, lwd = 2.5, lty = 5)))
g2 <- s.label(xy, labels = cha)
update(g2, paxes.draw = FALSE, pgrid = list(col = "blue", lwd = 2, lty = 5, text = list(pos = "bottomright", cex = 2, col = "green")))
update(g2, porigin = list(alpha = 0.5, col = "red", lty = 5 , lwd = 2, origin = c(0.6, 0.1)), pgrid.lwd = 0.5)
update(g2, psub = list(text = "parameters", cex = 2, col = "red", position = "topright"))
update(g2, plabels.cex = 0, ppoints = list(alpha = 0.4, cex = 2, col = "red", fill = "blue", pch = 21))
## from tdr641
data(doubs, package = "ade4")
dudi1 <- ade4::dudi.pca(doubs$env, scale = T, scannf = F, nf = 3)
dudi2 <- ade4::dudi.pca(doubs$fish, scale = T, scannf = F, nf = 2)
coin1 <- ade4::coinertia(dudi1, dudi2, scannf = F, nf = 2)
g3 <- s.arrow(coin1$l1, plabels.cex = .87)
update(g3, plines = list(col = "blue", lwd = 2, lty = 3), parr.end = "both", parr = list(angle = 25, length = 0.5))
## with spatial object
data(elec88, package = "ade4")
g4 <- s.label(elec88$xy, label = as.character(1:nrow(elec88$xy)), porigin.include = FALSE, Sp = elec88$Spatial, pSp.col = colorRampPalette(c("yellow", "blue"))(5), pgrid.draw = TRUE)
update(g4, pSp = list(col = "yellow", border = "blue", lwd = 2, lty = 5, alpha = 0.01)) ## don't match : to solve
## plabels parameter
data(tortues, package = "ade4")
pturtles <- tortues
names(pturtles) <- c("length", "width", "height", "sex")
sex <- pturtles$sex
sexcol <- ifelse(sex == "M", "blue", "red")
measures <- pturtles[, 1:3]
pca1 <- ade4::dudi.pca(measures, scann = FALSE, nf = 3)
g5 <- scatter(pca1, row.plabel.cex = 0, col.plabel.cex = c(1, 2, 3), posieig = "none", col.plabel.col = c("red", "blue", "green"))
adegraphics/tests/ade4-functions.R 0000644 0001762 0000144 00000011107 14520214453 016634 0 ustar ligges users ## delete/remove this file when 'scatter' functions will be removed in ade4
library(adegraphics)
pdf("ade4-functions.pdf")
##################### scatter.dudi
data(deug, package = "ade4")
dd1 <- ade4::dudi.pca(deug$tab, scannf = FALSE, nf = 4)
scatter(dd1, posieig = "bottomright")
scatter(dd1, posieig = "bottomright", plot = T, prop = TRUE)
scatter(dd1, posieig = "none", plot = T)
scatter(dd1, posieig = "bottomleft", plot = T)
scatter(dd1, posieig = "topright", plot = T)
scatter(dd1, posieig = "topleft", plot = T, eig.col = c("white", "blue", "red"))
data(rhone, package = "ade4")
dd1 <- ade4::dudi.pca(rhone$tab, nf = 4, scannf = FALSE)
g1 <- scatter(dd1, sub = "Principal component analysis", row = list(plabels.optim = TRUE), col.pla.boxes.alpha = 0.5)
g1[2, drop = TRUE]
scatter(dd1, row = list(sub = "Principal component analysis", plabels.optim = TRUE), col.pla.boxes.alpha = 0.5)
scatter(dd1, prop = TRUE, ppoints.cex = 0.2, density.plot = TRUE, row = list(threshold = 0.01))
scatter(dd1, posieig = "none")
scatter(dd1, posieig = "bottomright")
scatter(dd1, posieig = c(0.5, 0.5))
scatter(dd1, posieig = c(0.5, 0.5, 1, 1))
##################### scatter.coa
data(housetasks, package = "ade4")
par(mfrow = c(2, 2))
dd2 <- ade4::dudi.coa(housetasks, scan = FALSE)
ade4::scatter(dd2, method = 1, sub = "1 / Standard", posieig = "none")
ade4::scatter(dd2, method = 2, sub = "2 / Columns -> averaging -> Rows", posieig = "none")
ade4::scatter(dd2, method = 3, sub = "3 / Rows -> averaging -> Columns ", posieig = "none")
par(mfrow = c(1, 1))
g1 <- scatter(dd2, method = 1, row.sub = "1 / Standard", posieig = "none", plot = FALSE)
g2 <- scatter(dd2, method = 2, col.sub = "2 / Columns -> averaging -> Rows", posieig = "none", plot = FALSE)
g3 <- scatter(dd2, method = 3, row.sub = "3 / Rows -> averaging -> Columns ", posieig = "none", plot = FALSE)
G <- ADEgS(list(g1, g2, g3), layout = c(2, 2), plot = TRUE)
scatter(dd2, posieig = "none")
scatter(dd2, posieig = "bottomright")
scatter(dd2, posieig = c(0.5, 0.5))
scatter(dd2, posieig = c(0.5, 0.5, 1, 1))
##################### scatter.pco
data(yanomama, package = "ade4")
gen <- ade4::quasieuclid(as.dist(yanomama$gen))
gen1 <- ade4::dudi.pco(gen, scann = FALSE, nf = 3)
scatter(gen1, posieig = "none")
scatter(gen1, posieig = "bottomri")
scatter(gen1, posieig = c(0.5, 0.5))
scatter(gen1, posieig = c(0.5, 0.5, 1, 1))
##################### scatter.nipals
data(doubs, package = "ade4")
acp1 <- ade4::dudi.pca(doubs$env, scannf = FALSE, nf = 2)
nip1 <- ade4::nipals(doubs$env)
scatter(nip1, posieig = "none")
scatter(nip1, posieig = "bottomri")
scatter(nip1, posieig = c(0.5, 0.5))
scatter(nip1, posieig = c(0.5, 0.5, 1, 1))
##################### score.inertia - plot.inertia
data(housetasks, package = "ade4")
coa2 <- ade4::dudi.coa(housetasks, scann = FALSE)
res21 <- ade4::inertia(coa2, row = TRUE, col = FALSE)
plot(res21, posieig = "none")
plot(res21, posieig = "bottomri")
plot(res21, posieig = c(0.5,0.5))
plot(res21, posieig = c(0.5, 0.5, 1, 1))
score(res21, posieig = "none")
score(res21, posieig = "bottomri")
score(res21, posieig = c(0.5, 0.5))
score(res21, posieig = c(0.5, 0.5, 1, 1))
res22 <- ade4::inertia(coa2, row = FALSE, col = TRUE)
plot(res22, posieig = "none")
plot(res22, posieig = "bottomri")
plot(res22, posieig = c(0.5, 0.5))
plot(res22, posieig = c(0.5, 0.5, 1, 1))
score(res22, posieig = "none")
score(res22, posieig = "bottomri")
score(res22, posieig = c(0.5, 0.5))
score(res22, posieig = c(0.5, 0.5, 1, 1))
res23 <- ade4::inertia(coa2, row = TRUE, col = TRUE)
plot(res23, posieig = "none")
plot(res23, posieig = "bottomri")
plot(res23, posieig = c(0.5, 0.5))
plot(res23, posieig = c(0.5, 0.5, 1, 1))
score(res23, posieig = "none")
score(res23, posieig = "bottomri")
score(res23, posieig = c(0.5, 0.5))
score(res23, posieig = c(0.5, 0.5, 2, 2))
data(doubs, package = "ade4")
afc <- ade4::dudi.coa(doubs$fish, scannf = FALSE, nf = 5)
ic <- ade4::inertia.dudi(afc, row.inertia=TRUE, col.inertia=TRUE)
plot(ic, contrib = "abs", threshold = 0.1, type = "label")
plot(ic, contrib="abs", threshold = 0.1, type = "label", xax = 3, yax = 4)
##################### plot.acm
data(lascaux, package = "ade4")
acm1 <- ade4::dudi.acm(lascaux$ornem, sca = FALSE)
p1 <- proc.time()
ade4::scatter(acm1)
Tade4 <- proc.time() - p1
p2 <- proc.time()
plot(acm1, ppoints.cex = 0.3, plot = T)
Tadegraphics <- proc.time() - p2
## faster calculus, longest display than for ade4
##################### plot.fca
data(coleo, package = "ade4")
coleo.fuzzy <- ade4::prep.fuzzy.var(coleo$tab, coleo$col.blocks)
fca1 <- ade4::dudi.fca(coleo.fuzzy, scannf = FALSE, nf = 3)
ade4::scatter(fca1)
plot(fca1)
adegraphics/tests/table.value.R 0000644 0001762 0000144 00000005514 13742303021 016213 0 ustar ligges users library(adegraphics)
pdf("table.value.pdf")
## ex1
data(olympic, package = "ade4")
tab1 <- data.frame(scale(olympic$tab))
pca <- ade4::dudi.pca(tab1, scann = FALSE)
g1 <- table.value(tab1, axis.line = list(col = "blue"), axis.text = list(col = "grey"))
g2 <- table.value(tab1, coordsx = c(1:5, 10:6))
g3 <- table.value(tab1, coordsx = c(1:5, 10:8))
g4 <- table.value(tab1, coordsy = rank(pca$li[, 1]), coordsx = rank(pca$co[, 1]), method = "color")
g5 <- table.value(tab1, coordsy = pca$li[, 1], coordsx = pca$co[, 1], ptable = list(x = list(srt = 90)))
## ex2
data(eurodist)
g61 <- table.value(eurodist)
g62 <- table.value(eurodist, store = TRUE, symbol = "circle")
g63 <- table.value(eurodist, store = FALSE, psub.text = "eurodist", psub.position = c(0, -0.04))
g64 <- table.value(eurodist, ptable.margin = list(b = 17, t = 17, l = 17, r = 17))
g65 <- table.value(eurodist, ptable.x = list(pos = "bottom"),
ptable.margin = list(b = 17, t = 17, l = 17, r = 17))
## ex3
data("doubs", package = "ade4")
tab2 <- as.table(as.matrix(doubs$fish))
g8 <- table.value(tab2)
## ex4
data(chats, package = "ade4")
tab3 <- as.table(as.matrix(data.frame(t(chats))))
coa1 <- ade4::dudi.coa(data.frame(t(chats)), scann = FALSE)
adegparold <- adegpar()
adegpar(ptable = list(x = list(pos = "bottom", srt = 0), y = list(pos = "left")), plegend.drawKey = FALSE)
g9 <- table.value(tab3, meanX = TRUE, ablineX = TRUE)
g10 <- table.value(tab3, meanY = TRUE, ablineY = TRUE)
g11 <- table.value(tab3, coordsx = coa1$c1[, 1], coordsy = coa1$l1[, 1], meanX = TRUE, ablineX = TRUE)
g12 <- table.value(tab3, coordsx = coa1$c1[, 1], coordsy = coa1$l1[, 1], meanY = TRUE, ablineY = TRUE)
g13 <- ADEgS(list(g9, g10, g11, g12), pos = rbind(c(0, 0.5, 0.5, 1), c(0.5, 0.5, 1, 1), c(0, 0, 0.5, 0.5), c(0.5, 0, 1, 0.5)))
adegpar(adegparold)
## ex5
data(rpjdl, package = "ade4")
tab4 <- data.frame(t(rpjdl$fau))
coa2 <- ade4::dudi.coa(tab4, scann = FALSE)
g14 <- table.value(tab4, coordsx = coa2$c1[, 1], coordsy = rank(coa2$l1[, 1]), axis.text = list(cex = 0), labelsy = rpjdl$lalab, plot = F)
## ex6
tab5 <- as.table(matrix(rep(0, 100), 10))
tab5[1:5, 1:5] <- 10
ade4::table.cont(tab5, abmean.x = T, y = 10:1)
g15 <- table.value(tab5, coordsy = 10:1, meanX = T)
g16 <- table.value(tab5, coordsy = 10:1, meanX = T, meanY = TRUE, ablineX = TRUE, ablineY = TRUE)
## ex7
tab6 <- matrix(rep(0, 100), 10)
tab6[1:5, 1:5] <- 20
colnames(tab6) <- LETTERS[1:10]
rownames(tab6) <- LETTERS[1:10]
ade4::table.value(tab6, x = 1:10, y = 10:1)
g17 <- table.value(tab6, coordsx = 1:10, coordsy = 10:1)
g18 <- table.value(tab6, coordsx = 1:10, coordsy = c(1, 2, 5, 6, 8, 9, 10, 3, 4, 7))
## ex8
d <- as.dist(matrix(rep(1:5, 5), 5), upper = TRUE)
attr(d, "Labels") <- c ("A", "B", "C", "D", "E")
g4 <- table.value(d)
## ex9
data(irishdata, package = "ade4")
d.geo <- dist(irishdata$xy.utm)
g5 <- table.value(d.geo)
adegraphics/MD5 0000644 0001762 0000144 00000024561 14774713152 013057 0 ustar ligges users e0670df238e6c4e4f77769832fe4b779 *DESCRIPTION
7a2bb639515e90741a3b754f4dfb53c5 *NAMESPACE
6f74ca1d6869610883364261fdb3a85b *R/ADEg.C1.R
f9398e5cc9c57c5c4b6835dde14f7bc5 *R/ADEg.R
b0d456702948c478289e233bb2d6821c *R/ADEg.S1.R
522e9e371f20c1de07a07d43e8c1c17c *R/ADEg.S2.R
2545695c9bb86d7dff7813f355bb224d *R/ADEg.T.R
b4a31e4d6d66b198dfca50fbb945cdeb *R/ADEg.Tr.R
b79114f2aa3977da3b2c05d4b08129ff *R/ADEgS.R
d6f0c6730a3f5be15659bfe2ce2fb462 *R/C1.barchart.R
1f4103b624811d0b729c057dc6867bc7 *R/C1.curve.R
76136e17a4e5d68fe309c19edc1be83d *R/C1.curves.R
913e0d087fe9131efd6334a8863f17ad *R/C1.density.R
f798f96b582b953940858322f83d8b7e *R/C1.dotplot.R
06da697087e69fb8e9b534408441364c *R/C1.gauss.R
e9057d5301f4fa57dbdaf86117517f71 *R/C1.hist.R
1ca0f312a9aa8ae5be1e1e0845820d87 *R/C1.interval.R
e9fb52648a715b8569c875be01d80fd4 *R/S1.boxplot.R
735ea8ac922bb40b8bda34361b778457 *R/S1.class.R
b7188f7d92e5986ec6c987188978d26d *R/S1.distri.R
49299eab6e71fa09994fc724ded2052f *R/S1.label.R
003a1a9798720cffd544741a9dcab3ec *R/S1.match.R
d2158ec7e703b4b23d779c9b66ef8b07 *R/S2.arrow.R
c9c37b88bee570cb17ddc2d8dfc17b8e *R/S2.class.R
6342c5bb617412bf649c8eaa0a74feda *R/S2.corcircle.R
75fd05b0a8651d3e7afe32b2457d926c *R/S2.density.R
0ae00589ce3d17c1fadfc7dcb154be51 *R/S2.distri.R
483a6225905acc06feea74922668e798 *R/S2.image.R
52ced134bad7a2203ef4e538821080d7 *R/S2.label.R
bdc79dbb85c026ddbaf264e646d4543c *R/S2.logo.R
5fdf0105d4cb987efd8a82d8845d48b6 *R/S2.match.R
1e27841e9bb7f69d78a4e8c7bf95cdb2 *R/S2.traject.R
81d93764f3b498c5b57e185594d58f7e *R/S2.value.R
0e8d0ea82221d74f6b162321d2828f4d *R/T.cont.R
d7c25fac44f6a5db9c083953ee638183 *R/T.image.R
3292aa8a605cc7308c4bb25ce42dbe44 *R/T.value.R
6fcbbe6e3ceb352e806c7d9a06dbcb62 *R/Tr.class.R
a6d51db01e3ba0f57781bb3e37b5c552 *R/Tr.label.R
7a87a5a2046fd344048cbf8314d6c168 *R/Tr.match.R
112a6887d82d2dbaa411cccebf8faccc *R/Tr.traject.R
42a21c2bf26aa6affeefe0625ab711c9 *R/addhist.R
de228249670c7f1395b72653b4549fdc *R/addline.R
89e1632bb6abd57f62906e81ab970a9f *R/addpoint.R
00678a7575a2e72f0949c933b17429dc *R/addsegment.R
22a8e97c6a914d21a231235acc7a92ab *R/addtext.R
39123987eed917bacc4398a6ea9ae0de *R/ade4-kplot.R
c318be0c908e76fbc02879877fa322cb *R/ade4-plot.R
3785c6a0be3039dce3d32a98cb2a4c86 *R/ade4-scatter.R
f33d5c8934cd430652bdb93f2951b2ee *R/ade4-score.R
970d295db2936d608f06cbd2ece30b50 *R/adeGsenv.R
a2a46c68ed91b8cc76b2b9064b76bd82 *R/genericMethod.R
79a5cfbcf1f12f4227465b71ac2fd520 *R/multiplot.R
bfb8ee7f5fa4bd14054bd0606af7b7c8 *R/panelfunctions.R
7277d5d04a6d8fc214c6bb0a754e233f *R/parameter.R
e21a4cb7e6359e8d2d27405328ba61eb *R/s.Spatial.R
758d59e8318503e39061a5cd31fac71f *R/utils.R
0fed2f0f01d422b356f9e4a410f92a6a *R/utilsADEgS.R
cadc907d6b204acff6fd94143b178b4c *R/utilsclass.R
486605c9cd6485291c4e3c7c486b518e *R/utilskey.R
bf8d58f56fec3d532e6611ee839eb1b6 *R/utilstriangle.R
e68e3dad2560bc4e2d8f6a4d36907618 *build/vignette.rds
3f94c9abdede35f61e9df43ddbea1165 *inst/CITATION
5855859bbd73de5bdae1026303d8be3d *inst/doc/FAQ.R
81511e923fe1556c2a022a2fd7362762 *inst/doc/FAQ.Rmd
3683cdd98a65df1bb9b709c1f7dcb33b *inst/doc/FAQ.html
59317f0473bf21768f71e3e98bc44976 *inst/doc/adegraphics.R
67f684730aa8611f93fd01a38a6bb911 *inst/doc/adegraphics.Rmd
300b068e1ee6344a09161328db6d94d2 *inst/doc/adegraphics.html
5598610d87d39c76f4655ded0eb71939 *man/ADEg-class.Rd
04d2d39bbab2e82a441b1dbb4f996e29 *man/ADEg.C1-class.Rd
fe42debb511ab4a929b9029778b4fdac *man/ADEg.S1-class.Rd
fbdf0df2c03ed9297d5e812eef1e68a0 *man/ADEg.S2-class.Rd
911ffe3a951cab8e45199dfb7b3a8e63 *man/ADEg.T-class.Rd
fefb3b817bcb32d08afb0d4d8fc9494c *man/ADEg.Tr-class.Rd
0baa08dcf2af5cb4f5907e6ddf959ac7 *man/ADEgS-class.Rd
ff24343f2c2fe48dee8142b6bbd5b605 *man/ADEgS.Rd
88800e779ad8c04ad63382833233677b *man/C1.barchart-class.Rd
1250e8ac88f1739a8cbf1274e6298467 *man/C1.curve-class.Rd
06cc64ed333d3fc5cdde3ba14f26c559 *man/C1.density-class.Rd
b438e7afdb9592d106ab927d94e1e014 *man/C1.dotplot-class.Rd
3061b29846f210d2aca0e6152d5aca11 *man/C1.gauss-class.Rd
d216ddb2c2b58a05d8f0f72349559ea9 *man/C1.hist-class.Rd
2d6d101a398b8c5e1bd33aaef5df6415 *man/C1.interval-class.Rd
7ae1eadd9adf1ab229886b554d8e698b *man/S1.boxplot-class.Rd
de5f6476be1f6a9ab016c88b91c9bbf7 *man/S1.class-class.Rd
dcdd8a493382df52d7bebf25adc2bdcf *man/S1.distri-class.Rd
ccdf3bc2fe1fa928c01b3e3eb6a1fe77 *man/S1.label-class.Rd
9233128a5129ec98a5b0ffb768d99ec8 *man/S1.match-class.Rd
4fb52e7b683616c6a717ee66d9cb12b4 *man/S2.arrow-class.Rd
6d7135823f31d606678757c428ae0bca *man/S2.class-class.Rd
50c3549ba79a734cf55f0431860ed0db *man/S2.corcircle-class.Rd
64fea9fc12633cfaa5e19d570d60bf2f *man/S2.density-class.Rd
821f8156feee060b07e5031cb4fe4a13 *man/S2.distri-class.Rd
04520e2cf701a51b9af7a8a9e055a7b1 *man/S2.image-class.Rd
425d1128f82830cf8c9e065c21218608 *man/S2.label-class.Rd
5b7cf8c2ceb2e019abcbe8680401630f *man/S2.logo-class.Rd
425abe8b71bbeea2b60618fb6345cf78 *man/S2.match-class.Rd
b55f15033357545e498bd2916eda4a28 *man/S2.traject-class.Rd
99ee1dac269f87545d9d4531bd7892c1 *man/S2.value-class.Rd
8c8e2e372dd37cb0c4993d6c39f90d9f *man/T.cont-class.Rd
1c62778fdcab3fb8c2bbc44979a4b83f *man/T.image-class.Rd
4d9d77163bb26e7bd695048caca831ce *man/T.value-class.Rd
4f00222ee88ee4ee93cf7a98c59723fb *man/Tr.class-class.Rd
eebd649933116bbd0a3d157103e3893c *man/Tr.label-class.Rd
271d927c3968008b8b842a69cd2dd731 *man/Tr.match-class.Rd
5ae2ceb127ac94164bccb3028ad122a5 *man/Tr.traject-class.Rd
0c7b0685e07ffcc4b795eebd2cb3db38 *man/add.ADEg.Rd
1fc0b2b157d5b97948a8e93e31769f5d *man/addhist.Rd
95a74bd74a3336f1d826fc85a78f7007 *man/addline.Rd
8d5f5a7796f7b116d46e1eaaf04ae107 *man/addpoint.Rd
bd3a4ec328c07829413dbf36b60da536 *man/addsegment.Rd
98bf035a866432768e1523cc6d0cca7e *man/addtext.Rd
7663b968ca32d6da4e170a0499a66d4b *man/adeg.panel.Spatial.Rd
dedf78380758f45ca0e207941931bf5d *man/adeg.panel.hist.Rd
9332cd504eb2ceb5dedf28a26e5acc05 *man/adeg.panel.join.Rd
e7c451559023d096b2fc822785bb2527 *man/adeg.panel.label.Rd
73bde03d6c00c0e4244c938172589d5a *man/adeg.panel.nb.Rd
9c0d74adc122976f8d165cf94525a267 *man/adeg.panel.values.Rd
4f71081c62ce518b3f8ce82f6f57ed32 *man/adegpar.Rd
b236f2fcf939e84c32c2f12947a6d646 *man/adegraphics-internal.Rd
882c5772f313893fe395b6b898e969be *man/adegraphics-package.Rd
f67375b3996b3c8475123c129aa99ff8 *man/cbindADEg.Rd
3ff9c210f3c3ff6f1fb07a0824bf8359 *man/changelatticetheme.Rd
3685372b4e0b9847d9cc4c002d245eb4 *man/getcall-methods.Rd
6369ae7778afbed77354e019c2704c3e *man/insert.Rd
349c1d1984cfd9297fc1cd48c1658b7a *man/layout2position.Rd
54125b8cd7e930803ed18aae6196b54a *man/panel-methods.Rd
a1f9efa0f1116423c63e019aef6707b3 *man/plot.Rd
08a95671d2021341fed7f0b41e7db784 *man/plot.inertia.Rd
22f22e39e74120ce0473c5bae267d26d *man/plotEig.Rd
8c1d6460e342bf764802ea0a1b4377e9 *man/prepare-methods.Rd
2968dddcfcfa4d4f42a658b2cbdf7bc1 *man/s.Spatial.Rd
6c34d9ac54550d66665c875b40a09010 *man/s.arrow.Rd
405755d59de8e046df922cde0ed6494c *man/s.class.Rd
62611638daec8c5448a6ce369a715107 *man/s.corcircle.Rd
0d743ad4bc59be66347c21a0a08f24e1 *man/s.density.Rd
4f4b13b10306a004ee688befecb9fe46 *man/s.distri.Rd
f4b7815ef4bcff9c5e014b2e2177e69f *man/s.image.Rd
3bdcb6cb1b937b09c9a5e6ec183b90a1 *man/s.label.Rd
835971ca2fcd623bfca4cb020cd7fc4f *man/s.logo.Rd
7b61953336ea5ce084586e689eb9bce3 *man/s.match.Rd
d27b943fe8bae0ce295e5fd72587dffc *man/s.traject.Rd
de5a2b09ca7820b23ce4fdc372600217 *man/s.value.Rd
198a63b4910c5286868756fc0b943918 *man/s1d.barchart.Rd
9a7a01eed3541b4f8bb4067dd94934f4 *man/s1d.boxplot.Rd
b395fc2c44c262fa62e52fe3a3ec1897 *man/s1d.class.Rd
1e2078d044e58c8ae36ffedd79f751d5 *man/s1d.curve.Rd
0b1b30396480f8d75ba2e7ba972f1dac *man/s1d.curves.Rd
5693ead2c63677e67f0a71ad2d1c6194 *man/s1d.density.Rd
5a837a311c574253054b7852c14569d6 *man/s1d.distri.Rd
b6d20f9b0fec290688e53237f4897d50 *man/s1d.dotplot.Rd
387567a96db26a70afdc6dc84bbb8e6a *man/s1d.gauss.Rd
f978ad297d26ea7934c1b502c6446690 *man/s1d.hist.Rd
06bc6632401967ed221f319f9e087aed *man/s1d.interval.Rd
0f6faa4348634061d0e6fcd5b562ecec *man/s1d.label.Rd
1eb668e640b0ef5f01803e7b054756a7 *man/s1d.match.Rd
62a318294a166b0efca13ab3723763ba *man/setlimits1D.Rd
d521408a977531b8d58c7c7e29ea8f1b *man/sortparamADEg.Rd
e0f5a596dd873f9a49f36532fffef83b *man/superpose.Rd
1b2d4e5770016736118a9cbde8ecde89 *man/table.image.Rd
84885822abf9dd54add96dbff22e64ce *man/table.value.Rd
94b4c00b0ecf6a885f37360e5a363c51 *man/triangle.class.Rd
b3da4bd4af2cd0052020122b32f54463 *man/triangle.label.Rd
f7ac2a54fc22d3d9ea646a5376c8bf9b *man/triangle.match.Rd
1b77d1c084b2bccb1571f651b06212df *man/triangle.traject.Rd
c3afe7c260dd4eca59f03ca2097fafec *man/zoom.Rd
115debefa2f321aaf1696a757e9a4b83 *tests/add.R
48e7d303484712161d4cf18335b7b49b *tests/ade4-functions.R
5e517dea83edac5c1a447f6ed495010a *tests/adegraphics.R
202913bcd9c77982320e544fd8cdc835 *tests/nbgraph.R
4a4ea3813dbbc3e37f037b380b62103f *tests/panelSpatial.R
f89edc95fba7af6ec5f90920e55512a2 *tests/parameter.R
6ffcf224c4cca0787627c920998a151d *tests/s.arrow.R
b44718dd5dfa2320a0e92aa441b579c0 *tests/s.class.R
f9fe8c009eef52db351eac53d520b582 *tests/s.corcircle.R
b887dabc7bbb48a8fccb910d8cb9dea9 *tests/s.density.R
77c9be0b3f529e52718a7fbb892fa7cd *tests/s.distri.R
3aab860f9c8f20cd3126f4f195752a41 *tests/s.image.R
a9bcd29036d786df49807a88d0d63547 *tests/s.label.R
86caf8017c8526619fa999d63e383903 *tests/s.logo.R
89481fdbb48f7152a0a3c8287e0df518 *tests/s.match.R
b11418f95ee8fc6ad79d617175c91efc *tests/s.traject.R
2391641d0049c4e52f28f7fb306400e1 *tests/s.value.R
e4165bdc3aec92cb9308ef825604afdc *tests/s1d.barchart.R
0249418d2c4dd0f0de9d3fac737f65e7 *tests/s1d.boxplot.R
2a99ba9860010454a83d309c30cce4c9 *tests/s1d.class.R
a01a1e74736e70b7c97f7a1f32e5fc57 *tests/s1d.density.R
d923871e6c60ba04e736bb5e5dc9a4bd *tests/s1d.distri.R
cd1ee4bb8abc725fe9eb029172392749 *tests/s1d.gauss.R
de8d985d9eff6b46497e9fb748ffb6fd *tests/s1d.hist.R
8e45493f980b7849afe935d58c240a50 *tests/s1d.label.R
c3348687040f2feb1b3eebeda243807d *tests/s1d.match.R
68cbc8ecd439a481b06c94cdd41cb5e3 *tests/table.image.R
3611ca9b2b3a27ee07755316d98d4e7c *tests/table.value.R
22e0c33678322769bdbd349bdd157368 *tests/triangle.R
81511e923fe1556c2a022a2fd7362762 *vignettes/FAQ.Rmd
67f684730aa8611f93fd01a38a6bb911 *vignettes/adegraphics.Rmd
d9fc6c74dd6f5f6e1d474a1e9d0550fb *vignettes/adegraphics.bib
94e2c4c89709af434aea77d06cae63a7 *vignettes/classes.png
1d77c7392af1b74694a1a360391faf63 *vignettes/gargsVSclass.R
8f602c5d25cda55f1dec6ed200823ab2 *vignettes/gargsVSclass.csv
f2678b6a3b44dfed82563a378d98d086 *vignettes/paramVSfunction.R
2b0090986571a97a477ad4154b503786 *vignettes/paramVSparam.R
f6179df0e8e9082cd6ca1c6b2aa42a3e *vignettes/tableparamVSfunction.csv
adegraphics/R/ 0000755 0001762 0000144 00000000000 14572567407 012746 5 ustar ligges users adegraphics/R/ade4-scatter.R 0000644 0001762 0000144 00000023352 13742303021 015330 0 ustar ligges users "scatter.dudi" <- function(x, xax = 1, yax = 2, permute = FALSE, posieig = "topleft", prop = FALSE,
density.plot = ifelse(permute, ncol(x$tab) > 1000, nrow(x$tab) > 1000), plot = TRUE, storeData = TRUE, pos = -1, ...) {
if(!inherits(x, "dudi"))
stop("Object of class 'dudi' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
position <- .getposition(posieig[1:min(2, length(posieig))])
## sort parameters for each graph
graphsnames <- c("row", "col", "eig")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## parameters management
params <- list()
params$row <- list(plabels = list(cex = 0.75))
params$col <- list()
params$eig <- list(pbackground = list(box = TRUE), psub = list(text = "Eigenvalues"))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
if(prop) {
id <- inertia.dudi(x, col.inertia = TRUE)
if(is.null(sortparameters[[2]]$plabels$cex)) {
sortparameters$col$plabels$cex <- id$col.cum[, 2] / (max(id$col.cum[, 2]) / 1.5)
} else {
sortparameters$col$plabels$cex <- sortparameters$col$plabels$cex * id$col.cum[, 2] / (max(id$col.cum[, 2]) / 1.5)
}
}
## prepare and create g1
if(permute)
df1 <- substitute(x$co)
else
df1 <- substitute(x$li)
g1 <- do.call(ifelse(density.plot, "s.density", "s.label"), c(list(dfxy = df1, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$row))
## prepare and create g2
if(permute) {
colss <- x$l1
} else {
colss <- x$c1
}
knormali <- c(min(colss[, xax]), max(colss[, xax]), min(colss[, yax]), max(colss[, yax])) / c(g1@g.args$xlim, g1@g.args$ylim)
csts <- 0.9 / max(knormali)
if(permute) {
df2 <- substitute(x$l1 * csts)
} else {
df2 <- substitute(x$c1 * csts)
}
g2 <- do.call("s.arrow", c(list(dfxy = df2, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$col))
## create the final ADEgS
object <- do.call("superpose", list(g1, g2))
object@Call <- call("superpose", g1@Call, g2@Call)
if(!is.null(position)) {
g3 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$eig))
object <- do.call("insert", list(g3@Call, object@Call, posi = position, plot = FALSE, ratio = 0.25))
}
names(object) <- graphsnames[1:length(object)]
object@Call <- match.call()
if(plot)
print(object)
invisible(object)
}
"scatter.coa" <- function(x, xax = 1, yax = 2, method = 1:3, posieig = "topleft", pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "dudi"))
stop("Object of class 'dudi' expected")
if(!inherits(x, "coa"))
stop("Object of class 'coa' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
position <- .getposition(posieig[1:min(2, length(posieig))])
method <- method[1]
## limits management
if(method == 1)
x.global <- rbind(as.matrix(x$li), as.matrix(x$co))
else if(method == 2)
x.global <- rbind(as.matrix(x$c1), as.matrix(x$li))
else if(method == 3)
x.global <- rbind(as.matrix(x$l1), as.matrix(x$co))
adegtot <- adegpar()
lim.global <- setlimits2D(minX = min(x.global[, xax]), maxX = max(x.global[, xax]), minY = min(x.global[, yax]), maxY = max(x.global[, yax]), origin = adegtot$porigin$origin, aspect.ratio = adegtot$paxes$aspectratio, includeOr = adegtot$porigin$include)
## sort parameters for each graph
graphsnames <- c("row", "col", "eig")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## parameters management
params <- list()
params$row <- list(plabels = list(cex = 0.75), xlim = lim.global$xlim, ylim = lim.global$ylim)
params$col <- list(xlim = lim.global$xlim, ylim = lim.global$ylim)
params$eig <- list(pbackground = list(box = TRUE), psub = list(text = "Eigenvalues"))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg and of the final ADEgS
if(method == 1) {
g1 <- do.call("s.label", c(list(dfxy = substitute(x$li), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$row))
g2 <- do.call("s.label", c(list(dfxy = substitute(x$co), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$col))
} else if(method == 2) {
g1 <- do.call("s.label", c(list(dfxy = substitute(x$c1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$col))
g2 <- do.call("s.label", c(list(dfxy = substitute(x$li), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$row))
} else if(method == 3) {
g1 <- do.call("s.label", c(list(dfxy = substitute(x$l1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$row))
g2 <- do.call("s.label", c(list(dfxy = substitute(x$co), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$col))
}
object <- do.call("superpose", list(g1, g2))
object@Call <- call("superpose", g1@Call, g2@Call)
if(!is.null(position)) {
g3 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$eig))
object <- do.call("insert", list(g3@Call, object@Call, posi = position, plot = FALSE, ratio = 0.25))
}
object@Call <- match.call()
names(object) <- graphsnames[1:length(object)]
if(plot)
print(object)
invisible(object)
}
"scatter.pco" <- function(x, xax = 1, yax = 2, posieig = "topleft", pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "dudi"))
stop("Object of class 'dudi' expected")
if(!inherits(x, "pco"))
stop("Object of class 'pco' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
position <- .getposition(posieig[1:min(2, length(posieig))])
## sort parameters for each graph
graphsnames <- c("row", "eig")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## parameters management
params <- list()
params$row <- list()
params$eig <- list(pbackground = list(box = TRUE), psub = list(text = "Eigenvalues"))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg and of the final ADEgS
object <- do.call("s.label", c(list(dfxy = substitute(x$li), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$row))
if(!is.null(position)) {
g2 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$eig))
object <- do.call("insert", list(g2@Call, object@Call, posi = position, plot = FALSE, ratio = 0.25))
names(object) <- graphsnames[1:length(object)]
}
object@Call <- match.call()
if(plot)
print(object)
invisible(object)
}
"scatter.nipals" <- function(x, xax = 1, yax = 2, posieig = "topleft", pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "nipals"))
stop("Object of class 'nipals' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
position <- .getposition(posieig[1:min(2, length(posieig))])
## sort parameters for each graph
graphsnames <- c("row", "col", "eig")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## parameters management
params <- list()
params$row <- list(plabels = list(cex = 0.75))
params$col <- list()
params$eig <- list(pbackground = list(box = TRUE), psub = list(text = "Eigenvalues"))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## prepare and create g1
g1 <- do.call("s.label", c(list(dfxy = substitute(x$li), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$row))
## prepare and create g2
knormali <- c(min(x$c1[, xax]), max(x$c1[, xax]), min(x$c1[, yax]), max(x$c1[, yax])) / c(g1@g.args$xlim, g1@g.args$ylim)
csts <- 0.8 / max(knormali)
df2 <- substitute(x$c1 * csts)
g2 <- do.call("s.arrow", c(list(dfxy = df2, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$col))
## creation of each individual ADEg and of the final ADEgS
object <- do.call("superpose", list(g1, g2))
object@Call <- call("superpose", g1@Call, g2@Call)
if(!is.null(position)) {
g3 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$eig))
object <- do.call("insert", list(g3@Call, object@Call, posi = position, plot = FALSE, ratio = 0.25))
}
names(object) <- graphsnames[1:length(object)]
object@Call <- match.call()
if(plot)
print(object)
invisible(object)
}
adegraphics/R/T.value.R 0000644 0001762 0000144 00000017032 13742303021 014364 0 ustar ligges users setClass(
Class = "T.value",
contains = "ADEg.T"
)
setMethod(
f = "prepare",
signature = "T.value",
definition = function(object) {
name_obj <- deparse(substitute(object))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
if(object@data$storeData) {
z <- as.vector(as.matrix(object@data$dftab))
dftab <- object@data$dftab
labelsx <- object@data$labelsx
labelsy <- object@data$labelsy
} else {
z <- as.vector(as.matrix(eval(object@data$dftab, envir = sys.frame(object@data$frame))))
dftab <- eval(object@data$dftab, envir = sys.frame(object@data$frame))
labelsx <- eval(object@data$labelsx, envir = sys.frame(object@data$frame))
labelsy <- eval(object@data$labelsy, envir = sys.frame(object@data$frame))
}
if(is.null(object@g.args$breaks))
object@s.misc$breaks.update <- pretty(z, object@g.args$nclass)
else
object@s.misc$breaks.update <- object@g.args$breaks
object@s.misc$breaks.update <- breakstest(object@s.misc$breaks.update, z, n = length(object@s.misc$breaks.update))
n <- length(object@s.misc$breaks.update)
if(is.null(object@adeg.par$ppoints$cex))
adegtot$ppoints$cex <- 1
if(is.null(object@adeg.par$ppoints$alpha))
adegtot$ppoints$alpha <- 1
if(is.null(labelsx))
adegtot$ptable$x$tck <- 0
if(is.null(labelsy))
adegtot$ptable$y$tck <- 0
## symbols for z = center
if(!is.null(object@g.args$centerpar)) {
default <- list(pch = 4, cex = 1, col = "black")
if(is.list(object@g.args$centerpar))
object@g.args$centerpar <- modifyList(default, object@g.args$centerpar, keep.null = TRUE)
else
object@g.args$centerpar <- default
}
## setting colors
if(!is.null(object@g.args$col)) {
switch(object@g.args$method,
size = {
if(length(object@g.args$col) != 2 & !inherits(dftab, "table") & !inherits(dftab, "dist"))
stop("if method size choosen, col vector should be size 2", call. = FALSE)
adegtot$ppoints$col <- object@g.args$col ## color given by the user
},
color = {
if(length(object@g.args$col) < (n - 1))
stop(paste("not enough colors defined for method color, at least ", (n - 1), " colors expected", sep = "") , call. = FALSE)
adegtot$ppoints$fill <- object@g.args$col[1:(n - 1)] ## color given by the user
})
} else {
if(object@g.args$method == "color")
adegtot$ppoints$fill <- adegtot$ppalette$quanti(n - 1)
else if(inherits(dftab, "table") | inherits(dftab, "dist")) {
adegtot$ppoints$col <- adegtot$ppalette$quanti(2)
}
else
adegtot$ppoints$col <- adegtot$ppalette$quanti(2)
}
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "T.value",
definition = function(object, x, y) {
if(object@data$storeData)
dftab <- as.matrix(object@data$dftab)
else
dftab <- as.matrix(eval(object@data$dftab, envir = sys.frame(object@data$frame)))
adeg.panel.values(x = x[col(dftab)], y = y[row(dftab)], z = as.vector(dftab), center = object@g.args$center, method = object@g.args$method,
symbol = object@g.args$symbol, ppoints = object@adeg.par$ppoints, breaks = object@s.misc$breaks.update, centerpar = object@g.args$centerpar)
})
table.value <- function(dftab, coordsx = 1:ncol(as.matrix(dftab)), coordsy = nrow(as.matrix(dftab)):1, labelsx, labelsy, breaks = NULL, method = c("size", "color"),
symbol = c("square", "circle", "diamond", "uptriangle", "downtriangle"), col = NULL, nclass = 3, center = 0, centerpar = NULL, plot = TRUE,
storeData = TRUE, add = FALSE, pos = -1, ...) {
## 4 different types can be used as tab :
## distance matrix (dist), contingency table (table), data.frame or matrix
## evaluation of some parameters
thecall <- .expand.call(match.call())
thecall$method <- match.arg(method)
thecall$symbol <- match.arg(symbol)
dftab <- eval(thecall$dftab, envir = sys.frame(sys.nframe() + pos))
if(any(is.na(dftab)))
stop("NA entries not accepted")
if(inherits(dftab, "dist")) {
if(missing(labelsx)){
thecall$labelsx <- labelsx <- NULL
if(!is.null(attr(dftab, "Labels")))
if(storeData)
labelsx <- attr(dftab, "Labels")
else
thecall$labelsx <- call("attr", thecall$dftab, "Labels")
}
if(missing(labelsy)) {
thecall$labelsy <- labelsy <- NULL
if(!is.null(attr(dftab, "Labels")))
if(storeData)
labelsy <- attr(dftab, "Labels")
else
thecall$labelsy <- call("attr", thecall$dftab, "Labels")
}
## coordsx and coordsy should be identical for dist objects (symmetric)
thecall$coordsx <- call(":", 1, call("attr", thecall$dftab, "Size"))
thecall$coordsy <- call(":", call("attr", thecall$dftab, "Size"), 1)
} else { ## data.frame, matrix, table
if(missing(labelsy)) {
thecall$labelsy <- labelsy <- NULL
if(!is.null(rownames(dftab)))
if(storeData)
labelsy <- rownames(dftab)
else
thecall$labelsy <- call("rownames", thecall$dftab)
}
if(missing(labelsx)) {
thecall$labelsx <- labelsx <- NULL
if(!is.null(colnames(dftab)))
if(storeData)
labelsx <- colnames(dftab)
else
thecall$labelsx <- call("colnames", thecall$dftab)
}
}
## parameters sorted
sortparameters <- sortparamADEg(...)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(breaks = breaks, method = thecall$method, symbol = thecall$symbol, center = thecall$center, col = col, nclass = nclass, centerpar = centerpar))
if(storeData)
tmp_data <- list(dftab = dftab, coordsx = coordsx, coordsy = coordsy, labelsx = labelsx, labelsy = labelsy, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(dftab = thecall$dftab, coordsx = thecall$coordsx, coordsy = thecall$coordsy, labelsx = thecall$labelsx, labelsy = thecall$labelsy, frame = sys.nframe() + pos, storeData = storeData)
if(inherits(dftab, "table")) {
condres <- pmatch(c("ablineX", "ablineY", "meanX", "meanY"), names(sortparameters$rest))
if(any(!is.na(condres))) {
tmplist <- sortparameters$rest[condres[!is.na(condres)]]
names(tmplist) <- c("ablineX", "ablineY", "meanX", "meanY")[which(!is.na(condres))]
sortparameters$rest <- sortparameters$rest[-condres[(!is.na(condres))]]
g.args <- c(g.args, tmplist)
}
g.args[c("ablineX", "ablineY", "meanX", "meanY")[which(is.na(condres))]] <- FALSE
object <- new(Class = "T.cont", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = match.call())
} else
object <- new(Class = "T.value", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = match.call())
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## preparation of the graph
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
else
if(plot)
print(object)
invisible(object)
}
adegraphics/R/ADEg.R 0000644 0001762 0000144 00000027205 14572567273 013640 0 ustar ligges users ##############################################
## general class ##
##############################################
setClass(
Class = "ADEg",
contains = "VIRTUAL",
slots = c(
trellis.par = "list",
adeg.par = "list",
lattice.call = "list",
g.args = "list",
stats = "list",
s.misc = "list",
Call = "call")
## validity
## validity = function(object){return(TRUE)}
)
##############################################
## initialize ##
##############################################
setMethod(
f = "initialize",
signature = "ADEg",
definition = function(.Object, trellis.par = list(), adeg.par = list(), lattice.call = list(), g.args = list(), stats = list(), s.misc = list(), Call = call("emptycall"), ...) {
.Object@trellis.par <- trellis.par
.Object@adeg.par <- adeg.par
.Object@lattice.call <- lattice.call
.Object@g.args <- g.args
.Object@stats <- stats
.Object@s.misc <- s.misc
.Object@Call <- Call
return(.Object)
})
setOldClass("trellis")
setClassUnion(name = "ADEgORtrellis", members = c("ADEg", "trellis"))
setMethod(
f = "panelbase",
signature = "ADEg",
definition = function(object, x, y) {
whichpanel <- packet.number()
sub <- lapply(object@adeg.par$psub, FUN = function(x) {rep(x, length.out = max(whichpanel, 2))}) ## repeat at least twice for position coordinates
if(is.numeric(object@adeg.par$psub$position))
num <- 1
else
num <- 0
if(sub$cex[whichpanel] && (sub$text[whichpanel] != "")) {
if(!num)
posit <- .setposition(sub$position[whichpanel])
else
posit <- .setposition(sub$position[(2 * whichpanel - 1):(2 * whichpanel)])
text <- textGrob(label = sub$text[whichpanel], x = posit$posi[1], y = posit$posi[2], gp = gpar(cex = sub$cex[whichpanel], col = sub$col[whichpanel]), just = posit$just, name = paste("subtitle_", whichpanel, sep = ""))
grid.rect(x = posit$posi[1], y = posit$posi[2], width = grobWidth(text), height = grobHeight(text), just = posit$just, gp = gpar(fill = ifelse(class(object) == "S2.corcircle" | inherits(object, "ADEg.Tr"), "transparent", object@adeg.par$pbackground$col), alpha = 1, col = "transparent"))
grid.draw(text)
}
})
##############################################
## Get elements/information ##
##############################################
setMethod(
f = "getparameters",
signature = "ADEg",
definition = function(object, number = 0) {
if(number == 0)
return(list(trellis.par = object@trellis.par, adeg.par = object@adeg.par, g.args = object@g.args))
if(number == 1)
return(object@trellis.par)
if(number == 2)
return(object@adeg.par)
stop("wrong number for getparameters")
})
setMethod(
f = "getlatticecall",
signature = "ADEg",
definition = function(object) {
return(object@lattice.call)
})
setMethod(
f = "getcall",
signature = "ADEg",
definition = function(object) {
return(object@Call)
})
setMethod(
f = "getstats",
signature = "ADEg",
definition = function(object) {
return(object@stats)
})
##############################################
## superposition ##
##############################################
## g1 superpose on refg
## settings about margin limits ect... taken from refg
## modified object only displayed (not save), original limits ect are kept
setMethod(
f = "printSuperpose",
signature = c("ADEgORtrellis", "ADEgORtrellis"),
definition = function(g1, refg) {
## to respect axis, limits, etc., we work directly on the trellis objects.
if(inherits(refg, "ADEg")) {
trelref <- gettrellis(refg)
if(inherits(g1, "ADEg")) {
g1@adeg.par$pgrid$draw <- FALSE
g1@g.args$xlim <- refg@g.args$xlim
g1@g.args$ylim <- refg@g.args$ylim
g1@adeg.par$paxes$draw <- refg@adeg.par$paxes$draw
g1@adeg.par$pbackground$col <- "transparent" ## useful for S2.corcircle
g1@adeg.par$porigin$draw <- FALSE
g1@s.misc$scales <- refg@s.misc$scales
if(inherits(g1, "ADEg.Tr") & inherits(refg, "ADEg.Tr")) {
g1@g.args$min3d <- refg@g.args$min3d
g1@g.args$max3d <- refg@g.args$max3d
g1@adeg.par$pgrid$text$cex <- 0 ## no text corner for g1
g1@lattice.call$arguments$par.settings$axis.text$cex <- 0
}
setlatticecall(g1)
trel1 <- gettrellis(g1)
} else {
trel1 <- g1
}
} else { ## refg is a trellis
trelref <- refg
if(inherits(g1, "ADEg")) {
g1@adeg.par$pgrid$draw <- FALSE
g1@g.args$xlim <- refg$x.limits
g1@g.args$ylim <- refg$y.limits
g1@adeg.par$paxes$draw <- refg$x.scales$draw * refg$y.scales$draw
g1@adeg.par$porigin$draw <- FALSE
g1@g.args$xlab <- ""
g1@g.args$ylab <- ""
setlatticecall(g1)
trel1 <- gettrellis(g1)
} else {
trel1 <- g1
}
}
trel1$par.settings$panel.background$col <- "transparent"
trel1$par.settings$axis.text$alpha <- 0
trel1$par.settings$axis.line$col <- "transparent"
names <- c("x.scales", "y.scales", "xlab", "ylab", "main", "sub", "x.between", "y.between", "as.table", "x.limits", "y.limits", "aspect.ratio")
for(i in names)
trel1[[i]] <- trelref[[i]]
print(trel1, newpage = FALSE)
})
setMethod(
f = "superpose",
signature = c("ADEgORtrellis", "ADEgORtrellis", "ANY", "ANY"),
definition = function(g1, g2, which, plot) {
addi <- matrix(0, 2, 2)
addi[1, 2] <- 1
obj <- new(Class = "ADEgS", ADEglist = list(g1, g2), positions = matrix(rep(c(0, 1), each = 4), 2, 4), add = addi, Call = match.call())
if(plot)
print(obj)
invisible(obj)
})
##############################################
## insertion ##
##############################################
setMethod(
f = "insert",
signature = c("ADEgORtrellis", "missing"),
definition = function(graphics, oldgraphics, posi, ratio, inset, plot, which) {
positions <- .getposition(posi, w = ratio, h = ratio) + inset
currentgraphic <- get("currentadeg", envir = .ADEgEnv)
if(!(length(currentgraphic)))
stop("no existing graphics")
else
newADEgS <- insert(graphics = graphics, oldgraphics = currentgraphic, posi = posi, ratio = ratio, inset = inset, plot = plot, which = which)
if(plot)
print(newADEgS[length(newADEgS)], closeViewport = FALSE)
assign("currentadeg", newADEgS, envir = .ADEgEnv)
invisible(newADEgS)
})
setMethod(
f = "insert",
signature = c("ADEgORtrellis", "ADEg"),
definition = function(graphics, oldgraphics, posi, ratio, inset, plot) {
positions <- .getposition(posi, w = ratio, h = ratio) + inset
thecall <- call("insert", graphics@Call, oldgraphics@Call)
newADEgS <- new(Class = "ADEgS", ADEglist = list(oldgraphics, graphics), positions = rbind(c(0, 0, 1, 1), positions), add = matrix(0, ncol = 2, nrow = 2), Call = thecall)
if(plot)
print(newADEgS)
assign("currentadeg", newADEgS, envir = .ADEgEnv)
invisible(newADEgS)
})
##############################################
## Add ##
##############################################
setMethod(
f = "+",
signature = c("ADEg", "ADEg"),
definition = function(e1, e2) {
newobj <- superpose(e1, e2)
newobj@Call <- match.call()
return(newobj)
})
setMethod(
f = "add.ADEg",
signature = c("ADEg"),
definition = function(object) {
previous <- get("currentadeg", envir = .ADEgEnv)
if(!(length(previous)))
stop("no graph to add to")
objects <- superpose(previous, object)
if(inherits(previous, "ADEg"))
printSuperpose(object, previous, position = c(0, 0, 1, 1))
else if(inherits(previous, "ADEgS"))
printSuperpose(object, previous[[length(previous)]], position = previous@positions[length(previous), ])
# lattice:::lattice.setStatus(print.more = FALSE)
assign("currentadeg", objects, envir = .ADEgEnv)
invisible(objects)
})
##############################################
## Update ##
##############################################
## update the modified parameters
setMethod(
f = "update",
signature = "ADEg",
definition = function(object, ..., plot = TRUE) {
nameobj <- deparse(substitute(object, env = parent.frame(n = 1)))
## object is in parent.frame() because 'update' method pattern is different with 'update' generic method pattern
## see https://stat.ethz.ch/pipermail/r-help/2008-January/152296.html
## extract specific slots used in function call
pattern <- names(object@g.args)
lpattern <- as.list(rep("", length(pattern)))
names(lpattern) <- pattern
## sort parameters
sep <- separation(..., pattern = lpattern)
selection <- sortparamADEg(sep[[2]])
selection$g.args <- c(selection$g.args, sep[[1]])
if(length(selection$rest))
warning(c("Unused parameters: ", paste(unique(names(selection$rest)), " ", sep = "")), call. = FALSE)
object@adeg.par <- modifyList(object@adeg.par, selection$adepar, keep.null = TRUE)
object@trellis.par <- modifyList(object@trellis.par, selection$trellis, keep.null = TRUE)
object@g.args <- modifyList(object@g.args, selection$g.args, keep.null = TRUE)
prepare(object)
setlatticecall(object)
if(plot)
print(object)
assign(nameobj, object, envir = parent.frame(n = 2))
## see also https://stat.ethz.ch/pipermail/r-help/2008-January/152296.html
assign("currentadeg", object, envir = .ADEgEnv)
})
##############################################
## Display ##
##############################################
setMethod(
f = "show",
signature = "ADEg",
definition = function(object) {
print(object)
})
setMethod(
f = "plot",
signature = c("ADEg", "ANY"),
definition = function(x, y, adjust = FALSE) {
print(x, adjust = adjust)
})
setMethod(
f = "print",
signature = c("ADEg"),
definition = function(x, adjust = FALSE, newpage = TRUE) {
## if adjust, graphic limits are readjust according to the device size.
## for now it is only available if only an ADEg is drawn (not in ADEgS)
if(adjust) {
aspp <- dev.size() ## device size (in inches)
ratid <- aspp[1] / aspp[2]
oxlim <- x@lattice.call$arguments$xlim ## old xlim
oylim <- x@lattice.call$arguments$ylim
ratig <- diff(oxlim) / diff(oylim)
## if not mandatory ...?
if((ratid / ratig) > 1) {
## width device bigger (relative) than width graphic
centerx <- oxlim[1] + diff(oxlim) / 2
nxlim <- rep(centerx, 2) + c(-1, 1) * ((ratid * diff(oylim)) / 2)
nylim <- oylim
}
else if((ratid / ratig) < 1) { ## then relative device height bigger than relative graphic height
centery <- oylim[1] + diff(oylim) / 2
nylim <- rep(centery, 2) + c(-1, 1) * (1 / ratid * diff(oxlim)) / 2
nxlim <- oxlim
}
x@s.misc$backgrid <- .getgrid(xlim = nxlim, ylim = nylim, x@adeg.par$pgrid$nint, rep(x@adeg.par$porigin$origin, le = 2), asp = x@adeg.par$paxes$aspectratio)
setlatticecall(x) ## passing backgrid
## changing limits
x@lattice.call$arguments$xlim <- nxlim
x@lattice.call$arguments$ylim <- nylim
}
object <- x
if(!length(object@lattice.call))
stop("no graphics instruction")
else {
tmp_object <- gettrellis(x)
print(tmp_object, newpage = newpage)
assign("currentadeg", x, envir = .ADEgEnv)
}
})
adegraphics/R/S2.density.R 0000644 0001762 0000144 00000015257 14354572626 015042 0 ustar ligges users ##########################################################################
## s.density ##
##########################################################################
setClass(
Class = "S2.density",
contains = "ADEg.S2"
)
## no initialize function (use ADEg.S2 by inheritance)
setMethod(
f = "prepare",
signature = "S2.density",
definition = function(object) {
name_obj <- deparse(substitute(object))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
if(object@data$storeData)
dfxy <- object@data$dfxy
else
dfxy <- eval(object@data$dfxy, envir = sys.frame(object@data$frame))
if(is.null(object@adeg.par$plabels))
adegtot$plabels$cex <- 0
if(is.null(object@adeg.par$porigin$include) & (any(names(object@g.args) %in% c("Sp", "nbobject"))))
adegtot$porigin$include <- FALSE
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
## compute density using bkde2D (KernSmooth package)
## bandwidth and gridsize can be provided by user. range.x allows computation for all the panel (even with no points)
if(is.null(object@g.args$bandwidth))
object@g.args$bandwidth <- diff(apply(dfxy[, c(object@data$xax, object@data$yax)], 2, quantile, probs = c(0.05, 0.95), na.rm = TRUE)) / 25
if(min(object@g.args$bandwidth) <= 0)
stop("'bandwidth' must be strictly positive")
object@g.args$threshold <- min(max(0, object@g.args$threshold), 1)
object@stats$densit <- bkde2D(dfxy[, c(object@data$xax[1], object@data$yax[1])], bandwidth = object@g.args$bandwidth, gridsize = rep(object@g.args$gridsize, length.out = 2))
## TODO: as in s.image, remove points (only) where density is null
## use expand.grid...
## never optimized labels for s.density
object@adeg.par$plabels$optim <- FALSE
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "S2.density",
definition = function(object, x, y) {
densit <- object@stats$densit
if(is.null(object@g.args$col))
col <- object@adeg.par$ppalette$quanti(255)
else
col <- object@g.args$col
transformation <- function(x) x
densityy <- array(transformation(densit$fhat), dim = dim(densit$fhat))
if(object@g.args$region)
panel.levelplot(x = rep(densit$x1, length(densit$x2)),
y = rep(densit$x2, each = length(densit$x1)),
z = densityy,
at = c(-.Machine$double.eps, seq(from = max(densit$fhat) * object@g.args$threshold + .Machine$double.eps,
to = 1.01 * max(densit$fhat), length = length(col) + 2)),
col.regions = c("transparent", col),
subscripts = TRUE)
if(object@g.args$contour)
panel.levelplot(x = rep(densit$x1, length(densit$x2)),
y = rep(densit$x2, each = length(densit$x1)),
z = densityy,
labels = object@adeg.par$plabels,
label.style = if(object@adeg.par$plabels$srt == "horizontal") "flat" else "align", ## also exist "mixed" not used here
at = c(-.Machine$double.eps, seq(from = max(densit$fhat) * object@g.args$threshold + .Machine$double.eps,
to = 1.01 * max(densit$fhat), length = object@g.args$nclass + 1)),
col.regions = c("transparent", col),
subscripts = TRUE,
region = FALSE,
contour = TRUE)
## show nrpoints outilers
if(object@g.args$nrpoints > 0) {
## copy of panel.smoothScatter
ixm <- round((x - densit$x1[1]) / (densit$x1[length(densit$x1)] - densit$x1[1]) * (length(densit$x1) - 1))
iym <- round((y - densit$x2[1]) / (densit$x2[length(densit$x2)] - densit$x2[1]) * (length(densit$x2) - 1))
idens <- densityy[1 + iym * length(densit$x1) + ixm]
nrpoints <- min(nrow(x), ceiling(object@g.args$nrpoints))
sel <- order(idens, decreasing = FALSE)[1:nrpoints]
panel.points(x[sel], y[sel], pch = object@adeg.par$ppoints$pch, cex = object@adeg.par$ppoints$cex, col = object@adeg.par$ppoints$col, fill = object@adeg.par$ppoints$fill)
}
})
s.density <- function(dfxy, xax = 1, yax = 2, bandwidth = NULL, gridsize = c(450L, 450L), nrpoints = 300, threshold = 0.1, col = NULL,
contour = FALSE, region = !contour, nclass = 8, facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters
thecall <- .expand.call(match.call())
df <- try(as.data.frame(eval(thecall$dfxy, envir = sys.frame(sys.nframe() + pos))), silent = TRUE)
if(inherits(df, "try-error") | is.null(thecall$dfxy)) ## non convenient dfxy argument
stop("non convenient selection for dfxy (can not be converted to dataframe)")
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if((length(xax) == 1 & length(yax) == 1))
object <- multi.facets.S2(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple xax/yax")
}
## multiple axes
else if((length(xax) > 1 | length(yax) > 1)) {
object <- multi.ax.S2(thecall)
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(bandwidth = bandwidth, gridsize = gridsize, threshold = threshold, col = col, nrpoints = nrpoints, contour = contour, region = region, nclass = nclass))
if(storeData)
tmp_data <- list(dfxy = dfxy, xax = xax, yax = yax, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(dfxy = thecall$dfxy, xax = xax, yax = yax, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "S2.density", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = as.call(thecall))
## preparation
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/addtext.R 0000644 0001762 0000144 00000011566 13742303021 014511 0 ustar ligges users setMethod(
f = "addtext",
signature = "ADEg",
definition = function(object, xcoord, ycoord, label, plot = TRUE, ...) {
# iterate coordinates and/or labels if necessary
size <- max(length(xcoord), length(ycoord), length(label))
xcoord <- rep_len(xcoord, length.out = size)
ycoord <- rep_len(ycoord, length.out = size)
labels <- rep_len(label, length.out = size)
# collect limits
xlim <- object@g.args$xlim
ylim <- object@g.args$ylim
aspect <- object@adeg.par$paxes$aspectratio
## sorting parameters
sortparameters <- sortparamADEg(...)$adepar
params <- adegpar()
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
params <- sortparameters$plabels
# create the lattice object
textadded <- xyplot(ycoord ~ xcoord, xlim = xlim, ylim = ylim, xlab = NULL, ylab = NULL, aspect = aspect,
panel = function(x, y, ...) adeg.panel.label(x, y, labels, plabels = params), plot = FALSE)
textadded$call <- call("xyplot", ycoord ~ xcoord, xlim = substitute(xlim), ylim = substitute(ylim), xlab = NULL, ylab = NULL,
aspect = substitute(aspect), labels = substitute(labels),
panel = function(x, y, labels, ...) adeg.panel.label(x, y, labels = labels, plabels = params))
# superposition
obj <- superpose(object, textadded, plot = FALSE)
nn <- all.names(substitute(object))
names(obj) <- c(ifelse(is.na(nn[2]), nn[1], nn[2]), "textadded")
if(plot)
print(obj)
invisible(obj)
})
setMethod(
f = "addtext",
signature = "trellis",
definition = function(object, xcoord, ycoord, label, plot = TRUE, ...) {
# iterate coordinates and/or labels if necessary
size <- max(length(xcoord), length(ycoord), length(label))
xcoord <- rep_len(xcoord, length.out = size)
ycoord <- rep_len(ycoord, length.out = size)
labels <- rep_len(label, length.out = size)
# collect limits
xlim <- c(0,1)
ylim <- c(0,1)
if (is.numeric(object$x.limits))
xlim <- object$x.limits
if (is.numeric(object$y.limits))
ylim <- object$y.limits
aspect <- object$aspect.ratio
## sorting parameters
sortparameters <- sortparamADEg(...)$adepar
params <- adegpar()
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
params <- sortparameters$plabels
# create the lattice object
textadded <- xyplot(ycoord ~ xcoord, xlim = xlim, ylim = ylim, xlab = NULL, ylab = NULL, aspect = aspect,
panel = function(x, y, ...) adeg.panel.label(x, y, labels, plabels = params), plot = FALSE)
textadded$call <- call("xyplot", ycoord ~ xcoord, xlim = substitute(xlim), ylim = substitute(ylim), xlab = NULL, ylab = NULL,
aspect = substitute(aspect), labels = substitute(labels),
panel = function(x, y, labels, ...) adeg.panel.label(x, y, labels = labels, plabels = params))
# superposition
obj <- superpose(object, textadded, plot = FALSE)
nn <- all.names(substitute(object))
names(obj) <- c(ifelse(is.na(nn[2]), nn[1], nn[2]), "textadded")
if(plot)
print(obj)
invisible(obj)
})
setMethod(
f = "addtext",
signature = "ADEgS",
definition = function(object, xcoord, ycoord, label, plot = TRUE, which = 1:length(object), ...) {
ngraph <- length(object)
if(max(which) > ngraph)
stop("Values in 'which' should be lower than the length of object")
if(length(which) == 1) { # if only one subgraph is selected, all the labels are displayed on this unique subgraph
size <- max(length(xcoord), length(ycoord), length(label))
xcoord <- rep_len(xcoord, length.out = size)
ycoord <- rep_len(ycoord, length.out = size)
labels <- rep_len(label, length.out = size)
object[[which]] <- addtext(object[[which]], xcoord, ycoord, labels, ..., plot = FALSE)
} else { # if several subgraphs are selected, each label is displayed on one subgraph; there is only one label by subgraph
if(sum(object@add) != 0)
stop("The 'addtext' function is not available for superposed objects.", call. = FALSE)
## sorting parameters
sortparameters <- sortparamADEg(...)$adepar
params <- adegpar()
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
params <- sortparameters$plabels
params <- rapply(params, function(X) rep(X, length.out = length(which)), how = "list")
xcoord <- rep_len(xcoord, length.out = length(which))
ycoord <- rep_len(ycoord, length.out = length(which))
labels <- rep_len(label, length.out = length(which))
for (i in which)
object[[i]] <- addtext(object[[i]], xcoord[i], ycoord[i], labels[i], which = 1, plot = FALSE, plabels = lapply(params, function(X) X[i]))
}
obj <- object
if(plot)
print(obj)
invisible(obj)
}) adegraphics/R/utilsADEgS.R 0000644 0001762 0000144 00000025074 13742303021 015017 0 ustar ligges users plotEig <- function(eigvalue, nf, xax = 1, yax = 2, col.plot = "black", col.kept = "grey", col = "white", facets = NULL, plot = TRUE, storeData = FALSE, pos = -1, ...) {
## prepare
col <- rep(col, length(eigvalue))
col[nf] <- col.kept
col[c(xax, yax)] <- col.plot
## parameters management
sortparameters <- sortparamADEg(...)
params <- list()
params$adepar <- list(ppolygons = list(col = col), p1d = list(horizontal = FALSE), psub = list(position = "topright"), pgrid = list(draw = FALSE), pbackground = list(box = FALSE))
sortparameters$adepar <- modifyList(params$adepar, sortparameters$adepar, keep.null = TRUE)
if(is.null(facets) || isTRUE(sortparameters$g.args$samelimits)) {
lim <- c(0, ifelse(is.null(facets), length(eigvalue), max(table(facets)))) + 0.5
if(isTRUE(sortparameters$adepar$p1d$horizontal))
params$g.args <- list(ylim = lim)
else
params$g.args <- list(xlim = lim)
lim.val <- range(eigvalue)
if(lim.val[1] >= 0) {
lim.val <- c(0, lim.val[2] + diff(c(lim.val[1], lim.val[2])) / 10)
if(isTRUE(sortparameters$adepar$p1d$horizontal))
params$g.args <- list(xlim = lim.val, ylim = params$g.args$ylim)
else
params$g.args <- list(xlim = params$g.args$xlim, ylim = lim.val)
}
at <- 1:length(eigvalue)
} else {
params$g.args <- list(xlim = NULL, ylim = NULL)
at <- unlist(sapply(tabulate(facets), seq_len))
}
sortparameters$g.args <- modifyList(params$g.args, sortparameters$g.args, keep.null = TRUE)
do.call("s1d.barchart", c(list(score = substitute(eigvalue), at = at, pos = pos - 2, plot = plot, facets = facets, storeData = storeData),
sortparameters$adepar, sortparameters$trellis, sortparameters$g.args, sortparameters$stats, sortparameters$s.misc, sortparameters$rest))
}
"plotRandTest" <- function(hist, nclass, obs, pos = -1, storeData = TRUE, plot = TRUE, params) {
graphsnames <- c("sim", "obs")
sortparameters <- sortparamADEgS(params, graphsnames = graphsnames)
## creation of each individual ADEg
g1 <- do.call("s1d.hist", c(list(score = hist, nclass = nclass, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g2 <- do.call("addsegment", c(list(g1, x0 = obs, x1 = obs, y0 = 0, y1 = max(hist$counts) / 2,
plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("addpoint", c(list(g1, xcoord = obs, ycoord = max(hist$counts) / 2,
plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g4 <- g2$segmentadded + g3$pointadded
## ADEgS creation
object <- superpose(g1, g4)
names(object) <- graphsnames
return(object)
}
## si ADEgS contenu dans un plus petit espace;
## oldposition: matrice de position: nrow:number of graphs, col: x0, y0, x1, y1
## newposition: vector, length 4: x0, y0, x1, y1
## Calcul: toute les oldpositions: dans newposition.
## renvoie d'une matrice, 4col, nrow(oldposition) rows.
## cette indique les nouvelles positions des graphiques dans le reférentiel de refposition
## test:
## oldpos <- t(rbind(rep(c(0, 1 / 3, 2 / 3), 2), c(rep(0.5, 3), rep(0, 3)), rep(c(1 / 3, 2 / 3, 1), 2), c(rep(1, 3), rep(0.5, 3))))
## newpos <- c(0.5, 0.5, 1, 1)
## .updateadegsposition(oldpos, refpositions)
.updateADEgSposition <- function(oldposition, refposition) {
## test arguments
if(NCOL(oldposition) > 4)
stop("wrong position, only 4columns expected")
if(any(oldposition[, 1] >= oldposition[, 3]))
stop("wrong position given, x0>=x1 cannot work")
if(any(oldposition[, 2] >= oldposition[, 4]))
stop("wrong position given, y0>=y1 cannot work")
if(NCOL(refposition) != 1)
stop("error in .updateADEgSposition, several containing graphs given, only one possible") ## ne devrait jamais jamais arriver!
## formula:
## xnewi <- xoldi * wnew + x0new
## ynewi <- yoldi * hnew + y0new
x0o <- oldposition[, 1]
x1o <- oldposition[, 3]
y0o <- oldposition[, 2]
y1o <- oldposition[, 4]
wnew <- refposition[3] - refposition[1]
hnew <- refposition[4] - refposition[2]
## peut mieux faire (optimisation)
calcNew <- function(old, new, wh) {return(old * wh + new)}
return(cbind(calcNew(x0o, refposition[1], wnew),
calcNew(y0o, refposition[2], hnew),
calcNew(x1o, refposition[1], wnew),
calcNew(y1o, refposition[2], hnew)))
}
## .getposition: mainly for placing eigen plot.
## gives coordinates according to string position and width, height wanted
.getposition <- function(position, w = 0.25, h = 0.25) {
if(is.numeric(position) && length(position) == 4)
posnum <- position
else if(is.numeric(position) && length(position) == 2)
posnum <- c(position[1], position[2], position[1] + w, position[2] + h)
else if(is.character(position)) {
position <- match.arg(position[1], choices = c("bottomleft", "bottomright", "topleft", "topright", "none"), several.ok = FALSE)
if(position == "bottomleft")
posnum <- c(0.0, 0.0, w, h)
else if(position == "bottomright")
posnum <- c(1 - w, 0.0, 1, h)
else if(position == "topleft")
posnum <- c(0.0, 1 - h, w, 1)
else if(position == "topright")
posnum <- c(1 - w, 1 - h, 1, 1)
else if(position == "none")
posnum <- NULL
else
stop("Wrong indication of position")
}
else
stop("Wrong indication of position")
return(posnum)
}
## pour adeGs, on doit etre capable de separer facilement les parametres pour pouvoir avoir un adressage specifique pour chaque graphique (ie pas la meme chose poru le sarrow et le slabel dans un scatterdudi)
## selon les graphiques adeGs nous aurons des pattern differents:
## ex pour scatter.dudi, nous pouvons imager 'col', 'row', 'eigen' pour distinguer les paramètres spécifiques au graph
.partoadeg <- function(..., pattern = NULL) {
if(is.null(pattern))
stop("error in .partoadeg, pattern should be filled")
if(try(is.list(...), silent = TRUE) == TRUE)
dots <- as.list(...)
else dots <- list(...)
result <- vector("list", length = length(pattern))
result <- lapply(result, as.list)
names(result) <- pattern
## si deja indique en list
if(length(dots)) {
whichG <- c()
then <- c()
## pour ceux indiquer avec des .
splitgrp <- sapply(names(dots), FUN = function(x) {strsplit(x, ".", fixed=TRUE)})
for(i in 1:length(splitgrp)) {
## premier niveaux quel graph
whichG <- c(whichG, splitgrp[[i]][1])
## deuxieme niveau si il y a le nom suivant (qui etait colle avec un .)
if(length(splitgrp[[i]]) > 1) { ## un second element
then <- c(then, paste(splitgrp[[i]][2:length(splitgrp[[i]])], collapse = "."))
}
else
then <- c(then, NA)
}
indix <- pmatch(whichG, pattern, duplicates.ok = TRUE)
notna <- which(!is.na(indix)) ## ne garder que les non na
arena <- which(is.na(indix)) ## position dans indix des NA ie: ceux qui n'ont pas de match
for(i in 1:length(result)) {
sublist <- result[[i]] ## sous list deja trouve... a priori list
if(any(indix[notna] == i)) { ## si un indix vaut i=> a mettre dans result
## soit dire une liste soiton a dans then
toselect <- which(indix == i)
for(have2 in 1:length(toselect))
if(!is.na(then[toselect[have2]])) { ## a ete renseigne avec un point ensuite
newlist <- c(list(), dots[toselect[have2]])
names(newlist) <- then[toselect[have2]]
sublist <- c(sublist, newlist)
}
else ## c un na na donc ensuite on avait une liste
sublist <- c(sublist, dots[[toselect[have2]]])
}
if(length(arena)) ## on a en plus des na, donc des parameteres pour tous
selectNa <- indix[arena]
sublist <- c(sublist, dots[arena])
if(!is.null(sublist))
result[[i]] <- sublist
}}
return(result)
}
.n2mfrow <- function(nr.plots) {
## inspired by n2mfrow but we change the default when the number of graphs is <6
if (nr.plots <= 3)
c(1, nr.plots)
else if (nr.plots <= 6)
c(2, (nr.plots + 1) %/% 2)
else if (nr.plots <= 9)
c((nr.plots + 2) %/% 3, 3)
else if (nr.plots <= 12)
c((nr.plots + 3) %/% 4, 4)
else c(nrow <- ceiling(sqrt(nr.plots)), ceiling(nr.plots / nrow))
}
## Get positions matrix for ADEgs according a given layout
## strongly inspired by the layout function
## ng: number of positions to get
layout2position <- function(mat, widths = rep(1, NCOL(mat)), heights = rep(1, NROW(mat)), ng, square = FALSE) {
if(is.vector(mat)) {
if(missing(ng)) ng <- mat[1] * mat[2]
mat <- matrix(c(1:ng, rep(0, length.out = ((mat[1] * mat[2]) - ng))), nrow = mat[1], byrow = TRUE)
if(missing(widths))
widths <- rep(1, ncol(mat))
if(missing(heights))
heights <- rep(1, nrow(mat))
}
if(NROW(mat) != length(heights)) stop("wrong number of heigths given", call. = FALSE)
if(NCOL(mat) != length(widths)) stop("wrong number of widths given", call. = FALSE)
nbgraph <- max(mat)
## get xi position and yi position
xi <- c(0)
yi <- c(0)
## here, width given such as proportional colums.
## so the sum(width)/length(widths) == 1
## more units to take in account"
if(square == TRUE) {
wi <- widths / max(length(widths), length(heights))
hi <- heights / max(length(widths), length(heights))
} else {
wi <- widths / sum(widths)
hi <- heights / sum(heights)
}
## layout from left to right, up to bottom
for(i in 1:length(wi))
xi <- c(xi, xi[i] + wi[i])
for(i in 1:length(hi))
yi <- c(yi, yi[i] + hi[i])
yi <- rev(yi)
pos <- c()
for(i in 1:nbgraph) { ## for each graph, get the positions as x0, y0, x1, y1
indx <- which(mat == i, arr.ind = TRUE)
if(length(indx) == 0) { ## just in case
warning(paste("in layout2position, a graph position is missing, no graph", i, "defined", sep = " "), call. = FALSE)
pos <- rbind(pos, rep(0, 4))
}
else
pos <- rbind(pos, c(xi[min(indx[, 2])], yi[(max(indx[, 1]) + 1)], xi[(max(indx[, 2]) + 1)], yi[min(indx[, 1])]))
}
return(pos)
}
## For analysis plot (ADEgS creation)
sortparamADEgS <- function(..., graphsnames, nbsubgraphs = rep(1, length(graphsnames))) {
seppara <- .partoadeg(..., pattern = graphsnames)
sortparameters <- lapply(seppara, FUN = sortparamADEg)
alist <- function(x) {
aa <- list()
for(i in 1:length(x))
aa <- c(aa, x[[i]])
aa
}
tomerge <- lapply(sortparameters, alist)
oki <- lapply(tomerge, .mergingList)
if(!all(nbsubgraphs == rep(1, length(graphsnames))))
for (i in 1:length(nbsubgraphs))
oki[[i]] <- repList(oki[[i]], nbsubgraphs[i])
return(oki)
}
adegraphics/R/adeGsenv.R 0000644 0001762 0000144 00000007617 13742303021 014612 0 ustar ligges users ## At the loading of the package, creation of an environment .ADEgEnv to store:
## - the list of graphical parameters
## - the theme adeg
## - the last plotted graphics
.ADEgEnv <- new.env()
.onLoad <- function(libname, pkgname) {
assign("padegraphic",
list(p1d = list(horizontal = TRUE, reverse = FALSE, rug = list(draw = TRUE, tck = 0.5, margin = 0.07, line = TRUE)),
parrows = list(angle = 15, ends = "last", length = 0.1),
paxes = list(aspectratio = "iso", draw = FALSE, x = list(draw = TRUE), y = list(draw = TRUE)),
pbackground = list(col = "white", box = TRUE),
pellipses = list(alpha = 0.5, axes = list(draw = TRUE, col = "black", lty = 4, lwd = 1), border = "black", col = "transparent", lty = 1, lwd = 1),
pgrid = list(col = "grey", draw = TRUE, lty = 1, lwd = 1, nint = 5, text = list(cex = 1, col = "black", pos = "topright")),
plabels = list(alpha = 1, cex = 1, col = "black", srt = "horizontal", optim = FALSE,
boxes = list(alpha = 1, border = "black", col = "white", draw = TRUE, lwd = 1, lty = 1)),
plegend = list(drawKey = TRUE, drawColorKey = FALSE, size = 1),
plines = list(col = "black", lty = 1, lwd = 1),
pnb = list(edge = list(col = "black", lwd = 1, lty = 1), node = list(pch = 20, cex = 1, col = "black", alpha = 1)),
porigin = list(alpha = 1, col = "black", draw = TRUE, include = TRUE, lty = 1, lwd = 1, origin = c(0, 0)),
ppalette = list(quanti = colorRampPalette(c("white", "black")),
quali = function(n, name = "Set1") {
if(n > 9)
return(rainbow(n))
else if(n > 2)
return(brewer.pal(n, name))
else
return(brewer.pal(n + 2, name)[1:n])
}), ## see http://colorbrewer2.org/
ppoints = list(alpha = 1, cex = 1, col = "black", pch = 20, fill = "black"),
ppolygons = list(border = "black", col = "grey", lty = 1, lwd = 1, alpha = 0.4),
pSp = list(col = "grey", border = "black", lwd = 1, lty = 1, alpha = 1, cex = 3, pch = 20),
psub = list(cex = 1, col = "black", position = "bottomleft", text = ""),
ptable = list(x = list(srt = 0, pos = "top", tck = 5, adj = NA),
y = list(srt = 90, pos = "right", tck = 5, adj = NA),
margin = list(bottom = 5, left = 5, top = 5, right = 5))
),
envir = .ADEgEnv)
assign("adegtheme",
list(layout.heights = list(
top.padding = 0, main.key.padding = 0,
key.axis.padding = 0, axis.xlab.padding = 0,
xlab.key.padding = 0, key.sub.padding = 0,
bottom.padding = 0),
layout.widths = list(left.padding = 0, key.ylab.padding = 0, ylab.axis.padding = 0, axis.key.padding = 0, right.padding = 0),
background = list(col = "transparent", alpha = 1),
plot.polygon = list(col = "#F2F2F2"),
plot.line = list(col = "#000000"),
add.line = list(col = "#000000", lty = 2),
## clipping allows drawing to go outside panel (i.e : drawings) limits
as.table = TRUE
), envir = .ADEgEnv
)
changelatticetheme(get("adegtheme", envir = .ADEgEnv))
assign("currentadeg", list(), envir = .ADEgEnv)
}
adegraphics/R/C1.barchart.R 0000644 0001762 0000144 00000014066 13742303021 015102 0 ustar ligges users setClass(
Class = "C1.barchart",
contains = "ADEg.C1"
)
setMethod(
f = "initialize",
signature = "C1.barchart",
definition = function(.Object, data = list(score = NULL, labels = NULL, at = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.C1 initialize
.Object@data$labels <- data$labels
.Object@data$at <- data$at
validObject(.Object)
return(.Object)
})
setMethod(
f = "prepare",
signature = "C1.barchart",
definition = function(object) {
nameobj <- deparse(substitute(object))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
if(object@data$storeData) {
score <- object@data$score
at <- object@data$at
} else {
score <- eval(object@data$score, envir = sys.frame(object@data$frame))
at <- eval(object@data$at, envir = sys.frame(object@data$frame))
}
score <- as.matrix(score)[, 1] ## to manage 'score' when it is a data.frame with only one column
## change default for some parameters
if(adegtot$p1d$horizontal && is.null(object@adeg.par$plabels$srt))
adegtot$plabels$srt <- 0
else if(!adegtot$p1d$horizontal && is.null(object@adeg.par$plabels$srt))
adegtot$plabels$srt <- 90
if(is.null(object@adeg.par$plabels$boxes$draw))
adegtot$plabels$boxes$draw <- FALSE
adegtot$p1d$rug$draw <- FALSE
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
if(object@adeg.par$p1d$horizontal && is.null(object@g.args$ylim))
object@g.args$ylim <- setlimits1D(min(at), max(at), 0, FALSE)
if(!object@adeg.par$p1d$horizontal && is.null(object@g.args$xlim))
object@g.args$xlim <- setlimits1D(min(at), max(at), 0, FALSE)
assign(nameobj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "C1.barchart",
definition = function(object, x, y) {
## Drawing barchart
## x is the index
## y is the score
## get some parameters
pscore <- object@adeg.par$p1d
ppoly <- lapply(object@adeg.par$ppolygons, FUN = function(x) {rep(x, length.out = length(x))})
plabels <- lapply(object@adeg.par$plabels, FUN = function(x) {rep(x, length.out = length(x))})
if(object@data$storeData)
labels <- object@data$labels
else
labels <- eval(object@data$labels, envir = sys.frame(object@data$frame))
## manage string rotation
srt <- 0
if(is.numeric(plabels$srt[1]))
srt <- plabels$srt[1]
else {
if(plabels$srt[1] == "horizontal")
srt <- 0
else if(plabels$srt[1] == "vertical")
srt <- 90
}
## reorder values and labels
y <- y[order(x)]
labels <- labels[order(x)]
x <- sort(x)
## Starts the display
## depends on the parametres horizontal
## reverse and rug.draw are always considered as FALSE
if(pscore$horizontal) {
x.tmp <- y
y.tmp <- x
} else {
x.tmp <- x
y.tmp <- y
}
panel.barchart(x = x.tmp, y = y.tmp, horizontal = pscore$horizontal, box.width = 0.9, origin = 0, reference = FALSE,
border = ppoly$border, col = ppoly$col, lty = ppoly$lty, lwd = ppoly$lwd, alpha = ppoly$alpha)
## panel.text(x.tmp, y.tmp, labels)
if(!is.null(labels)) {
if(abs(sin(srt)) > sin(45)) {
## almost vertical labels
if(pscore$horizontal)
width <- stringWidth("h")
else
width <- stringWidth(labels) + stringWidth("h")
width <- rep(plabels$cex, length.out = length(labels)) * convertUnit(width, "native", typeFrom = "dimension", axisFrom = "x", axisTo = "y", valueOnly = TRUE) / 2
} else {
## almost horizont labels
if(pscore$horizontal)
width <- stringWidth(labels) + stringWidth("h")
else
width <- stringWidth("h")
width <- rep(plabels$cex, length.out = length(labels)) * convertUnit(width, "native", typeFrom = "dimension", axisFrom = "x", valueOnly = TRUE) / 2
}
if(pscore$horizontal)
adeg.panel.label(x = x.tmp + width * sign(x.tmp), y = y.tmp, labels = labels, plabels = plabels)
else
adeg.panel.label(x = x.tmp, y = y.tmp + width * sign(y.tmp), labels = labels, plabels = plabels)
}
})
s1d.barchart <- function(score, labels = NULL, at = 1:NROW(score), sort = FALSE, facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters
thecall <- .expand.call(match.call())
score <- eval(thecall$score, envir = sys.frame(sys.nframe() + pos))
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if(NCOL(score) == 1)
object <- multi.facets.C1(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple scores")
}
## multiple scores
else if(NCOL(score) > 1) {
object <- multi.score.C1(thecall)
}
## simple ADEg graphic
else {
# if score is sorted
if(sort)
at <- rank(score)
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(sort = sort))
if(storeData)
tmp_data <- list(score = score, labels = labels, at = at, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(score = thecall$score, labels = thecall$labels, at = thecall$at, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "C1.barchart", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = sortparameters$g.args, Call = match.call())
## preparation
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/S1.boxplot.R 0000644 0001762 0000144 00000021724 13742303021 015022 0 ustar ligges users ###########################################################
## s1d.boxplot ##
###########################################################
setClass(
Class = "S1.boxplot",
contains = "ADEg.S1"
)
setMethod(
f = "initialize",
signature = "S1.boxplot",
definition = function(.Object, data = list(score = NULL, fac = NULL, at = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.S1 initialize
.Object@data$fac <- data$fac
return(.Object)
})
setMethod(
f = "prepare",
signature = "S1.boxplot",
definition = function(object) {
name_obj <- deparse(substitute(object))
if(object@data$storeData)
fac <- as.factor(object@data$fac)
else
fac <- as.factor(eval(object@data$fac, envir = sys.frame(object@data$frame)))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
## change default for some parameters
if(adegtot$p1d$horizontal & is.null(object@adeg.par$plabels$srt))
adegtot$plabels$srt <- 0
else if(!adegtot$p1d$horizontal & is.null(object@adeg.par$plabels$srt))
adegtot$plabels$srt <- 90
## setting colors
paramsToColor <- list(ppoints = list(col = object@adeg.par$ppoints$col, fill = object@adeg.par$ppoints$fill),
plabels = list(col = object@adeg.par$plabels$col, boxes = list(border = object@adeg.par$plabels$boxes$border)),
plines = list(col = object@adeg.par$plines$col),
ppolygons = list(border = object@adeg.par$ppolygons$border, col = object@adeg.par$ppolygons$col))
if(!(is.null(object@g.args$col) || (is.logical(object@g.args$col) && !object@g.args$col)))
adegtot <- modifyList(adegtot, col2adepar(ccol = object@g.args$col, pparamsToColor = paramsToColor, nnlev = nlevels(fac)))
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "S1.boxplot",
definition = function(object, x, y) {
if(object@data$storeData) {
fac <- object@data$fac
at <- object@data$at
} else {
fac <- eval(object@data$fac, envir = sys.frame(object@data$frame))
at <- eval(object@data$at, envir = sys.frame(object@data$frame))
}
fac <- as.factor(fac)
nlev <- nlevels(fac)
labels <- levels(fac)
lims <- current.panel.limits(unit = "native")
pscore <- object@adeg.par$p1d
plabels <- object@adeg.par$plabels
## repeat graphical parameters (one for each level)
ppoints <- lapply(object@adeg.par$ppoints, FUN = function(x) x <- rep(x, length.out = nlev))
ppoints <- lapply(ppoints, FUN = function(x) x <- x[1:nlev])
plines <- lapply(object@adeg.par$plines, FUN = function(x) x <- rep(x, length.out = nlev))
plines <- lapply(plines, FUN = function(x) x <- x[1:nlev])
ppolygons <- lapply(object@adeg.par$ppolygons, FUN = function(x) x <- rep(x, length.out = nlev))
ppolygons <- lapply(ppolygons, FUN = function(x) x <- x[1:nlev])
## manage trellis parameters
oldcolsymbol <- trellis.par.get("plot.symbol")$col
oldcolumbrella <- trellis.par.get("box.umbrella")$col
oldcolrectangle <- trellis.par.get("box.rectangle")$col
trellis.par.set(list("plot.symbol" = list("col" = "black"), "box.umbrella" = list("col" = plines$col), "box.rectangle" = list("col" = ppolygons$border)))
on.exit(trellis.par.set(list("plot.symbol" = list("col" = oldcolsymbol), "box.umbrella" = list("col" = oldcolumbrella), "box.rectangle" = list("col" = oldcolrectangle))))
## manage string rotation
srt <- 0
if(is.numeric(plabels$srt[1]))
srt <- plabels$srt[1]
else {
if(plabels$srt[1] == "horizontal")
srt <- 0
else if(plabels$srt[1] == "vertical")
srt <- 90
}
gettextpos <- function(x, lim) {
if(length(x) != 2) {
## if no data in the given level
return(c(NA, NA))
} else {
if(abs(lim[2] - x[2]) > abs(lim[1] - x[1]))
return(c(x[2], 1))
else
return(c(x[1], -1))
}
}
if(pscore$horizontal) {
## horizontal plot
ylab <- at
if(length(ylab) > 1)
bwid <- diff(range(ylab)) / (nlev + 1)
else
bwid <- 1 / 10
## panel.bwplot
do.call("panel.bwplot", list(x = y, y = ylab[fac], box.ratio = bwid, coef = 1.5, pch = "|", horizontal = TRUE))
## add means
do.call("panel.points", c(list(x = (tapply(y, fac, mean)), y = ylab), ppoints))
minmax <- tapply(y, fac, range)
etis <- sapply(minmax, gettextpos, lim = lims$xlim)
} else {
## vertical plot
xlab <- at
if(length(xlab) > 1)
bwid <- diff(range(xlab)) / (nlev + 1)
else
bwid <- 1 / 10
## panel.bwplot
do.call("panel.bwplot", list(x = xlab[fac], y = y, box.ratio = bwid, coef = 1.5, pch = "|", horizontal = FALSE))
## add means
do.call("panel.points", c(list(y = (tapply(y, fac , mean)), x = xlab), ppoints))
minmax <- tapply(y, fac, range)
etis <- sapply(minmax, gettextpos, lim = lims$ylim)
}
## draw labels
if(abs(sin(srt)) > sin(45)) {
## almost vertical labels
if(pscore$horizontal)
width <- stringWidth("h")
else
width <- stringWidth(labels) + stringWidth("h")
width <- rep(plabels$cex, length.out = length(labels)) * convertUnit(width, "native", typeFrom = "dimension", axisFrom = "x", axisTo = "y", valueOnly = TRUE) / 2
} else {
## almost horizontal labels
if(pscore$horizontal)
width <- stringWidth(labels) + stringWidth("h")
else
width <- stringWidth("h")
width <- rep(plabels$cex, length.out = length(labels)) * convertUnit(width, "native", typeFrom = "dimension", axisFrom = "x", valueOnly = TRUE) / 2
}
if(pscore$horizontal)
adeg.panel.label(x = etis[1, ] + etis[2, ] * width, y = ylab, labels = labels, plabels = plabels)
else
adeg.panel.label(x = xlab, y = etis[1, ] + etis[2, ] * width, labels = labels, plabels = plabels)
})
## For boxplot, parameters can only be changed using par.settings arguments;
setMethod(
f = "setlatticecall",
signature = "S1.boxplot",
definition = function(object) {
name_obj <- deparse(substitute(object))
callNextMethod()
ppolygons <- object@adeg.par$ppolygons
object@lattice.call$arguments$par.settings <- modifyList(list(box.rectangle = c(list(col = ppolygons$border, fill = ppolygons$col),
ppolygons[-c(which(names(ppolygons) == "border" | (names(ppolygons) == "col")))]), box.umbrella = object@adeg.par$plines,
plot.symbol = modifyList(list(col = "black", fill = "black"), object@adeg.par$ppoints)), object@lattice.call$arguments$par.settings, keep.null = TRUE)
assign(name_obj, object, envir = parent.frame())
})
s1d.boxplot <- function(score, fac = gl(1, NROW(score)), at = 1:nlevels(fac), col = NULL, facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters
thecall <- .expand.call(match.call())
fac <- eval(thecall$fac, envir = sys.frame(sys.nframe() + pos))
score <- eval(thecall$score, envir = sys.frame(sys.nframe() + pos))
if(NROW(fac) != NROW(score))
stop("fac and score must have the same number of rows")
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if(NCOL(score) == 1 & NCOL(fac) == 1)
object <- multi.facets.S1(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple scores or fac")
}
## multiple scores
else if(NCOL(score) > 1) {
if(NCOL(fac) == 1)
object <- multi.score.S1(thecall)
else
stop("Multiple scores are not allowed with multiple fac")
}
## multiple fac
else if(NCOL(fac) > 1) {
object <- multi.variables.S1(thecall, "fac")
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(col = col))
if(storeData)
tmp_data <- list(score = score, fac = fac, at = at, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(score = thecall$score, fac = fac, at = thecall$at, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "S1.boxplot", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = match.call())
## preparation
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/utilsclass.R 0000644 0001762 0000144 00000005713 13742303021 015237 0 ustar ligges users
#### revoir cette fonction ####
.util.ellipse <- function(mx, my, vx, vy, cxy, coeff) {
if(!is.finite(mx) | !is.finite(my)) ## levels with no individuals
return(NULL)
lig <- 100
epsi <- 1e-10
x <- 0
y <- 0
if(vx < 0)
vx <- 0
if(vy < 0)
vy <- 0
if(vx == 0 && vy == 0)
return(NULL)
delta <- (vx - vy) * (vx - vy) + 4 * cxy * cxy
delta <- sqrt(delta)
l1 <- (vx + vy + delta) / 2
l2 <- vx + vy - l1
if(l1 < 0)
l1 <- 0
if(l2 < 0)
l2 <- 0
l1 <- sqrt(l1)
l2 <- sqrt(l2)
test <- 0
if(vx == 0) {
a0 <- 0
b0 <- 1
test <- 1
}
if((vy == 0) && (test == 0)) {
a0 <- 1
b0 <- 0
test <- 1
}
if(((abs(cxy)) < epsi) && (test == 0)) {
if(vx > vy){
a0 <- 1
b0 <- 0
} else {
a0 <- 0
b0 <- 1
}
test <- 1
}
if(test == 0) {
a0 <- 1
b0 <- (l1 * l1 - vx) / cxy
norm <- sqrt(a0 * a0 + b0 * b0)
a0 <- a0 / norm
b0 <- b0 / norm
}
a1 <- 2 * pi / lig
c11 <- coeff * a0 * l1
c12 <- (-coeff) * b0 * l2
c21 <- coeff * b0 * l1
c22 <- coeff * a0 * l2
angle <- 0
for (i in 1:lig) {
cosinus <- cos(angle)
sinus <- sin(angle)
x[i] <- mx + c11 * cosinus + c12 * sinus
y[i] <- my + c21 * cosinus + c22 * sinus
if(is.null(mx + c11 * cosinus + c12 * sinus) || is.null(y[i] <- my + c21 * cosinus + c22 * sinus))
print("in util.ellipse x or y null")
angle <- angle + a1
}
return(list(x = x, y = y, seg1 = c(mx + c11, my + c21, mx - c11, my - c21), seg2 = c(mx + c12, my + c22, mx - c12, my - c22)))
}
## Nouvelle version:
## principe:
## 1) calcul de distance entre les points appartenant a un groupe et le centroides du groupe
## 2) extraction du quantile correspondant a optchull (les % d les plus eloignes forment le polugfone
## x, y: points, mx, my: coordonnees des centroides, optchull: paramètre voulu pour lenvellope converxe, fac: facteur separeant les poitns
.util.chull <- function(x, y, mx, my, fac, chullSize) {
## pour chaque groupe calcul des distances
chulls <- list()
for(i in 1:nlevels(fac)) { ## attention fac est passe en facteur!
index <- which(fac == levels(fac)[i])
if(length(index) > 0) {
x1 <- x[index]
y1 <- y[index]
dd <- sqrt((x1 - mx[i])^2 + (y1 - my[i])^2) ## distances chaque points a la moyenne
tmp_quant <- list()
for(quant in chullSize) { ## pour chaque envelope demandee
selected <- which(dd <= quantile(dd, quant)) ## points en dessous du quant
xin <- x1[selected]
yin <- y1[selected]
chullchoice <- chull(xin, yin) ## points formant la convex hull
x2 <- xin[chullchoice]
y2 <- yin[chullchoice]
tmp_quant <- c(tmp_quant, list(cbind(x2, y2))) ## coord des points formant le polygone
}
names(tmp_quant) <- as.character(chullSize)
} else
tmp_quant <- NULL
chulls <- c(chulls, list(tmp_quant))
}
names(chulls) <- as.character(levels(fac))
return(chulls)
}
adegraphics/R/S2.arrow.R 0000644 0001762 0000144 00000011164 14354572530 014500 0 ustar ligges users ##########################################################################
## s.arrow ##
##########################################################################
setClass(
Class = "S2.arrow",
contains = "ADEg.S2"
)
setMethod(
f = "initialize",
signature = "S2.arrow",
definition = function(.Object, data = list(dfxy = NULL, xax = 1, yax = 2, labels = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.S2 initialize
.Object@data$labels <- data$labels
return(.Object)
})
setMethod(
f = "prepare",
signature = "S2.arrow",
definition = function(object) {
name_obj <- deparse(substitute(object))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
## change default for some parameters
if(is.null(object@adeg.par$ppoints$cex))
adegtot$ppoints$cex <- 0
if(is.null(object@adeg.par$porigin$include) & (any(names(object@g.args) %in% c("Sp", "nbobject"))))
adegtot$porigin$include <- FALSE
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
if(is.null(object@s.misc$lim.update)) {
if(is.null(object@g.args$Sp)) {
xdiff <- diff(object@g.args$xlim)
ydiff <- diff(object@g.args$ylim)
object@g.args$xlim <- object@g.args$xlim + c(-1, 1) * 0.05 * xdiff
object@g.args$ylim <- object@g.args$ylim + c(-1, 1) * 0.05 * ydiff
}
object@s.misc$lim.update <- TRUE
}
## never optimized labels for s.arrow
object@adeg.par$plabels$optim <- FALSE
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "S2.arrow",
definition = function(object, x, y) {
## draw arrows
panel.arrows(x0 = object@adeg.par$porigin$origin[1], y0 = object@adeg.par$porigin$origin[2], y1 = y, x1 = x, angle = object@adeg.par$parrows$angle,
length = object@adeg.par$parrows$length, ends = object@adeg.par$parrows$end, lwd = object@adeg.par$plines$lwd,
col = object@adeg.par$plines$col, lty = object@adeg.par$plines$lty)
## draw labels
## positions
plabels <- object@adeg.par$plabels
if(object@data$storeData)
arrownames <- object@data$labels
else
arrownames <- eval(object@data$labels, envir = sys.frame(object@data$frame))
if(!is.null(arrownames)) {
pos <- .textpos(x, y, origin = c(0, 0))
test <- .textsize(arrownames, plabels)
w <- test$w
h <- test$h
if(any(object@adeg.par$plabels$cex > 0))
adeg.panel.label(x + pos[1, ] * w / 2, y + pos[2, ] * h / 2 , arrownames, plabels)
}
})
s.arrow <- function(dfxy, xax = 1, yax = 2, labels = row.names(as.data.frame(dfxy)), facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters (required for multiplot)
thecall <- .expand.call(match.call())
df <- try(as.data.frame(eval(thecall$dfxy, envir = sys.frame(sys.nframe() + pos))), silent = TRUE)
if(inherits(df, "try-error") | is.null(thecall$dfxy)) ## non convenient dfxy argument
stop("non convenient selection for dfxy (can not be converted to dataframe)")
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if((length(xax) == 1 & length(yax) == 1))
object <- multi.facets.S2(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple xax/yax")
}
## multiple axes
else if((length(xax) > 1 | length(yax) > 1)) {
object <- multi.ax.S2(thecall)
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
if(storeData)
tmp_data <- list(dfxy = dfxy, xax = xax, yax = yax, labels = labels, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(dfxy = thecall$dfxy, xax = xax, yax = yax, labels = thecall$labels, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "S2.arrow", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = sortparameters$g.args, Call = as.call(thecall))
## preparation
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/S2.class.R 0000644 0001762 0000144 00000025067 14354572556 014472 0 ustar ligges users ##########################################################################
## s.class ##
##########################################################################
setClass(
Class = "S2.class",
contains = "ADEg.S2"
)
setMethod(
f = "initialize",
signature = "S2.class",
definition = function(.Object, data = list(dfxy = NULL, xax = 1, yax = 2, fac = NULL, wt = NULL, labels = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...)
.Object@data$fac <- data$fac
.Object@data$wt <- data$wt
.Object@data$labels <- data$labels
return(.Object)
})
setMethod(
## prepare computations for ellipses, stars and labels
f = "prepare",
signature = "S2.class",
definition = function(object) {
name_obj <- deparse(substitute(object))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
if(object@data$storeData) {
fac <- as.factor(object@data$fac)
dfxy <- object@data$dfxy
wt <- object@data$wt
} else {
fac <- as.factor(eval(object@data$fac, envir = sys.frame(object@data$frame)))
dfxy <- eval(object@data$dfxy, envir = sys.frame(object@data$frame))
wt <- eval(object@data$wt, envir = sys.frame(object@data$frame))
}
## change default for some parameters
if(is.null(object@adeg.par$porigin$include) & (any(names(object@g.args) %in% c("Sp", "nbobject"))))
adegtot$porigin$include <- FALSE
if(any(adegtot$plabels$cex > 0) & is.null(object@adeg.par$plegend$drawKey)) ## if labels, no legend
adegtot$plegend$drawKey <- FALSE
## setting colors
paramsToColor <- list(ppoints = list(col = object@adeg.par$ppoints$col, fill = object@adeg.par$ppoints$fill),
plabels = list(col = object@adeg.par$plabels$col, boxes = list(border = object@adeg.par$plabels$boxes$border)),
plines = list(col = object@adeg.par$plines$col),
pellipses = list(border = object@adeg.par$pellipses$border, col = object@adeg.par$pellipses$col),
ppolygons = list(border = object@adeg.par$ppolygons$border, col = object@adeg.par$ppolygons$col))
if(!(is.null(object@g.args$col) || (is.logical(object@g.args$col) && !object@g.args$col)))
adegtot <- modifyList(adegtot, col2adepar(ccol = object@g.args$col, pparamsToColor = paramsToColor, nnlev = nlevels(fac)))
## preliminary computations
object@stats$means <- matrix(meanfacwt(dfxy[, c(object@data$xax, object@data$yax)], fac, wt), nrow = nlevels(fac))
## for ellipse, covariance and variance needed
if(object@g.args$ellipseSize)
object@stats$covvar <- covfacwt(dfxy[, c(object@data$xax, object@data$yax)], fac, wt)
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
## compute ellipses
if(object@g.args$ellipseSize > 0) {
object@s.misc$ellipses <- lapply(1:nlevels(fac), FUN = function(i) {
.util.ellipse(object@stats$means[i, 1], object@stats$means[i, 2], vx = object@stats$covvar[[i]][1, 1], vy = object@stats$covvar[[i]][2, 2],
cxy = object@stats$covvar[[i]][1, 2], coeff = object@g.args$ellipseSize)
})
}
## compute convex hulls
if(!is.null(object@g.args$chullSize))
if(any(object@g.args$chullSize > 0))
object@s.misc$chullcoord <- .util.chull(dfxy[, object@data$xax], dfxy[, object@data$yax], object@stats$means[, 1], object@stats$means[, 2], fac = fac, chullSize = object@g.args$chullSize)
## never optimized labels for s.class
object@adeg.par$plabels$optim <- FALSE
assign(name_obj, object, envir = parent.frame())
})
## a changer: dessin level par level,
setMethod(
f = "panel",
signature = "S2.class",
definition = function(object, x, y) {
if(object@data$storeData) {
fac <- object@data$fac
labels <- object@data$labels
} else {
fac <- eval(object@data$fac, envir = sys.frame(object@data$frame))
labels <- eval(object@data$labels, envir = sys.frame(object@data$frame))
}
nlev <- nlevels(fac)
## convex hulls
if(any(object@g.args$chullSize > 0)) {
chullpo <- object@s.misc$chullcoord
ppolygons <- lapply(object@adeg.par$ppolygons, FUN = function(x) {rep(x, length.out = length(chullpo))})
for(level in 1:nlev)
if(!any(is.null(chullpo[[level]]))) {
for(j in 1:length(chullpo[[level]]))
panel.polygon(
x = chullpo[[level]][[j]][, 1], y = chullpo[[level]][[j]][, 2],
border = ppolygons$border[level], col = ppolygons$col[level],
lty = ppolygons$lty[level], lwd = ppolygons$lwd[level], alpha = ppolygons$alpha[level])
}
}
## ellipses
if(object@g.args$ellipseSize > 0) {
ellip <- object@s.misc$ellipses
pellip <- object@adeg.par$pellipses
pellip <- lapply(pellip, FUN = function(x) {if(is.list(x)) return(x) else rep(x, le = length(ellip))})
pellip$axes <- lapply(pellip$axes, FUN = function(x) {rep(x, length.out = length(ellip))})
for(level in 1:nlev) { ## for each group
ell <- ellip[[level]]
if(!(any(is.null(ell))))
if(!any(is.na(ell))) {
panel.polygon(ell$x, ell$y, col = pellip$col[level], lwd = pellip$lwd[level], lty = pellip$lty[level], alpha = pellip$alpha[level], border = pellip$border[level])
if(pellip$axes$draw[level]) { ## axes drawing
panel.segments(ell$seg1[1], ell$seg1[2], ell$seg1[3], ell$seg1[4], lwd = pellip$axes$lwd[level], lty = pellip$axes$lty[level], col = pellip$axes$col[level])
panel.segments(ell$seg2[1], ell$seg2[2], ell$seg2[3], ell$seg2[4], lwd = pellip$axes$lwd[level], lty = pellip$axes$lty[level], col = pellip$axes$col[level])
}
}
}
}
## stars
if(object@g.args$starSize > 0) {
plines <- lapply(object@adeg.par$plines, FUN = function(x) {rep(x, length.out = nlev)})
for(level in 1:nlev) {
if(all(is.finite(object@stats$means[level, ]))) {
xbase <- object@stats$means[level, 1]
ybase <- object@stats$means[level, 2]
xlev <- x[fac == levels(fac)[level]]
ylev <- y[fac == levels(fac)[level]]
panel.segments(
x0 = xbase,
y0 = ybase,
x1 = xbase + object@g.args$starSize * (xlev - xbase),
y1 = ybase + object@g.args$starSize * (ylev - ybase),
lty = plines$lty[level], lwd = plines$lwd[level], col = plines$col[level])
}
}
}
## plot points
if(any(object@adeg.par$ppoints$cex > 0)) {
ppoints <- object@adeg.par$ppoints
if(nlev > 1) {
ppoints <- lapply(object@adeg.par$ppoints, FUN = function(x, fac, nlev) {
if(length(x) > nlev)
return(x)
else {
xlev <- rep(x, length.out = nlev)
xpar <- xlev[fac]
return(xpar)
}
}, fac = fac, nlev = nlev)
}
if(any(is.na(ppoints$pch))) {
indx <- 1:length(x)
indx <- indx[- which(is.na(ppoints$pch))]
panel.points(x = x[indx], y = y[indx], type = "p", pch = ppoints$pch[indx], cex = ppoints$cex[indx],
col = ppoints$col[indx], alpha = ppoints$alpha[indx], fill = ppoints$fill[indx])
} else
panel.points(x = x, y = y, type = "p", pch = ppoints$pch, cex = ppoints$cex, col = ppoints$col,
alpha = ppoints$alpha, fill = ppoints$fill)
}
## plot of labels
if(any(object@adeg.par$plabels$cex > 0)) {
labX <- object@stats$means[, 1]
labY <- object@stats$means[, 2]
adeg.panel.label(x = labX, y = labY, labels = labels, object@adeg.par$plabels)
}
})
s.class <- function(dfxy, fac, xax = 1, yax = 2, wt = rep(1, NROW(fac)), labels = levels(fac), ellipseSize = 1.5, starSize = 1,
chullSize = NULL, col = NULL, facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters (required for multiplot)
thecall <- .expand.call(match.call())
labels <- eval(thecall$labels, envir = sys.frame(sys.nframe() + pos))
fac <- eval(thecall$fac, envir = sys.frame(sys.nframe() + pos))
df <- try(as.data.frame(eval(thecall$dfxy, envir = sys.frame(sys.nframe() + pos))), silent = TRUE)
if(inherits(df, "try-error") | is.null(thecall$dfxy)) ## non convenient dfxy argument
stop("non convenient selection for dfxy (can not be converted to dataframe)")
if(missing(fac))
stop("no factor specified")
if(NCOL(fac) == 1) {
fac <- as.factor(fac)
if(length(labels) != nlevels(fac))
stop("wrong number of labels")
}
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if((length(xax) == 1 & length(yax) == 1) & NCOL(fac) == 1)
object <- multi.facets.S2(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple xax/yax or multiple fac")
}
## multiple axes
else if((length(xax) > 1 | length(yax) > 1)) {
if(NCOL(fac) == 1)
object <- multi.ax.S2(thecall)
else
stop("Multiple xax/yax are not allowed with multiple fac")
}
## multiple fac
else if(NCOL(fac) > 1) {
object <- multi.variables.S2(thecall, "fac")
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(ellipseSize = ellipseSize, starSize = starSize, chullSize = chullSize, col = col))
if(storeData)
tmp_data <- list(dfxy = dfxy, fac = fac, xax = xax, yax = yax, wt = wt, labels = labels, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(dfxy = thecall$dfxy, fac = thecall$fac, xax = xax, yax = yax, wt = thecall$wt, labels = thecall$labels, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "S2.class", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = as.call(thecall))
## preparation of the graph
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(! add & plot)
print(object)
invisible(object)
}
adegraphics/R/Tr.traject.R 0000644 0001762 0000144 00000016311 14572276635 015113 0 ustar ligges users ######################################################
## Tr.traject ###
######################################################
setClass(
Class = "Tr.traject",
contains = "ADEg.Tr"
)
setMethod(
f = "initialize",
signature = "Tr.traject",
definition = function(.Object, data = list(dfxyz = NULL, fac = NULL, labels = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...)
.Object@data$fac <- data$fac
.Object@data$labels <- data$labels
return(.Object)
})
setMethod(
f = "prepare",
signature = "Tr.traject",
definition = function(object) {
name_obj <- deparse(substitute(object))
if(object@data$storeData) {
df <- object@data$dfxyz
fac <- as.factor(object@data$fac)
} else {
df <- eval(object@data$dfxyz, envir = sys.frame(object@data$frame))
fac <- as.factor(eval(object@data$fac, envir = sys.frame(object@data$frame)))
}
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
## setting colors
paramsToColor <- list(ppoints = list(col = object@adeg.par$ppoints$col, fill = object@adeg.par$ppoints$fill),
plabels = list(col = object@adeg.par$plabels$col, boxes = list(border = object@adeg.par$plabels$boxes$border)),
plines = list(col = object@adeg.par$plines$col))
if(!(is.null(object@g.args$col) || (is.logical(object@g.args$col) && !object@g.args$col)))
adegtot <- modifyList(adegtot, col2adepar(ccol = object@g.args$col, pparamsToColor = paramsToColor, nnlev = nlevels(fac)))
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
## calculate 2D coordinates
df <- sweep(df, 1, rowSums(df), "/")
object@stats$coords2d <- .coordtotriangleM(df, mini3 = object@g.args$min3d, maxi3 = object@g.args$max3d)[, 2:3]
## never optimized labels for triangle.traject
object@adeg.par$plabels$optim <- FALSE
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "Tr.traject",
definition = function(object, x, y) {
if(object@data$storeData) {
fact <- object@data$fac
labels <- object@data$labels
} else {
fact <- eval(object@data$fac, envir = sys.frame(object@data$frame))
labels <- eval(object@data$labels, envir = sys.frame(object@data$frame))
}
todrawX <- split(object@stats$coords2d[, 1], fact)
todrawY <- split(object@stats$coords2d[, 2], fact)
sizelevels <- unlist(lapply(todrawX, length))
if(!is.null(object@g.args$order))
orderdraw <- split(order, fact)
else
orderdraw <- lapply(sizelevels, FUN = function(x) if(x > 0) 1:x else NULL)
## ordrerdraw is a list used to recycle graphical parameters
setparam <- function(params, nblevel, sizelevels) {
## for param begin and end or repetition
if(length(params) == nblevel)
return(mapply(params, FUN = function(x, y) rep(x, length.out = y), sizelevels, SIMPLIFY = FALSE))
else
return(mapply(sizelevels, FUN = function(x, y) rep(params, length.out = x), SIMPLIFY = FALSE))
}
parrows <- lapply(object@adeg.par$parrows, setparam, nblevel = length(todrawX), sizelevels = sizelevels)
plines <- lapply(object@adeg.par$plines, setparam, nblevel = length(todrawX), sizelevels = sizelevels)
ppoints <- lapply(object@adeg.par$ppoints, setparam, nblevel = length(todrawX), sizelevels = sizelevels)
for(i in 1:length(todrawX)) {
if(length(todrawX[[i]]) > 0)
panel.points(x = todrawX[[i]], y = todrawY[[i]], col = ppoints$col[[i]], cex = ppoints$cex[[i]], pch = ppoints$pch[[i]], fill = ppoints$fill[[i]])
}
for(i in 1:length(todrawX)) {
if(length(todrawX[[i]]) > 1) {
suborder <- orderdraw[[i]]
for(j in 1:(length(todrawX[[i]]) - 1)) {
panel.arrows(x0 = todrawX[[i]][suborder[j]], y0 = todrawY[[i]][suborder[j]],
x1 = todrawX[[i]][suborder[j + 1]], y1 = todrawY[[i]][suborder[j + 1]],
angle = parrows$angle[[i]][suborder[j + 1]], length = parrows$length[[i]][suborder[j + 1]],
ends = parrows$end[[i]][suborder[j + 1]], lwd = plines$lwd[[i]][suborder[j + 1]],
col = plines$col[[i]][suborder[j + 1]], lty = plines$lty[[i]][suborder[j + 1]])
}
}
}
if(any(object@adeg.par$plabels$cex > 0)) {
## draws labels in the middle part of the trajectory
middl <- unlist(lapply(orderdraw, FUN = function(x) floor(length(x) / 2)))
x <- y <- rep(NA, length(middl))
for(i in 1:length(middl)) {
if(length(todrawX[[i]]) > 1) {
x[i] <- (todrawX[[i]][suborder[middl[i]]] + todrawX[[i]][suborder[middl[i]+1]]) / 2
y[i] <- (todrawY[[i]][suborder[middl[i]]] + todrawY[[i]][suborder[middl[i]+1]]) / 2
}
}
adeg.panel.label(x, y, labels = labels, plabels = object@adeg.par$plabels)
}
})
triangle.traject <- function(dfxyz, fac = gl(1, nrow(dfxyz)), order, labels = levels(fac), col = NULL, adjust = TRUE,
min3d = NULL, max3d = NULL, showposition = TRUE, facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## dfxyz: matrix/data.frame with 3 columns
## min3d, max3d: limits by default: c(0,0,0), c(1,1,1)
thecall <- .expand.call(match.call())
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if(NCOL(fac) == 1)
object <- multi.facets.Tr(thecall, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed multiple fac")
}
## multiple fac
else if(NCOL(fac) > 1) {
object <- multi.variables.Tr(thecall, "fac")
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(adjust = adjust, min3d = min3d, max3d = max3d, col = col, order = thecall$order))
if(storeData)
tmp_data <- list(dfxyz = dfxyz, fac = fac, labels = labels, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(dfxyz = thecall$dfxyz, fac = thecall$fac, labels = thecall$labels, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "Tr.traject", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = match.call())
## preparation
prepare(object)
setlatticecall(object)
if(showposition & add) {
print("cannot show position and add") ## can be done, but modifies the meaning of the superposition
showposition <- FALSE
}
if(showposition)
object <- new(Class = "ADEgS", ADEglist = list("triangle" = object, "positions" = .showpos(object)), positions = rbind(c(0, 0, 1, 1), c(0, 0.7, 0.3, 1)), add = matrix(0, ncol = 2, nrow = 2), Call = match.call())
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/addline.R 0000644 0001762 0000144 00000005514 13742303021 014450 0 ustar ligges users setMethod(
f = "addline",
signature = "ADEg",
definition = function(object, a = NULL, b = 0, h = NULL, v = NULL, plot = TRUE, ...) {
# collect limits
xlim <- object@g.args$xlim
ylim <- object@g.args$ylim
aspect <- object@adeg.par$paxes$aspectratio
## sorting parameters
sortparameters <- sortparamADEg(...)$adepar
params <- adegpar()
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
params <- sortparameters$plines
lineadded <- xyplot(0 ~ 0, xlim = xlim, ylim = ylim, xlab = NULL, ylab = NULL, aspect = aspect, mya = a, myb = b, myh = h, myv = v,
panel = function(x, y, ...) panel.abline(a = a, b = b, h = h, v = v, lwd = params$lwd, lty = params$lty, col = params$col), plot = FALSE)
lineadded$call <- call("xyplot", 0 ~ 0, xlim = substitute(xlim), ylim = substitute(ylim), xlab = NULL, ylab = NULL,
aspect = substitute(aspect), lwd = params$lwd, lty = params$lty, col = params$col,
a = substitute(a), b = substitute(b), h = substitute(h), v = substitute(v),
panel = function(x, y, ...) panel.abline(a = a, b = b, h = h, v = v))
# superposition
obj <- superpose(object, lineadded, plot = FALSE)
nn <- all.names(substitute(object))
names(obj) <- c(ifelse(is.na(nn[2]), nn[1], nn[2]), "lineadded")
if(plot)
print(obj)
invisible(obj)
})
setMethod(
f = "addline",
signature = "ADEgS",
definition = function(object, a = NULL, b = 0, h = NULL, v = NULL, plot = TRUE, which = 1:length(object), ...) {
ngraph <- length(object)
if(max(which) > ngraph)
stop("Values in 'which' should be lower than the length of object")
if(length(which) == 1) {
object[[which]] <- addline(object[[which]], a = a, b = b, h = h, v = v, ..., plot = FALSE)
} else {
if(sum(object@add) != 0)
stop("The 'addline' function is not available for superposed objects.", call. = FALSE)
## sorting parameters
sortparameters <- sortparamADEg(...)$adepar
params <- adegpar()
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
params <- sortparameters$plines
params <- rapply(params, function(X) rep(X, length.out = length(which)), how = "list")
if(!is.null(a)) a <- rep_len(a, length.out = length(which))
b <- rep_len(b, length.out = length(which))
if(!is.null(h)) h <- rep_len(h, length.out = length(which))
if(!is.null(v)) v <- rep_len(v, length.out = length(which))
for (i in which)
object[[i]] <- addline(object[[i]], a = a[i], b = b[i], h = h[i], v = v[i], which = 1, plot = FALSE, plines = lapply(params, function(X) X[i]))
}
obj <- object
if(plot)
print(obj)
invisible(obj)
}) adegraphics/R/S1.distri.R 0000644 0001762 0000144 00000015531 13742303021 014630 0 ustar ligges users ###########################################################
## s1d.distri ##
###########################################################
setClass(
Class = "S1.distri",
contains = "ADEg.S1"
)
setMethod(
f = "initialize",
signature = "S1.distri",
definition = function(.Object, data = list(score = NULL, dfdistri = NULL, labels = NULL, at = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.S1 initialize
.Object@data$dfdistri <- data$dfdistri
.Object@data$labels <- data$labels
return(.Object)
})
setMethod(
f = "prepare",
signature = "S1.distri",
definition = function(object) {
name_obj <- deparse(substitute(object))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
if(object@data$storeData) {
dfdistri <- object@data$dfdistri
score <- object@data$score
labels <- object@data$labels
} else {
dfdistri <- eval(object@data$dfdistri, envir = sys.frame(object@data$frame))
score <- eval(object@data$score, envir = sys.frame(object@data$frame))
labels <- eval(object@data$labels, envir = sys.frame(object@data$frame))
}
score <- as.matrix(score)[, 1] ## to manage 'score' when it is a data.frame with only one column
## change default for some parameters
if(adegtot$p1d$horizontal & is.null(object@adeg.par$plabels$srt))
adegtot$plabels$srt <- 0
else if(!adegtot$p1d$horizontal & is.null(object@adeg.par$plabels$srt))
adegtot$plabels$srt <- 90
## statistics calculus
object@stats$means <- sapply(dfdistri, function(x) weighted.mean(score, x))
names(object@stats$means) <- labels
object@stats$sds <- sapply(dfdistri, function(x) sqrt(varwt(score, x)))
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "S1.distri",
definition = function(object, x, y) {
if(object@data$storeData) {
labels <- object@data$labels
at <- object@data$at
} else {
labels <- eval(object@data$labels, envir = sys.frame(object@data$frame))
at <- eval(object@data$at, envir = sys.frame(object@data$frame))
}
lims <- current.panel.limits(unit = "native")
pscore <- object@adeg.par$p1d
ngroups <- length(object@stats$means)
means <- object@stats$means
sds <- object@stats$sds * object@g.args$sdSize
plabels <- object@adeg.par$plabels
lead <- ifelse(pscore$reverse, -1, 1)
if(pscore$horizontal) {
## horizontal plot
ylab <- at
if(object@g.args$yrank) {
idx <- order(means, decreasing = TRUE)
means <- means[idx]
sds <- sds[idx]
labels <- labels[idx]
}
do.call("panel.segments", c(list(x0 = means - sds, y0 = ylab, x1 = means + sds, y1 = ylab), object@adeg.par$plines))
do.call("panel.points", c(list(x = means, y = ylab), object@adeg.par$ppoints))
etis <- ifelse(abs(lims$xlim[2] - (means + sds)) > abs(lims$xlim[1] - (means - sds)), 1, -1)
} else {
## vertical plot
xlab <- at
if(object@g.args$yrank) {
idx <- order(means, decreasing = TRUE)
means <- means[idx]
sds <- sds[idx]
labels <- labels[idx]
}
do.call("panel.segments", c(list(x0 = xlab, y0 = means - sds, x1 = xlab, y1 = means + sds), object@adeg.par$plines))
do.call("panel.points", c(list(x = xlab, y = means), object@adeg.par$ppoints))
etis <- ifelse(abs(lims$ylim[2] - (means + sds)) > abs(lims$ylim[1] - (means - sds)), 1, -1)
}
## manage string rotation
srt <- 0
if(is.numeric(plabels$srt[1]))
srt <- plabels$srt[1]
else {
if(plabels$srt[1] == "horizontal")
srt <- 0
else if(plabels$srt[1] == "vertical")
srt <- 90
}
## draw labels
if(abs(sin(srt)) > sin(45)) {
## almost vertical labels
if(pscore$horizontal)
width <- stringWidth("h")
else
width <- stringWidth(labels) + stringWidth("h")
width <- rep(plabels$cex, length.out = length(labels)) * convertUnit(width, "native", typeFrom = "dimension", axisFrom = "x", axisTo = "y", valueOnly = TRUE) / 2
} else {
## almost horizont labels
if(pscore$horizontal)
width <- stringWidth(labels) + stringWidth("h")
else
width <- stringWidth("h")
width <- rep(plabels$cex, length.out = length(labels)) * convertUnit(width, "native", typeFrom = "dimension", axisFrom = "x", valueOnly = TRUE) / 2
}
if(pscore$horizontal)
adeg.panel.label(x = means + etis * (sds + width), y = ylab, labels = labels, plabels = plabels)
else
adeg.panel.label(x = xlab, y = means + etis * (sds + width), labels = labels, plabels = plabels)
})
s1d.distri <- function(score, dfdistri, labels = colnames(dfdistri), at = 1:NCOL(dfdistri), yrank = TRUE, sdSize = 1, facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters (required for multiplot)
thecall <- .expand.call(match.call())
dfdistri <- eval(thecall$dfdistri, envir = sys.frame(sys.nframe() + pos))
score <- eval(thecall$score, envir = sys.frame(sys.nframe() + pos))
if(NROW(dfdistri) != NROW(score))
stop("dfdis and score must have the same number of rows")
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)){
if(NCOL(score) == 1)
object <- multi.facets.S1(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple scores")
}
## multiple scores
else if(NCOL(score) > 1) {
object <- multi.score.S1(thecall)
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(yrank = yrank, sdSize = sdSize))
if(storeData)
tmp_data <- list(score = score, dfdistri = dfdistri, at = at, labels = labels, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(score = thecall$score, dfdistri = thecall$dfdistri, at = thecall$at, labels = labels, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "S1.distri", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = match.call())
## preparation
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/ADEg.Tr.R 0000644 0001762 0000144 00000017506 14572570030 014210 0 ustar ligges users setClass(
Class = "ADEg.Tr",
contains = c("ADEg", "VIRTUAL"),
slots = c(data = "list")
)
setMethod(
f = "initialize",
signature = "ADEg.Tr",
definition = function(.Object, data = list(dfxyz = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, ...) ## ADEg initialize
.Object@data <- data
return(.Object)
})
setMethod(
f = "prepare",
signature = "ADEg.Tr",
definition = function(object) {
name_obj <- deparse(substitute(object))
if(object@data$storeData)
df <- object@data$dfxyz
else
df <- eval(object@data$dfxyz, envir = sys.frame(object@data$frame))
## define limits
if(is.null(object@g.args$xlim))
object@g.args$xlim <- c(-0.8, 0.8)
if(is.null(object@g.args$ylim))
object@g.args$ylim <- c(-0.6, 1)
## grid computation
if(is.null(object@g.args$max3d))
object@g.args$max3d <- .trranges(df = df, adjust = object@g.args$adjust)$maxi
if(is.null(object@g.args$min3d))
object@g.args$min3d <- .trranges(df = df, adjust = object@g.args$adjust)$mini
valuLim <- .trranges(df = df, adjust = object@g.args$adjust, min3 = object@g.args$min3d, max3 = object@g.args$max3d)
## coordinates for the triangle vertices
A <- c(-1 / sqrt(2), -1 / sqrt(6))
B <- c(1 / sqrt(2), -1 / sqrt(6))
C <- c(0, 2 / sqrt(6))
object@s.misc$cornerp <- list(A = A, B = B, C = C)
## coordinates for grid and axes
ng <- object@adeg.par$pgrid$nint + 1 ## number of grid lines
pts1 <- pts2 <- pts3 <- c()
vdivision <- mapply(FUN = function(min, max) seq(min, max, length.out = ng), min = valuLim$mini, max = valuLim$maxi) ## 3 columns: one per axes
## where to draw the division
indented <- seq(0, 1, length.out = nrow(vdivision))[-c(1, nrow(vdivision))]
## axis 1 (A to B)
pts1 <- matrix(rep(A, length(indented)), ncol = 2, byrow = TRUE) + indented * (matrix(rep(B, length(indented)), ncol = 2, byrow = TRUE) - matrix(rep(A, length(indented)), ncol = 2, byrow = TRUE))
##axis 2 (A to C)
pts2 <- matrix(rep(C, length(indented)), ncol = 2, byrow = TRUE) + indented * (matrix(rep(A, length(indented)), ncol = 2, byrow = TRUE) - matrix(rep(C, length(indented)), ncol = 2, byrow = TRUE))
## axis 3 (B to C)
pts3 <- matrix(rep(B, length(indented)), ncol = 2, byrow = TRUE) + indented * (matrix(rep(C, length(indented)), ncol = 2, byrow = TRUE) - matrix(rep(B, length(indented)), ncol = 2, byrow = TRUE))
object@s.misc$lgrid <- list(pts1 = pts1, pts2 = pts2, pts3 = pts3, posgrid = vdivision)
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panelbase",
signature = "ADEg.Tr",
definition = function(object, x, y) {
callNextMethod()
## draw triangle (A -> B , B -> C, C -> A)
## small triangle: points distribution
## triangle vertices
dfcorner <- rbind(object@s.misc$cornerp$A, object@s.misc$cornerp$B, object@s.misc$cornerp$C, object@s.misc$cornerp$A)
panel.polygon(dfcorner, col = object@adeg.par$pbackground$col, border = if(object@adeg.par$pbackground$box) col = "#000000" else "transparent") ## not really useful (only for arguments consistency)
## size of the grid
nn <- sapply(object@s.misc$lgrid, nrow)[-4]
## draw grid
if(object@adeg.par$pgrid$draw)
panel.segments(x0 = c(rep(object@s.misc$lgrid[[1L]][, 1], 2), object@s.misc$lgrid[[2L]][, 1]),
x1 = c(rev(object@s.misc$lgrid[[2L]][, 1]), rep(rev(object@s.misc$lgrid[[3L]][, 1]), 2)),
y0 = c(rep(object@s.misc$lgrid[[1L]][, 2], 2),object@s.misc$lgrid[[2L]][, 2]),
y1 = c(rev(object@s.misc$lgrid[[2L]][, 2]), rep(rev(object@s.misc$lgrid[[3L]][, 2]), 2)),
lwd = object@adeg.par$pgrid$lwd,
col = object@adeg.par$pgrid$col,
lty = object@adeg.par$pgrid$lty)
## draw axes
axis.text <- modifyList(as.list(object@trellis.par$axis.text), trellis.par.get()$axis.text, keep.null = TRUE)
axis.text2 <- list()
axis.text2[c("cex", "col")] <- object@adeg.par$pgrid$text[c("cex", "col")]
# never used: division <- object@s.misc$lgrid$posgrid[-c(1, length(object@s.misc$lgrid$posgrid))]
pos <- c(1, 3, 3)
srt <- c(0, 60, -60)
## get axes names
if(object@data$storeData)
axisN <- colnames(object@data$dfxyz)[c(2, 1, 3)]
else
axisN <- colnames(eval(object@data$dfxyz, envir = sys.frame(object@data$frame)))[c(2, 1, 3)]
lab <- apply(object@s.misc$lgrid$posgrid, 2, as.character)
labels <- lab[-c(1, nrow(lab)), ] ## without corner
## final limits for axes
lcorners <- lab[c(1, nrow(lab)), ] ## corner lab (limits)
orderCplot <- dfcorner[c(3, 1, 1, 2, 2, 3), ] ## ordre dessin label, selon row de dfcorner, a reprendre
posCplot <- rep(c(2, 1, 4), each = 2)
order_lab <- c(2, 1, 3)
for(i in 1:3) { ## for the three axis
## ticks
if(object@adeg.par$paxes$draw)
do.call("panel.text", c(list(labels = labels[, order_lab[i]], x = object@s.misc$lgrid[[i]][, 1], y = object@s.misc$lgrid[[i]][, 2], pos = pos[i], srt = srt[i]), axis.text2))
ptlab <- object@s.misc$lgrid[[i]][1, ] + (object@s.misc$lgrid[[i]][nn[i], ] - object@s.misc$lgrid[[i]][1, ]) / 2
## axis names
if(axis.text$cex != 0)
do.call("panel.text", args = c(list(labels = axisN[i], x = ptlab[1], y = ptlab[2], srt = srt[i], pos = pos[i]), axis.text))
}
do.call("panel.text", c(list(x = orderCplot[, 1], y = orderCplot[, 2], lab = lcorners, pos = posCplot), axis.text2))
})
setMethod(
f = "gettrellis",
signature = "ADEg.Tr",
definition = function(object) {
tmp_trellis <- do.call(what = object@lattice.call$graphictype, args = c(formula(1 ~ 1), object@lattice.call$arguments, environment()))
return(tmp_trellis)
})
setMethod(
f = "setlatticecall",
signature = "ADEg.Tr",
definition = function(object) {
name_obj <- deparse(substitute(object))
## background and box
## object@trellis.par$panel.background$col <- object@adeg.par$pbackground$col
if(!object@adeg.par$pbackground$box)
object@trellis.par$axis.line$col <- "transparent"
else
object@trellis.par$axis.line$col <- "black"
arguments = list(
par.settings = object@trellis.par,
scales = if(!is.null(object@g.args$scales)) object@g.args$scales else list(draw = FALSE),
key = createkey(object),
aspect = object@adeg.par$paxes$aspectratio,
panel = function(...) {
panelbase(object, ...)
panel(object, ...)
})
object@lattice.call$arguments <- arguments
object@lattice.call$graphictype <- "xyplot"
## get lattice arguments (set unspecified to NULL)
argnames <- c("main", "sub", "xlab", "ylab")
largs <- object@g.args[argnames]
names(largs) <- argnames
## add xlim and ylim if not NULL
if("xlim" %in% names(object@g.args))
largs["xlim"] <- object@g.args["xlim"]
if("ylim" %in% names(object@g.args))
largs["ylim"] <- object@g.args["ylim"]
object@lattice.call$arguments <- c(object@lattice.call$arguments, largs, list(strip = FALSE))
assign(name_obj, object, envir = parent.frame())
})
adegraphics/R/addpoint.R 0000644 0001762 0000144 00000005717 13742303021 014657 0 ustar ligges users setMethod(
f = "addpoint",
signature = "ADEg",
definition = function(object, xcoord, ycoord, plot = TRUE, ...) {
# iterate coordinates if necessary
size <- max(length(xcoord), length(ycoord))
xcoord <- rep_len(xcoord, length.out = size)
ycoord <- rep_len(ycoord, length.out = size)
# collect limits
xlim <- object@g.args$xlim
ylim <- object@g.args$ylim
aspect <- object@adeg.par$paxes$aspectratio
## sorting parameters
sortparameters <- sortparamADEg(...)$adepar
params <- adegpar()
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
params <- sortparameters$ppoints
# create the lattice object
pointadded <- xyplot(ycoord ~ xcoord, xlim = xlim, ylim = ylim, xlab = NULL, ylab = NULL, aspect = aspect,
panel = function(x, y, ...) panel.points(xcoord, ycoord, alpha = params$alpha, cex = params$cex, col = params$col, pch = params$pch, fill = params$fill), plot = FALSE)
pointadded$call <- call("xyplot", ycoord ~ xcoord, xlim = substitute(xlim), ylim = substitute(ylim), xlab = NULL, ylab = NULL,
aspect = substitute(aspect), alpha = params$alpha, cex = params$cex, col = params$col, pch = params$pch, fill = params$fill,
panel = function(x, y, ...) panel.abline(x, y))
# superposition
obj <- superpose(object, pointadded, plot = FALSE)
nn <- all.names(substitute(object))
names(obj) <- c(ifelse(is.na(nn[2]), nn[1], nn[2]), "pointadded")
if(plot)
print(obj)
invisible(obj)
})
setMethod(
f = "addpoint",
signature = "ADEgS",
definition = function(object, xcoord, ycoord, plot = TRUE, which = 1:length(object), ...) {
ngraph <- length(object)
if(max(which) > ngraph)
stop("Values in 'which' should be lower than the length of object")
if(length(which) == 1) {
size <- max(length(xcoord), length(ycoord))
xcoord <- rep_len(xcoord, length.out = size)
ycoord <- rep_len(ycoord, length.out = size)
object[[which]] <- addpoint(object[[which]], xcoord, ycoord, ..., plot = FALSE)
} else {
if(sum(object@add) != 0)
stop("The 'addpoint' function is not available for superposed objects.", call. = FALSE)
## sorting parameters
sortparameters <- sortparamADEg(...)$adepar
params <- adegpar()
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
params <- sortparameters$ppoints
params <- rapply(params, function(X) rep(X, length.out = length(which)), how = "list")
xcoord <- rep_len(xcoord, length.out = length(which))
ycoord <- rep_len(ycoord, length.out = length(which))
for (i in which)
object[[i]] <- addpoint(object[[i]], xcoord[i], ycoord[i], which = 1, plot = FALSE, ppoints = lapply(params, function(X) X[i]))
}
obj <- object
if(plot)
print(obj)
invisible(obj)
}) adegraphics/R/S1.match.R 0000644 0001762 0000144 00000016377 13742303021 014437 0 ustar ligges users ###########################################################
## s1d.match ##
###########################################################
setClass(
Class = "S1.match",
contains = "ADEg.S1"
)
setMethod(
f = "initialize",
signature = "S1.match",
definition = function(.Object, data = list(score = NULL, labels = NULL, at = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.S1 initialize
.Object@data$labels <- data$labels
return(.Object)
})
setMethod(
f = "prepare",
signature = "S1.match",
definition = function(object) {
name_obj <- deparse(substitute(object))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
## change default for some parameters
if(adegtot$p1d$horizontal & is.null(object@adeg.par$plabels$srt))
adegtot$plabels$srt <- 90
else if(!adegtot$p1d$horizontal & is.null(object@adeg.par$plabels$srt))
adegtot$plabels$srt <- 0
adegtot$p1d$rug$tck <- 0
if(adegtot$p1d$horizontal & is.null(object@g.args$ylim))
object@g.args$ylim <- c(0, 1)
if(!adegtot$p1d$horizontal & is.null(object@g.args$xlim))
object@g.args$xlim <- c(0, 1)
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f= "panel",
signature = "S1.match",
definition = function(object, x, y) {
if(object@data$storeData) {
labels <- object@data$labels
at <- object@data$at
} else {
labels <- eval(object@data$labels, envir = sys.frame(object@data$frame))
at <- eval(object@data$at, envir = sys.frame(object@data$frame))
}
lims <- current.panel.limits(unit = "native")
nval <- length(y) %/% 2
score2 <- y[(nval + 1):length(y)]
score1 <- y[1 : nval]
pscore <- object@adeg.par$p1d
plabels <- object@adeg.par$plabels
plboxes <- plabels$boxes
porigin <- object@adeg.par$porigin
if(!is.null(labels)) {
## get text sizes for boxes
test <- .textsize(labels, plabels)
w <- test$w
h <- test$h
}
lead <- ifelse(pscore$reverse, -1, 1)
if(pscore$horizontal) {
## horizontal plot
## get positions for labels
spacelab <- diff(lims$xlim) / (nval + 1)
xlab <- seq(from = lims$xlim[1] + spacelab, by = spacelab, length.out = nval)[rank(score1, ties.method = "first")]
ylab <- rep(at, length.out = nval)
ypoints <- rep(object@s.misc$rug, length.out = nval)
ypoints2 <- rep(ypoints + lead * 0.05 * abs(diff(object@g.args$ylim)), length.out = nval)
## horizontal line
if(pscore$rug$draw & pscore$rug$line)
panel.abline(h = ypoints2, col = porigin$col, lwd = porigin$lwd, lty = porigin$lty, alpha = porigin$alpha)
## segments linking both scores
do.call("panel.segments", c(list(x0 = score1, y0 = ypoints, x1 = score2, y1 = ypoints2), object@adeg.par$plines))
## segments linking labels to second score
do.call("panel.segments", c(list(x0 = score2, y0 = ypoints2, x1 = xlab, y1 = ylab), object@adeg.par$plines))
## drawing labels
if(!is.null(labels) & any(plabels$cex > 0))
adeg.panel.label(x = xlab , y = ylab + lead * h / 2, labels = labels, plabels = plabels)
## draw points
if(any(object@adeg.par$ppoints$cex > 0))
panel.points(x = c(score1, score2), y = c(ypoints, ypoints2), pch = object@adeg.par$ppoints$pch, cex = object@adeg.par$ppoints$cex, col = object@adeg.par$ppoints$col, alpha = object@adeg.par$ppoints$alpha, fill = object@adeg.par$ppoints$fill)
} else {
## vertical plot
## get positions for labels
spacelab <- diff(lims$ylim) / (nval + 1)
ylab <- seq(from = lims$ylim[1] + spacelab, by = spacelab, length.out = nval)[rank(score1, ties.method = "first")]
xlab <- rep(at, length.out = nval)
xpoints <- rep(object@s.misc$rug, length.out = nval)
xpoints2 <- rep(xpoints + lead * 0.05 * abs(diff(object@g.args$xlim)), length.out = nval)
## vertical line
if(pscore$rug$draw & pscore$rug$line)
panel.abline(v = xpoints2, col = porigin$col, lwd = porigin$lwd, lty = porigin$lty, alpha = porigin$alpha)
## segments linking both scores
do.call("panel.segments", c(list(x0 = xpoints, y0 = score1, x1 = xpoints2, y1 = score2), object@adeg.par$plines))
## segments linking labels to second score
do.call("panel.segments", c(list(x0 = xpoints2, y0 = score2, x1 = xlab, y1 = ylab), object@adeg.par$plines))
## drawing labels
if(!is.null(labels) & any(plabels$cex > 0))
adeg.panel.label(x = xlab + lead * w / 2 , y = ylab, labels = labels, plabels = plabels)
## draw points
if(any(object@adeg.par$ppoints$cex > 0))
panel.points(x = c(xpoints, xpoints2), y = c(score1, score2), pch = object@adeg.par$ppoints$pch, cex = object@adeg.par$ppoints$cex, col = object@adeg.par$ppoints$col, alpha = object@adeg.par$ppoints$alpha, fill = object@adeg.par$ppoints$fill)
}
})
s1d.match <- function(score1, score2, labels = 1:NROW(score1), at = 0.5, facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters
thecall <- .expand.call(match.call())
score1 <- eval(thecall$score1, envir = sys.frame(sys.nframe() + pos))
score2 <- eval(thecall$score2, envir = sys.frame(sys.nframe() + pos))
if(NROW(score1) != NROW(score2))
stop("score1 and score2 should have the same length")
if(NCOL(score1) != NCOL(score2))
stop("score1 and score2 should have the same number of columns")
if((is.data.frame(score1) & NCOL(score1) == 1) | (is.data.frame(score2) & NCOL(score2) == 1))
stop("Not yet implemented for data.frame with only one column, please convert into vector")
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if(NCOL(score1) == 1)
object <- multi.facets.S1(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple scores")
}
## multiple scores
else if(NCOL(score1) > 1) {
object <- multi.score.S1(thecall)
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
if(storeData)
tmp_data <- list(score = c(score1, score2), labels = labels, at = at, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(score = call("c", thecall$score1, thecall$score2), labels = thecall$labels, at = thecall$at, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "S1.match", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = sortparameters$g.args, Call = match.call())
## preparation
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/T.cont.R 0000644 0001762 0000144 00000004315 13742303021 014213 0 ustar ligges users setClass(
Class = "T.cont",
contains = "T.value"
)
setMethod(
f = "panel",
signature = "T.cont",
definition = function(object, x, y) {
## call panel for T.value object
callNextMethod(object, x, y)
if(object@data$storeData) {
dftab <- object@data$dftab
coordsx <- object@data$coordsx
coordsy <- object@data$coordsy
} else {
dftab <- eval(object@data$dftab, envir = sys.frame(object@data$frame))
coordsx <- eval(object@data$coordsx, envir = sys.frame(object@data$frame))
coordsy <- eval(object@data$coordsy, envir = sys.frame(object@data$frame))
}
dftab <- dftab / sum(dftab)
f1 <- function(x, w) {
w1 <- weighted.mean(w, x)
w <- (w - w1)^2
w2 <- sqrt(weighted.mean(w, x))
return(c(w1, w2))
}
if(object@g.args$meanX) {
w <- t(apply(dftab, 2, f1, w = coordsy))
panel.points(x = coordsx, y = w[, 1], pch = 20, cex = 1.5, col = "black")
panel.segments(coordsx, w[, 1] - w[, 2] , coordsx, w[, 1] + w[, 2], col = object@adeg.par$plines$col, lty = object@adeg.par$plines$lty, lwd = object@adeg.par$plines$lwd)
}
if(object@g.args$meanY) {
w <- t(apply(dftab, 1, f1, w = coordsx))
panel.points(x = w[, 1], coordsy, pch = 20, cex = 1.5, col = "black")
panel.segments(w[, 1] - w[, 2], coordsy, w[, 1] + w[, 2], coordsy, col = object@adeg.par$plines$col, lty = object@adeg.par$plines$lty, lwd = object@adeg.par$plines$lwd)
}
coordsx <- coordsx[col(as.matrix(dftab))]
coordsy <- coordsy[row(as.matrix(dftab))]
if(object@g.args$ablineX)
panel.abline(reg = lm(coordsy ~ coordsx, weights = as.vector(as.matrix(dftab))), col = object@adeg.par$plines$col, lty = object@adeg.par$plines$lty, lwd = object@adeg.par$plines$lwd)
if(object@g.args$ablineY) {
w <- coefficients(lm(coordsx ~ coordsy, weights = as.vector(as.matrix(dftab))))
if(w[2] == 0)
panel.abline(h = w[1], col = object@adeg.par$plines$col, lty = object@adeg.par$plines$lty, lwd = object@adeg.par$plines$lwd)
else
panel.abline(c(-w[1] / w[2], 1 / w[2]), col = object@adeg.par$plines$col, lty = object@adeg.par$plines$lty, lwd = object@adeg.par$plines$lwd)
}
})
adegraphics/R/genericMethod.R 0000644 0001762 0000144 00000005037 13742303021 015625 0 ustar ligges users ###################################################
## definition of generic methods ###
###################################################
setGeneric("getparameters", function(object, number) {standardGeneric("getparameters")})
setGeneric("getlatticecall", function(object, number) {standardGeneric("getlatticecall")})
setGeneric("gettrellis", function(object) {standardGeneric("gettrellis")})
setGeneric("getcall", function(object) {standardGeneric("getcall")})
setGeneric("getgraphics", function(object) {standardGeneric("getgraphics")})
setGeneric("add.ADEg", function(object) {standardGeneric("add.ADEg")})
setGeneric("panel", function(object, x, y, ...) {standardGeneric("panel")})
setGeneric("panelbase", function(object, x, y) {"panelbase"})
setGeneric("zoom", function(object, zoom, center) {standardGeneric("zoom")})
setGeneric("prepare", function(object) {standardGeneric("prepare")})
setGeneric("setlatticecall", function(object) {standardGeneric("setlatticecall")})
setGeneric("addhist", function(object, bandwidth, gridsize = 60, kernel = "normal", cbreaks = 2, storeData = TRUE, plot = TRUE, pos = -1, ...) {standardGeneric("addhist")})
setGeneric("addline", function(object, a = NULL, b = 0, h = NULL, v = NULL, plot = TRUE, ...) {standardGeneric("addline")})
setGeneric("addpoint", function(object, xcoord, ycoord, plot = TRUE, ...) {standardGeneric("addpoint")})
setGeneric("addsegment", function(object, x0 = NULL, y0 = NULL, x1, y1, plot = TRUE, ...) {standardGeneric("addsegment")})
setGeneric("addtext", function(object, xcoord, ycoord, label, plot = TRUE, ...) {standardGeneric("addtext")})
setGeneric("createkey", function(object) {standardGeneric("createkey")})
setGeneric("addkey", function(object) {standardGeneric("addkey")})
setGeneric("createcolorkey", function(object) {standardGeneric("createcolorkey")})
setGeneric("getpositions", function(object) {standardGeneric("getpositions")})
setGeneric("getstats", function(object) {standardGeneric("getstats")})
setGeneric("superpose", function(g1, g2, which, plot = FALSE) {standardGeneric("superpose")})
setGeneric("printSuperpose", function(g1, refg, position) {standardGeneric("printSuperpose")})
setGeneric("insert", function(graphics, oldgraphics, posi = c("bottomleft", "bottomright", "topleft", "topright"), ratio = 0.2, inset = 0.0, plot = TRUE, which, dispatch = FALSE) {standardGeneric("insert")})
setGeneric("cbindADEg", function(g1, g2, ..., plot = FALSE) {standardGeneric("cbindADEg")})
setGeneric("rbindADEg", function(g1, g2, ..., plot = FALSE) {standardGeneric("rbindADEg")})
adegraphics/R/panelfunctions.R 0000644 0001762 0000144 00000027072 13742303021 016103 0 ustar ligges users ## Labels drawing
## TODO: labels' rotations.
## first, in no boxes, it is easy
## if boxes, at least do 90 degrees rotations
## finally, more than one rotation possible.
adeg.panel.label <- function(x, y, labels, plabels, pos = NULL) {
if(any(plabels$cex > 0)) {
n <- length(x)
plboxes <- plabels$boxes
draw <- plabels$cex > 0
## using .textsize funtion in utils.R
textS <- .textsize(labels, plabels)
srt <- textS$srt
if(any(plboxes$draw) && !(srt %in% c(0, 90)))
warning("Boxes only implemented for 0 or 90 degrees rotation", call. = FALSE)
ldraw <- rep(draw, length.out = n) ## draw long enough
ldraw[which(is.na(labels[1:n]) | labels[1:n] == "")] <- FALSE ## if no labels or null string don't bother
width <- rep(textS$w, length.out = n)[ldraw]
height <- rep(textS$h, lenght.out = n)[ldraw]
lab <- rep(labels, length.out = n)[ldraw] ## no NA, removed using ldraw
bdraw <- rep(plboxes$draw, length.out = length(ldraw))
## no boxes if no labels
bdraw <- (bdraw & ldraw)
## labels a dessiner
optim <- plabels$optim[1] ## only one possibility
newpos <- list(x = x[ldraw], y = y[ldraw])
if(optim) {
## calcul des nouvelles positions uniquement pour les labels qui seront dessines
## informations sur panel
nativelim <- current.panel.limits(unit = "native")
incheslim <- current.panel.limits(unit = "inches")
## calcul des nouvelles positions.
if(any(is.na(width)) | any(is.na(height)) | any(is.na(newpos$y)) | any(is.na(newpos$x)))
stop("NA restants revoir adeg.panel.label")
newpos <- .pointLabel(x = newpos$x, y = newpos$y, labels = lab,
width = width / diff(nativelim$xlim),
height = height / diff(nativelim$ylim),
limits = nativelim,
xyAspect = diff(incheslim$xlim) / diff(incheslim$ylim),
trace = FALSE)
pos <- NULL
}
if(any(bdraw)) {
## dessins de chaque boite avec son label
plboxes <- lapply(plboxes, FUN = function(x) {rep(x, length.out = length(ldraw))})
srt <- rep(srt, length.out = length(ldraw))
plabels <- lapply(plabels, FUN = function(x) {rep(x, length.out = n)[ldraw]})
for(i in 1:length(newpos$x)) {
if(bdraw[ldraw][i]) {
## labels sizes
panel.rect(
x = unit(newpos$x[i], "native"),
y = unit(newpos$y[i], "native"),
width = width[i],
height = height[i],
col = plboxes$col[ldraw][i],
alpha = plboxes$alpha[ldraw][i],
border = plboxes$border[ldraw][i],
lty = plboxes$lty[ldraw][i],
lwd = plboxes$lwd[ldraw][i]
)
}
panel.text(labels = lab[i], x = unit(newpos$x[i], "native"), y = unit(newpos$y[i], "native"), col = plabels$col[i], cex = plabels$cex[i], alpha = plabels$alpha[i], srt = srt[i])
}
}
else { ## only text
if(any(!ldraw)) ## obliger de repeter pour dessiner si un label doit etre ignorer
panel.text(labels = lab, x = unit(newpos$x, "native"), y = unit(newpos$y, "native"),
col = rep(plabels$col, length.out = length(ldraw))[ldraw], cex = rep(plabels$cex, length.out = length(ldraw))[ldraw],
alpha = rep(plabels$alpha, length.out = length(ldraw))[ldraw], rep(srt, length.out = length(ldraw))[ldraw], pos = pos)
else
panel.text(labels = lab, x = unit(newpos$x, "native"), y = unit(newpos$y, "native"),
col = plabels$col, cex = plabels$cex, alpha = plabels$alpha, srt = srt, pos = pos)
}
}
}
adeg.panel.nb <- function(nbobject, coords, col.edge = "black", lwd = 1, lty = 1, pch = 20, cex = 1, col.node = "black", alpha = 1) {
if(inherits(nbobject, "listw"))
nbobject <- nbobject$neighbours
if(!inherits(nbobject, "nb"))
stop("nb object is not class nb") ## prevoir dans les fonctions user une selection de l element neighbourght si object de type listw
if(length(nbobject) != nrow(coords))
stop("error for nb object, not the same numbers of nodes and coordinates", call. = FALSE)
edges <- cbind(rep(1:length(nbobject), lapply(nbobject, length)), unlist(nbobject))
edges <- edges[edges[,2] != 0, ]
## ici faire rep des parametres pour pouvoir ensuite modifier couleur
adeg.panel.edges(edges, coords, col.edge, lwd, lty, pch, cex, col.node, alpha)
}
## adeg.panel.edges....
## col, lwd, lty etc peuvent varier selon poids des connexions
adeg.panel.edges <- function(edges, coords, col.edge = "black", lwd = 1, lty = 1, pch = 20, cex = 1, col.node = "black", alpha = 1) {
panel.segments(x0 = coords[edges[, 1], 1], y0 = coords[edges[, 1], 2], x1 = coords[edges[, 2], 1], y1 = coords[edges[, 2], 2], col = col.edge, lwd = lwd, lty = lty)
panel.points(x = coords[, 1], y = coords[, 2], col = col.node, pch = pch, alpha = alpha, cex = cex)
}
################## Panel.spatial #############################
## spObject can be :
## SpatialGridDataFrame","SpatialLinesDataFrame","SpatialPixelsDataFrame","SpatialPointsDataFrame","SpatialPolygonsDataFrame"
## n : nombre intervales si data
## TODO: spObject pourrait etre une liste
adeg.panel.Spatial <- function(SpObject, sp.layout = NULL, col = 1, border = 1, lwd = 1, lty = 1, alpha = 0.8, cex = 1, pch = 20, n = length(col), spIndex = 1, ...) {
if(length(grep("DataFrame", class(SpObject))) > 0) { ## there is data in 'SpObject' (it is a SpatialPolygonsDataFrame).
mapSp <- try(SpObject[names(SpObject)[spIndex]], silent = TRUE) ## only the first map (spIndex = 1)
values <- try(mapSp@data[, 1], silent = TRUE)
if(is.factor(values)) { ## qualitative values
if(length(col) != nlevels(values)) {
if(length(col) == 1) ## all values have the same color
col <- rep(col, length.out = nlevels(values))
else
col <- adegpar()$ppalette$quali(nlevels(values))
colvalue <- col[values]
} else
colvalue <- col
} else { ## quantitative values
breaks <- pretty(values, length(col))
if((length(breaks) - 1) != length(col)) {
if(length(col) == 1) ## 'col' is not modified by the user
col <- adegpar()$ppalette$quanti(length(breaks) - 1)
else ## 'col' is modified but there is not enough color values
col <- colorRampPalette(col)(length(breaks) - 1)
}
colvalue <- col[cut(values, breaks, include.lowest = TRUE)]
}
} else { ## there is no data in 'SpObject'
mapSp <- SpObject
colvalue <- col
}
if(!is.null(sp.layout))
sppanel(sp.layout)
if(inherits(SpObject, what = "SpatialPoints")) {
## insert ppoints.parameters for pch and cex
sp.points(mapSp, col = colvalue, pch = pch, cex = cex, alpha = alpha)
}
if(inherits(SpObject, what = "SpatialPolygons"))
sp.polygons(mapSp, col = border, fill = colvalue, alpha = alpha, lty = lty, lwd = lwd)
## For spatialLine problems ; no various colors
if(inherits(SpObject, what = "SpatialLines"))
sp.lines(mapSp, col = colvalue, alpha = alpha, lty = lty, lwd = lwd)
if(inherits(SpObject, what = "SpatialGrid"))
sp.grid(mapSp, at = breaks, col = col)
}
adeg.panel.values <- function(x, y, z, method, symbol, ppoints, breaks, centerpar = NULL, center = 0) {
if((length(x) != length(y)) | (length(y) != length(z)))
stop("error in panel.values, not equal length for x, y, and z")
maxsize <- max(abs(breaks)) ## biggest value
z <- z - center
if(!missing(center) & !is.null(centerpar)) {
xnull <- x[abs(z) < sqrt(.Machine$double.eps)]
ynull <- y[abs(z) < sqrt(.Machine$double.eps)]
}
if(method == "size"){
size <- .proportional_map(z, maxsize) * ppoints$cex[1]
colfill <- ifelse(z < 0, ppoints$col[1], ppoints$col[2])
colborder <- ifelse(z < 0, ppoints$col[2], ppoints$col[1])
} else if(method == "color"){
size <- ppoints$cex[1]
breaks <- sort(breaks)
colfill <- ppoints$fill[as.numeric(cut(z, breaks, include.lowest = TRUE))]
if(any(is.null(colfill)) | any(is.na(colfill)))
stop("error in the definition of color symbol", call. = FALSE)
colborder <- ppoints$col
}
cstnormal <- 5 ## same value in createkey
panel.points(x = x, y = y, cex = size * cstnormal, pch = .symbol2pch(symbol), fill = colfill, col = colborder, alpha = ppoints$alpha)
if(!missing(center) && !is.null(centerpar))
panel.points(x = xnull, y = ynull, pch = centerpar$pch, col = centerpar$col, cex = centerpar$cex)
return(cstnormal)
}
adeg.panel.hist <- function(histValues, horizontal = TRUE, densi, drawLines, params = list(), identifier = "histogramADEg") {
## from panel.histogram of the lattice package
plot.polygon <- modifyList(list(plot.polygon = trellis.par.get("plot.polygon")), params, keep.null = TRUE)[[1L]] ## hist params
add.line <- modifyList(list(add.line = trellis.par.get("add.line")), params, keep.null = TRUE)[[1L]] ## backgroundlines
plot.line <- modifyList(list(plot.line = trellis.par.get("plot.line")), params, keep.null = TRUE)[[1L]] ## density line
h <- histValues
breaks <- h$breaks
heiBar <- h$counts
nb <- length(breaks)
## counts lines
if(horizontal)
do.call("panel.abline", c(list(h = drawLines), add.line))
else
do.call("panel.abline", c(list(v = drawLines), add.line))
## warning : density lines re-scale to check
contdensi <- (h$counts[h$density != 0 & h$counts != 0] / h$density[h$density != 0 & h$counts != 0])[1]
if(horizontal) {
if(nb > 1) {
panel.rect(x = h$mids, y = 0, height = heiBar, width = diff(breaks),
col = plot.polygon$col, alpha = plot.polygon$alpha, border = plot.polygon$border, lty = plot.polygon$lty,
lwd = plot.polygon$lwd, just = c("center", "bottom"), identifier = identifier)
}
do.call("panel.lines", c(list(x = densi$x, y = densi$y * contdensi), plot.line))
} else {
if(nb > 1)
panel.rect(y = h$mids, x = 0, height = diff(breaks), width = heiBar,
col = plot.polygon$col, alpha = plot.polygon$alpha, border = plot.polygon$border, lty = plot.polygon$lty,
lwd = plot.polygon$lwd, just = c("left", "center"), identifier = identifier)
do.call("panel.lines", c(list(y = densi$x, x = densi$y * contdensi), plot.line))
}
}
adeg.panel.join <- function(drawLines, params = list()) {
## circle from c(0,0)p, radius = drawLines
plot.line <- modifyList(list(add.line = trellis.par.get("add.line")), params, keep.null = TRUE)[[1L]] ## density line
## number of seg = 200
plabels <- modifyList(adegpar("plabels"), params, keep.null = TRUE)[[1L]]
scaleX <- c(current.panel.limits()$xlim, current.panel.limits()$ylim)
xlines <- seq(from = min(scaleX) - 0.1 * min(scaleX), to = max(scaleX) * 1.1, length.out = 200)
ylines <- lapply(drawLines, FUN = function(radius, x) {
indx <- (x <= radius) ## x can be greated than radius
return(c(sqrt(radius * radius - x[indx] * x[indx]), (- sqrt(abs(radius * radius - x[!indx] * x[!indx])))))
}, x = xlines)
trash <- lapply(ylines, FUN = function(y, x) {do.call("panel.lines", c(list(x = x[1:length(y)], y = y[1:length(y)]), plot.line))}, x = xlines)
adeg.panel.label(x = sqrt(0.5) * drawLines, y = sqrt(0.5) * drawLines, as.character(drawLines), plabels)
}
## from http://rwiki.sciviews.org/doku.php?id=tips:graphics-grid:displaybitmap
## used in s.logo (rasterGrob) to handle pixmap objects
as.raster.pixmapRGB <- function(x, ...) {
nr <- nrow(x@red)
r <- rgb((x@red), (x@green), (x@blue))
dim(r) <- x@size
r
}
as.raster.pixmapGrey <- function(x, ...) {
nr <- nrow(x@grey)
r <- x@grey
dim(r) <- x@size
r
}
adegraphics/R/S1.label.R 0000644 0001762 0000144 00000012472 13742303021 014412 0 ustar ligges users ###########################################################
## s1d.label ##
###########################################################
setClass(
Class = "S1.label",
contains = "ADEg.S1"
)
setMethod(
f = "initialize",
signature = "S1.label",
definition = function(.Object, data = list(score = NULL, labels = NULL, at = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.C1 initialize
.Object@data$labels <- data$labels
return(.Object)
})
setMethod(
f = "prepare",
signature = "S1.label",
definition = function(object) {
name_obj <- deparse(substitute(object))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
## change default for some parameters
if(adegtot$p1d$horizontal & is.null(object@adeg.par$plabels$srt))
adegtot$plabels$srt <- 90
else if(!adegtot$p1d$horizontal & is.null(object@adeg.par$plabels$srt))
adegtot$plabels$srt <- 0
if(adegtot$p1d$horizontal & is.null(object@g.args$ylim))
object@g.args$ylim <- c(0, 1)
if(!adegtot$p1d$horizontal & is.null(object@g.args$xlim))
object@g.args$xlim <- c(0, 1)
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "S1.label",
definition = function(object, x, y) {
if(object@data$storeData) {
labels <- object@data$labels
at <- object@data$at
} else {
labels <- eval(object@data$labels, envir = sys.frame(object@data$frame))
at <- eval(object@data$at, envir = sys.frame(object@data$frame))
}
lims <- current.panel.limits(unit = "native")
pscore <- object@adeg.par$p1d
plabels <- object@adeg.par$plabels
plboxes <- plabels$boxes
nval <- length(y)
if(!is.null(labels)) {
## get text sizes for boxes
test <- .textsize(labels, plabels)
w <- test$w
h <- test$h
}
lead <- ifelse(pscore$reverse, -1, 1)
if(pscore$horizontal) {
## horizontal plot
xpoints <- y
## draw labels
if(object@g.args$poslabel == "regular") {
spacelab <- diff(lims$xlim) / (nval + 1)
xlab <- seq(from = lims$xlim[1] + spacelab, by = spacelab, length.out = nval)[rank(xpoints, ties.method = "first")]
} else
xlab <- xpoints
if(!is.null(labels) & any(plabels$cex > 0))
adeg.panel.label(x = xlab , y = at + lead * h / 2, labels = labels, plabels = plabels)
## draw segments
ypoints <- object@s.misc$rug
do.call("panel.segments", c(list(x0 = xpoints, y0 = ypoints, x1 = xlab, y1 = at), object@adeg.par$plines))
} else {
## vertical plot
ypoints <- y
## draw labels
if(object@g.args$poslabel == "regular") {
spacelab <- diff(lims$ylim) / (nval + 1)
ylab <- seq(from = lims$ylim[1] + spacelab, by = spacelab, length.out = nval)[rank(ypoints, ties.method = "first")]
} else
ylab <- ypoints
if(!is.null(labels) & any(plabels$cex > 0))
adeg.panel.label(x = at + lead * w / 2 , y = ylab, labels = labels, plabels = plabels)
## draw segments
xpoints <- object@s.misc$rug
do.call("panel.segments", c(list(x0 = xpoints, y0 = ypoints, x1 = at, y1 = ylab), object@adeg.par$plines))
}
if(any(object@adeg.par$ppoints$cex > 0))
do.call("panel.points", c(list(x = xpoints, y = ypoints), object@adeg.par$ppoints))
})
s1d.label <- function(score, labels = 1:NROW(score), at = 0.5, poslabel = c("regular", "value"), facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters
thecall <- .expand.call(match.call())
score <- eval(thecall$score, envir = sys.frame(sys.nframe() + pos))
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if(NCOL(score) == 1)
object <- multi.facets.S1(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple scores")
}
## multiple scores
else if(NCOL(score) > 1) {
object <- multi.score.S1(thecall)
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(poslabel = match.arg(poslabel)))
if(storeData)
tmp_data <- list(score = score, labels = labels, at = at, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(score = thecall$score, labels = thecall$labels, at = thecall$at, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "S1.label", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = match.call())
## preparation
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/ade4-score.R 0000644 0001762 0000144 00000065220 13750030134 014777 0 ustar ligges users "score.acm" <- function (x, xax = 1, which.var = NULL, type = c("points", "boxplot"), pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "acm"))
stop("Object of class 'acm' expected")
if(x$nf == 1)
xax <- 1
if((xax < 1) || (xax > x$nf))
stop("non convenient axe number")
## prepare
oritab <- as.list(x$call)[[2]]
evTab <- eval.parent(oritab)
if(is.null(which.var))
which.var <- 1:ncol(evTab)
type <- match.arg(type)
## parameter management
sortparameters <- sortparamADEg(...)
params <- list()
if(type == "boxplot") {
## parameter management
params$adepar <- list(plabels = list(boxes = list(draw = FALSE)), p1d = list(rug = list(draw = TRUE)),
paxes = list(draw = TRUE, y = list(draw = FALSE)),
plegend = list(drawKey = FALSE), pgrid = list(text = list(cex = 0)),
psub = list(position = "topleft"))
params$g.args <- list(samelimits = FALSE)
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## ADEgS creation
ADEglist <- list()
score <- x$l1[, xax]
scorecall <- substitute(x$l1[, xax])
for(i in which.var) {
## data management
fac <- evTab[, i]
faccall <- call("[", oritab, 1:NROW(evTab), i)
ADEglist[[i]] <- do.call("s1d.boxplot", c(list(score = scorecall, fac = faccall, plot = FALSE, storeData = storeData, pos = pos - 2),
c(sortparameters$adepar, list(psub.text = paste0(colnames(evTab)[i], " (cr=", round(x$cr[i, xax], 2), ")"))),
sortparameters$trellis, sortparameters$g.args, sortparameters$rest))
}
ADEglist <- ADEglist[which.var]
## ADEgS creation
posmatrix <- layout2position(.n2mfrow(length(which.var)), ng = length(which.var))
object <- new(Class = "ADEgS", ADEglist = ADEglist, positions = posmatrix, add = matrix(0, ncol = length(which.var), nrow = length(which.var)), Call = match.call())
} else if(type == "points") {
## parameter management
params$adepar <- list(ppoints = list(pch = "|"), porigin = list(draw = FALSE), pgrid = list(draw = FALSE),
psub = list(position = "topleft"), paxes = list(draw = TRUE), plabels = list(cex = 1.25))
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
ADEglist <- list()
score <- x$l1[, xax]
scorecall <- substitute(x$l1[, xax])
for(i in which.var) {
## data management
fac <- evTab[, i]
faccall <- call("[", oritab, 1:NROW(evTab), i)
meangroup <- call("as.numeric", call("tapply", scorecall, faccall, mean))
dfxy <- call("cbind", scorecall, call("as.numeric", call("[", meangroup, faccall)))
## ADEg creation
g1 <- do.call("s.class", c(list(dfxy = dfxy, fac = faccall, ellipseSize = 0, plot = FALSE, storeData = storeData, pos = pos - 2),
c(sortparameters$adepar, list(psub.text = paste0(colnames(evTab)[i], " (cr=", round(x$cr[i, xax], 2), ")"))),
sortparameters$trellis, sortparameters$g.args, sortparameters$rest))
xlimg1 <- g1@g.args$xlim
ylimg1 <- g1@g.args$ylim
g2 <- xyplot(score ~ fac, xlab = "", ylab = "", scales = list(x = list(tck = c(1, 0)), y = list(tck = c(1, 0))), xlim = xlimg1, ylim = ylimg1,
aspect = g1@adeg.par$paxes$aspectratio, panel = function(x, y) {panel.abline(h = as.numeric(tapply(y, x, mean)), a = 0, b = 1, lty = 1)})
g2$call <- call("xyplot", substitute(scorecall ~ faccall), xlab = "", ylab = "", scales = list(x = list(tck = c(1, 0)), y = list(tck = c(1, 0))), xlim = substitute(xlimg1), ylim = substitute(ylimg1),
aspect = g1@adeg.par$paxes$aspectratio, panel = function(x, y) {panel.abline(h = as.numeric(tapply(y, x, mean)), a = 0, b = 1, lty = 1)})
ADEglist[[i]] <- superpose(g2, g1, plot = FALSE)
}
ADEglist <- ADEglist[which.var]
## ADEgS creation
posmatrix <- layout2position(.n2mfrow(length(which.var)), ng = length(which.var))
object <- new(Class = "ADEgS", ADEglist = ADEglist, positions = posmatrix, add = matrix(0, ncol = length(which.var), nrow = length(which.var)), Call = match.call())
}
names(object) <- colnames(evTab)[which.var]
object@Call <- match.call()
if(plot)
print(object)
invisible(object)
}
"score.mix" <- function (x, xax = 1, which.var = NULL, type = c("points", "boxplot"), pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "mix"))
stop("Object of class 'mix' expected")
if(x$nf == 1)
xax <- 1
if((xax < 1) || (xax > x$nf))
stop("non convenient axe number")
## internal function
lm.pcaiv <- function(x, df, weights) {
lm0 <- lm(as.formula(paste("reponse.generic ~ ", paste(names(df), collapse = "+"))), data = cbind.data.frame(x, df), weights = weights)
return(predict(lm0))
}
## data management
oritab <- as.list(x$call)[[2]]
evTab <- eval.parent(oritab)
if(is.null(which.var))
which.var <- 1:length(x$index)
index <- as.character(x$index)
score <- x$l1[, xax]
scorecall <- substitute(x$l1[, xax])
ADEglist <- list()
for (i in which.var) {
## parameters management
sortparameters <- sortparamADEg(...)
params <- list()
## data management
type.var <- index[i]
col.var <- which(x$assign == i)
y <- x$tab[, col.var]
ycall <- substitute(x$tab[, col.var])
## type of variable : quantitative
if(type.var == "q") {
## parameters management
params$adepar <- list(psub = list(text = paste0(colnames(evTab)[i], " (r2=", round(x$cr[i, xax], 2), ")"), position = "topleft"), paxes = list(aspectratio = "fill", draw = TRUE), porigin = list(include = FALSE), pgrid = list(draw = FALSE), plabels = list(cex = 0))
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
if(length(col.var) == 1) {
g1 <- do.call("s.label", c(list(dfxy = call("cbind", scorecall, ycall), plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$adepar, sortparameters$trellis, sortparameters$g.args, sortparameters$rest))
g2 <- xyplot(y ~ score, panel = function(x, y) {panel.abline(lm(y ~ x), lty = 1)})
g2$call <- call("xyplot", substitute(ycall ~ scorecall), panel = function(x, y) {panel.abline(lm(y ~ x), lty = 1)})
ADEglist[[i]] <- superpose(g1, g2)
} else {
## data management
lm0 <- lm(as.formula(paste("reponse.generic ~ ", paste(names(y), collapse = "+"))), data = cbind.data.frame(reponse.generic = score, y), weights = rep(1, nrow(y))/nrow(y))
lm0call <- substitute(lm(as.formula(paste("reponse.generic ~ ", paste(names(ycall), collapse = "+"))), data = cbind.data.frame(reponse.generic = scorecall, ycall), weights = rep(1, nrow(ycall))/nrow(ycall)))
score.est <- predict(lm0)
score.estcall <- substitute(predict(lm0call))
ord0 <- order(y[, 1])
ord0call <- substitute(order(ycall[, 1]))
y1call <- call("[", ycall, ord0call, 1)
x1call <- call("[", score.estcall, ord0call)
## ADEgS creation
g1 <- do.call("s.label", c(list(dfxy = call("cbind", scorecall, call("[", ycall, 1:NROW(y), 1)), plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$adepar, sortparameters$trellis, sortparameters$g.args, sortparameters$rest))
g2 <- xyplot(y[ord0, 1] ~ score.est[ord0], panel = function(x, y) {panel.lines(x, y, lty = 1)})
g2$call <- call("xyplot", substitute(y1call ~ x1call), panel = function(x, y) {panel.lines(x, y, lty = 1)})
ADEglist[[i]] <- superpose(g1, g2)
}
}
## type of variable : factor
else if(type.var == "f") {
## data management
fac <- evTab[, i]
faccall <- call("[", oritab, 1:NROW(evTab), i)
meangroup <- call("as.numeric", call("tapply", scorecall, faccall, mean))
dfxy <- call("cbind", scorecall, call("as.numeric", call("[", meangroup, faccall)))
type <- match.arg(type)
params <- list()
if(type == "boxplot") {
## parameter management
params$adepar <- list(plabels = list(boxes = list(draw = FALSE)), p1d = list(rug = list(draw = TRUE)), paxes = list(draw = TRUE, y = list(draw = FALSE)),
plegend = list(drawKey = FALSE), pgrid = list(text = list(cex = 0)),
psub = list(text = paste0(colnames(evTab)[i], " (cr=", round(x$cr[i, xax], 2), ")"), position = "topleft"))
params$g.args <- list(samelimits = FALSE)
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## ADEgS creation
ADEglist[[i]] <- do.call("s1d.boxplot", c(list(score = scorecall, fac = faccall, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$adepar, sortparameters$trellis, sortparameters$g.args, sortparameters$rest))
} else if(type == "points") {
## parameter management
params$adepar <- list(ppoints = list(pch = "|"), porigin = list(draw = FALSE), paxes = list(aspectratio = "fill", draw = TRUE),
pgrid = list(draw = FALSE),
psub = list(text = paste0(colnames(evTab)[i], " (cr=", round(x$cr[i, xax], 2), ")"), position = "topleft"))
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## ADEg creation
g1 <- do.call("s.class", c(list(dfxy = dfxy, fac = faccall, ellipseSize = 0, plot = FALSE, storeData = storeData, pos = pos - 2),
sortparameters$adepar, sortparameters$trellis, sortparameters$g.args, sortparameters$rest))
xlimg1 <- g1@g.args$xlim
ylimg1 <- g1@g.args$ylim
g2 <- xyplot(score ~ fac, xlab = "", ylab = "", xlim = xlimg1, ylim = ylimg1,
aspect = g1@adeg.par$paxes$aspectratio, panel = function(x, y) {panel.abline(h = as.numeric(tapply(y, x, mean)), a = 0, b = 1, lty = 1)})
g2$call <- call("xyplot", substitute(scorecall ~ faccall), xlab = "", ylab = "", xlim = substitute(xlimg1), ylim = substitute(ylimg1),
aspect = g1@adeg.par$paxes$aspectratio, panel = function(x, y) {panel.abline(h = as.numeric(tapply(y, x, mean)), a = 0, b = 1, lty = 1)})
ADEglist[[i]] <- superpose(g2, g1, plot = FALSE)
}
}
## type of variable : ordered
else if(type.var == "o") {
## parameters management
params$adepar <- list(ppoints = list(pch = 20), paxes = list(aspectratio = "fill", draw = TRUE),
porigin = list(draw = FALSE), pgrid = list(draw = FALSE),
psub = list(text = paste0(colnames(evTab)[i], " (r2=", round(x$cr[i, xax], 2), ")"), position = "topleft"))
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## data management
lm0 <- lm(as.formula(paste("reponse.generic ~ ", paste(names(y), collapse = "+"))), data = cbind.data.frame(reponse.generic = score, y), weights = rep(1, nrow(y))/nrow(y))
lm0call <- substitute(lm(as.formula(paste("reponse.generic ~ ", paste(names(ycall), collapse = "+"))), data = cbind.data.frame(reponse.generic = scorecall, ycall), weights = rep(1, nrow(ycall))/nrow(ycall)))
score.est <- predict(lm0)
score.estcall <- substitute(predict(lm0call))
ord0 <- order(y[, 1])
ord0call <- substitute(order(ycall[, 1]))
y1call <- call("[", ycall, ord0call, 1)
x1call <- call("[", score.estcall, ord0call)
## ADEgS creation
g1 <- do.call("s.label", c(list(dfxy = call("cbind", scorecall, call("[", ycall, 1:NROW(y), 1)), plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$adepar, sortparameters$trellis, sortparameters$g.args, sortparameters$rest))
g2 <- xyplot(y[ord0, 1] ~ score.est[ord0], panel = function(x, y) {panel.lines(x, y)})
g2$call <- call("xyplot", substitute(y1call ~ x1call), panel = function(x, y) {panel.lines(x, y)})
ADEglist[[i]] <- superpose(g1, g2)
}
}
ADEglist <- ADEglist[which.var]
## ADEgS creation
posmatrix <- layout2position(.n2mfrow(length(which.var)), ng = length(which.var))
object <- new(Class = "ADEgS", ADEglist = ADEglist, positions = posmatrix, add = matrix(0, ncol = length(which.var), nrow = length(which.var)), Call = match.call())
names(object) <- colnames(evTab)[which.var]
object@Call <- match.call()
if(plot)
print(object)
invisible(object)
}
"score.pca" <- function (x, xax = 1, which.var = NULL, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "pca"))
stop("Object of class 'pca' expected")
if(x$nf == 1)
xax <- 1
if((xax < 1) || (xax > x$nf))
stop("non convenient axe number")
## prepare
oritab <- as.list(x$call)[[2]]
type <- ade4::dudi.type(x$call)
evTab <- eval.parent(oritab)
if(is.null(which.var))
which.var <- 1:ncol(evTab)
## parameter management
sortparameters <- sortparamADEg(...)
params <- list()
params$adepar <- list(paxes = list(aspectratio = "fill", draw = TRUE), porigin = list(include = FALSE), pgrid = list(draw = FALSE), plabels = list(cex = 0))
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
ADEglist <- list()
for(i in which.var) {
typedudi <- if(type == 3) {paste0(" (r=", round(x$co[i, xax], 2), ")")} else {""}
dfxy <- call("cbind", substitute(x$l1[, xax]), call("[", oritab, 1:NROW(evTab), i))
g1 <- do.call("s.label", c(list(dfxy = dfxy, plot = FALSE, storeData = storeData, pos = pos - 2),
c(sortparameters$adepar, list(psub.text = paste0(colnames(evTab)[i], typedudi))),
sortparameters$trellis, sortparameters$g.args, sortparameters$rest))
g2 <- xyplot(eval(dfxy)[, 2] ~ eval(dfxy)[, 1], aspect = g1@adeg.par$paxes$aspectratio, panel = function(x, y) {panel.abline(lm(y ~ x))})
g2$call <- call("xyplot", substitute(dfxy[, 2] ~ dfxy[, 1]), aspect = g1@adeg.par$paxes$aspectratio, panel = function(x, y) {panel.abline(lm(y ~ x))})
ADEglist[[i]] <- superpose(g1, g2)
}
ADEglist <- ADEglist[which.var]
## ADEgS creation
posmatrix <- layout2position(.n2mfrow(length(which.var)), ng = length(which.var))
object <- new(Class = "ADEgS", ADEglist = ADEglist, positions = posmatrix, add = matrix(0, ncol = length(which.var), nrow = length(which.var)), Call = match.call())
names(object) <- colnames(evTab)[which.var]
object@Call <- match.call()
if(plot)
print(object)
invisible(object)
}
"score.inertia" <- function(x, xax = 1, threshold = 0.1, contrib = c("abs", "rel"), posieig = "none", pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "inertia"))
stop("Object of class 'inertia' expected")
## data management
ori <- as.list(x$call)
evTab <- eval.parent(ori[[2]])
if(length(xax) > 1)
stop("Not implemented for multiple xax")
if(xax > evTab$nf)
stop("Non convenient xax")
adegtot <- adegpar()
position <- .getposition(posieig[1:min(2, length(posieig))])
contrib <- match.arg(contrib)[1]
## sort parameters for each graph
graphsnames <- c("light_row", "heavy_row", "light_col", "heavy_col", "eig")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## parameters management
adegtot <- adegpar()
params <- list()
params$light_row <- list(plabels = list(cex = 0), ppoints = list(col = "grey20", alpha = 0.45, cex = 1.2, pch = 19))
params$light_col <- list(plabels = list(cex = 0), ppoints = list(col = "grey20", alpha = 0.45, cex = 1.2, pch = 19))
params$heavy_row <- list(plabels = list(boxes = list(draw = TRUE), col = "red", srt = "horizontal"), ppoints = list(col = "red", cex = 1.2, pch = 19))
params$heavy_col <- list(plabels = list(boxes = list(draw = TRUE), col = "blue", srt = "horizontal"), ppoints = list(col = "blue", cex = 1.2, pch = 19))
params$eig <- list(pbackground = list(box = TRUE), psub = list(text = "Eigenvalues"))
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
# never display points under contribution threshold
sortparameters$light_row$plabels$cex <- 0
sortparameters$light_col$plabels$cex <- 0
## management of the data and the parameters about the rows' contribution (individuals) on axes
if(!is.null(x$row.rel)) {
datacontrib <- x[[ifelse(contrib == "abs", "row.abs", "row.rel")]]
inertrow <- abs(datacontrib[, xax]) / 100
lightrow <- subset(evTab$li[, xax], inertrow < threshold)
heavyrow <- subset(evTab$li[, xax], inertrow >= threshold)
if(length(heavyrow) == 0)
stop("No points to draw, try lowering 'threshold'")
heavy_inertrow <- subset(inertrow, inertrow >= threshold)
names_heavyrow <- subset(rownames(datacontrib), inertrow >= threshold)
limglobal <- setlimits1D(mini = min(c(heavyrow, lightrow)), maxi = max(c(heavyrow, lightrow)),
origin = adegtot$porigin$origin, includeOr = adegtot$porigin$include)
params <- list()
params$light_row <- list(xlim = limglobal)
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
}
## management of the data and the parameters about the columns' contribution (variables) on axes
if(!is.null(x$col.rel)) {
datacontrib <- x[[ifelse(contrib == "abs", "col.abs", "col.rel")]]
inertcol <- abs(datacontrib[, xax]) / 100
lightcol <- subset(evTab$co[, xax], inertcol < threshold)
heavycol <- subset(evTab$co[, xax], inertcol >= threshold)
if(length(heavycol) == 0)
stop("No points to draw, try lowering 'threshold'")
heavy_inertcol <- subset(inertcol, inertcol >= threshold)
names_heavycol <- subset(rownames(datacontrib), inertcol >= threshold)
limglobal <- setlimits1D(mini = min(c(heavycol, lightcol)), maxi = max(c(heavycol, lightcol)),
origin = adegtot$porigin$origin, includeOr = adegtot$porigin$include)
params <- list()
params$light_col <- list(xlim = limglobal)
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
}
## displaying of the eigen values
if(!is.null(position))
geig <- do.call("plotEig", c(list(eigvalue = call("$", ori[[2]], "eig"), nf = 1:evTab$nf, xax = xax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$eig))
## function to create the graphics about the row' contribution (individuals) on axes
f_row <- function(posi = NULL, pos){
graphnames <- c(if(length(lightrow) > 0) {"light_row"}, "heavy_row", "contribution", if(!is.null(posi)) {"eig"})
if(length(lightrow) > 0) {
g1 <- do.call("s1d.label", c(list(score = lightrow, at = 0, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$light_row))
g2 <- do.call("s1d.label", c(list(score = heavyrow, at = heavy_inertrow, labels = names_heavyrow, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$heavy_row))
grow <- do.call("superpose", list(g1, g2))
grow@Call <- call("superpose", list(g1@Call, g2@Call))
} else {
grow <- do.call("s1d.label", c(list(score = heavyrow, at = heavy_inertrow, labels = names_heavyrow, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$heavy_col))
}
# add an horizontal line drawinf the contribution threshold
gcont <- xyplot(0 ~ 0, panel = function(x, y) {panel.abline(h = threshold, lty = "dotted", col = "grey")})
grow <- do.call("superpose", list(grow, gcont))
grow@Call <- call("superpose", list(grow@Call, gcont$call))
if(!is.null(posi))
grow <- do.call("insert", list(geig, grow, posi = posi, plot = FALSE, ratio = 0.25))
names(grow) <- graphnames
return(grow)
}
# function to create the graphics about the columns' contribution (variables) on axes
f_col <- function(posi = NULL, pos) {
graphnames <- c(if(length(lightcol) > 0) {"light_col"}, "heavy_col", "contribution", if(!is.null(posi)) {"eig"})
if(length(lightcol) > 0) {
g3 <- do.call("s1d.label", c(list(score = lightcol, at = 0, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$light_col))
g4 <- do.call("s1d.label", c(list(score = heavycol, at = heavy_inertcol, labels = names_heavycol, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$heavy_col))
gcol <- do.call("superpose", list(g3, g4))
gcol@Call <- call("superpose", list(g3@Call, g4@Call))
} else {
gcol <- do.call("s1d.label", c(list(score = heavycol, at = heavy_inertcol, labels = names_heavycol, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$heavy_col))
}
# add an horizontal line drawinf the contribution threshold
gcont <- xyplot(0 ~ 0, panel = function(x, y) {panel.abline(h = threshold, lty = "dotted", col = "grey")})
gcol <- do.call("superpose", list(gcol, gcont))
gcol@Call <- call("superpose", list(gcol@Call, gcont$call))
if(!is.null(posi))
gcol <- do.call("insert", list(geig, gcol, posi = posi, plot = FALSE, ratio = 0.25))
names(gcol) <- graphnames
return(gcol)
}
## function to create a layout of the graphics about the contribution of rows (individuals) and columns (variables) on axes
f_both <- function(posi = NULL, pos) {
object <- do.call("cbindADEg", c(list(f_row(posi = NULL, pos = pos - 1), f_col(posi = posi, pos = pos - 1))))
names(object) <- c("row", "col")
return(object)
}
## creation of the appropriate plot according to the input data
if(!is.null(x$row.rel) & is.null(x$col.rel))
object <- f_row(posi = position, pos = pos)
if(!is.null(x$col.rel) & is.null(x$row.rel))
object <- f_col(posi = position, pos = pos)
if(!is.null(x$row.rel) & !is.null(x$col.rel))
object <- f_both(posi = position, pos = pos)
if(is.null(x$row.rel) & is.null(x$col.rel))
stop(paste("No inertia was calculated in the ", substitute(x), " object", sep = ""))
object@Call <- match.call()
if(plot)
print(object)
invisible(object)
}
#"score.coa" <- function (x, xax = 1, dotchart = FALSE, pos = -1, storeData = TRUE, plot = TRUE, ...) {
#
# if(!inherits(x, "coa"))
# stop("Object of class 'coa' expected")
# if(x$nf == 1)
# xax <- 1
# if((xax < 1) || (xax > x$nf))
# stop("non convenient axe number")
#
# if(dotchart)
# stop("TRUE 'dotchart' not yet implemented")
#
#
#
# def.par <- par(mar = par("mar"))
# on.exit(par(def.par))
# par(mar = c(0.1, 0.1, 0.1, 0.1))
#
# sco.distri.class.2g <- function(score, fac1, fac2, weight, labels1 = as.character(levels(fac1)), labels2 = as.character(levels(fac2)), clab1, clab2, cpoi, cet) {
# nvar1 <- nlevels(fac1)
# nvar2 <- nlevels(fac2)
# ymin <- scoreutil.base(y = score, xlim = NULL, grid = TRUE, cgrid = 0.75, include.origin = TRUE, origin = 0, sub = NULL, csub = 0)
# ymax <- par("usr")[4]
# ylabel <- strheight("A", cex = par("cex") * max(1, clab1, clab2)) * 1.4
# xmin <- par("usr")[1]
# xmax <- par("usr")[2]
# xaxp <- par("xaxp")
# nline <- xaxp[3] + 1
# v0 <- seq(xaxp[1], xaxp[2], le = nline)
#
# ## dessine la grille
# segments(v0, rep(ymin, nline), v0, rep(ymax, nline), col = gray(0.5), lty = 1)
#
# ## dessine le cadre
# rect(xmin, ymin, xmax, ymax)
#
#
# sum.col1 <- unlist(tapply(weight, fac1, sum))
# sum.col2 <- unlist(tapply(weight, fac2, sum))
# sum.col1[sum.col1 == 0] <- 1
# sum.col2[sum.col2 == 0] <- 1
#
# weight1 <- weight/sum.col1[fac1]
# weight2 <- weight/sum.col2[fac2]
#
# y.distri1 <- tapply(score * weight1, fac1, sum)
# y.distri1 <- rank(y.distri1)
# y.distri2 <- tapply(score * weight2, fac2, sum)
# y.distri2 <- rank(y.distri2) + nvar1 + 2
# y.distri <- c(y.distri1, y.distri2)
#
# ylabel <- strheight("A", cex = par("cex") * max(1, clab1, clab2)) * 1.4
# y.distri1 <- (y.distri1 - min(y.distri))/(max(y.distri) - min(y.distri))
# y.distri1 <- ymin + ylabel + (ymax - ymin - 2 * ylabel) * y.distri1
# y.distri2 <- (y.distri2 - min(y.distri))/(max(y.distri) - min(y.distri))
# y.distri2 <- ymin + ylabel + (ymax - ymin - 2 * ylabel) * y.distri2
#
# for (i in 1:nvar1) {
# w <- weight1[fac1 == levels(fac1)[i]]
# y0 <- y.distri1[i]
# score0 <- score[fac1 == levels(fac1)[i]]
# x.moy <- sum(w * score0)
# x.et <- sqrt(sum(w * (score0 - x.moy)^2))
# x1 <- x.moy - cet * x.et
# x2 <- x.moy + cet * x.et
# etiagauche <- TRUE
# if ((x1 - xmin) < (xmax - x2))
# etiagauche <- FALSE
# segments(x1, y0, x2, y0)
# if (clab1 > 0) {
# cha <- labels1[i]
# cex0 <- par("cex") * clab1
# xh <- strwidth(cha, cex = cex0)
# xh <- xh + strwidth("x", cex = cex0)
# yh <- strheight(cha, cex = cex0) * 5/6
# if (etiagauche)
# x0 <- x1 - xh/2
# else x0 <- x2 + xh/2
# rect(x0 - xh/2, y0 - yh, x0 + xh/2, y0 + yh, col = "white", border = 1)
# text(x0, y0, cha, cex = cex0)
# }
# points(x.moy, y0, pch = 20, cex = par("cex") * cpoi)
# }
# for (i in 1:nvar2) {
# w <- weight2[fac2 == levels(fac2)[i]]
# y0 <- y.distri2[i]
# score0 <- score[fac2 == levels(fac2)[i]]
# x.moy <- sum(w * score0)
# x.et <- sqrt(sum(w * (score0 - x.moy)^2))
# x1 <- x.moy - cet * x.et
# x2 <- x.moy + cet * x.et
# etiagauche <- TRUE
# if ((x1 - xmin) < (xmax - x2))
# etiagauche <- FALSE
# segments(x1, y0, x2, y0)
# if (clab2 > 0) {
# cha <- labels2[i]
# cex0 <- par("cex") * clab2
# xh <- strwidth(cha, cex = cex0)
# xh <- xh + strwidth("x", cex = cex0)
# yh <- strheight(cha, cex = cex0) * 5/6
# if (etiagauche)
# x0 <- x1 - xh/2
# else x0 <- x2 + xh/2
# rect(x0 - xh/2, y0 - yh, x0 + xh/2, y0 + yh, col = "white", border = 1)
# text(x0, y0, cha, cex = cex0)
# }
# points(x.moy, y0, pch = 20, cex = par("cex") * cpoi)
# }
# }
#
# if (inherits(x, "witwit")) {
# y <- eval.parent(as.list(x$call)[[2]])
# oritab <- eval.parent(as.list(y$call)[[2]])
# } else
# oritab <- eval.parent(as.list(x$call)[[2]])
#
# l.names <- row.names(oritab)
# c.names <- names(oritab)
# oritab <- as.matrix(oritab)
# a <- x$co[col(oritab), xax]
# a <- a + x$li[row(oritab), xax]
# a <- a/sqrt(2 * x$eig[xax] * (1 + sqrt(x$eig[xax])))
# a <- a[oritab > 0]
# aco <- col(oritab)[oritab > 0]
# aco <- factor(aco)
# levels(aco) <- c.names
# ali <- row(oritab)[oritab > 0]
# ali <- factor(ali)
# levels(ali) <- l.names
# aw <- oritab[oritab > 0]/sum(oritab)
#
# sco.distri.class.2g(a, aco, ali, aw, clab1 = clab.c, clab2 = clab.r, cpoi = cpoi, cet = cet)
# scatterutil.sub("Rows", csub = csub, possub = "topleft")
# scatterutil.sub("Columns", csub = csub, possub = "bottomright")
#} adegraphics/R/ADEg.S1.R 0000644 0001762 0000144 00000032750 13742303021 014074 0 ustar ligges users ####################################################
## Uni-dimensionnal plot ##
####################################################
setClass(
Class = "ADEg.S1",
contains = c("ADEg", "VIRTUAL"),
slots = c(data = "list")
)
setMethod(
f = "initialize",
signature = "ADEg.S1",
definition = function(.Object, data = list(score = NULL, at = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, ...) ## ADEg initialize
.Object@data <- data
return(.Object)
})
## prepare: grid calculations
## reset limits and sets axis information for lattice
setMethod(
f = "prepare",
signature = "ADEg.S1",
definition = function(object) {
name_obj <- deparse(substitute(object))
if(object@data$storeData) {
score <- object@data$score
at <- object@data$at
} else {
score <- eval(object@data$score, envir = sys.frame(object@data$frame))
at <- eval(object@data$at, envir = sys.frame(object@data$frame))
}
if(inherits(object, "S1.boxplot")){
if(object@data$storeData) {
fac <- object@data$fac
} else {
fac <- eval(object@data$fac, envir = sys.frame(object@data$frame))
}
}
score <- as.matrix(score)[, 1] ## to manage 'score' when it is a data.frame with only one column
## limits and scale
minX <- min(score)
maxX <- max(score)
if(object@adeg.par$p1d$horizontal & !is.null(object@g.args$xlim) & is.null(object@s.misc$hori.update)) {
minX <- object@g.args$xlim[1]
maxX <- object@g.args$xlim[2]
}
if(!object@adeg.par$p1d$horizontal & !is.null(object@g.args$ylim) & is.null(object@s.misc$hori.update)) {
minX <- object@g.args$ylim[1]
maxX <- object@g.args$ylim[2]
}
origin <- object@adeg.par$porigin
lim <- setlimits1D(minX, maxX, origin = origin$origin[1], includeOr = origin$include)
## compute grid size
tmp <- pretty(lim, n = object@adeg.par$pgrid$nint)
if(!origin$include)
origin$origin[1] <- tmp[1]
cgrid <- diff(tmp)[1]
if(is.na(cgrid))
stop("error while calculating grid")
## compute grid location
v0 <- origin$origin[1]
if((origin$origin[1] + cgrid) <= lim[2])
v0 <- c(v0, seq(origin$origin[1] + cgrid, lim[2], by = cgrid))
if((origin$origin[1] - cgrid >= lim[1]))
v0 <- c(v0, seq(origin$origin[1] - cgrid, lim[1], by = -cgrid))
v0 <- sort(v0[v0 >= lim[1] & v0 <= lim[2]])
## clean near-zero values
delta <- diff(range(v0))/object@adeg.par$pgrid$nint
if (any(small <- abs(v0) < 1e-14 * delta))
v0[small] <- 0
object@s.misc$backgrid <- list(x = v0, d = cgrid)
## object@adeg.par$paxes has priority over object@g.args$scales
object@adeg.par$paxes$aspectratio <- "fill"
scalesandlab <- modifyList(as.list(object@g.args$scales), object@adeg.par$paxes, keep.null = TRUE)
if(!scalesandlab$draw) {
scalesandlab$x$draw <- FALSE
scalesandlab$y$draw <- FALSE
}
lead <- ifelse(object@adeg.par$p1d$reverse, 1 , -1)
if(object@adeg.par$p1d$horizontal) {
## draw axes for horizontal plot
if(is.null(scalesandlab$x$at))
scalesandlab$x$at <- object@s.misc$backgrid$x
if(is.null(object@g.args$xlim) || !identical(object@s.misc$hori.update, object@adeg.par$p1d$horizontal))
object@g.args$xlim <- lim
Ylim <- object@g.args$ylim
if(is.null(object@s.misc$p1dReverse.update) || (object@adeg.par$p1d$reverse != object@s.misc$p1dReverse.update) ||
is.null(object@s.misc$Ylim.update) || any(Ylim != object@s.misc$Ylim.update)) {
if(is.null(object@g.args$ylim))
Ylim <- setlimits1D(min(at), max(at), 0, FALSE)
if(inherits(object, "S1.boxplot")) ## extend ylim for boxes
Ylim <- Ylim + c(-1, 1) * abs(diff(range(at))) / (nlevels(fac) + 1)
if(object@adeg.par$p1d$rug$draw) {
ref <- ifelse(object@adeg.par$p1d$reverse, 2, 1)
margin <- Ylim[ref]
if(object@adeg.par$p1d$rug$draw)
margin <- object@adeg.par$p1d$rug$margin * abs(diff(Ylim))
object@s.misc$rug <- Ylim[ref]
Ylim[ref] <- Ylim[ref] + lead * margin
}
object@s.misc$Ylim.update <- Ylim
object@s.misc$p1dReverse.update <- object@adeg.par$p1d$reverse
}
object@g.args$ylim <- Ylim
} else {
## draw axes for vertical plot
if(is.null(scalesandlab$y$at))
scalesandlab$y$at <- object@s.misc$backgrid$x
if(is.null(object@g.args$ylim) || !identical(object@s.misc$hori.update, object@adeg.par$p1d$horizontal))
object@g.args$ylim <- lim
Xlim <- object@g.args$xlim
if(is.null(object@s.misc$p1dReverse.update) || (object@adeg.par$p1d$reverse != object@s.misc$p1dReverse.update) ||
is.null(object@s.misc$Xlim.update) || any(Xlim != object@s.misc$Xlim.update)) {
if(is.null(object@g.args$xlim))
Xlim <- setlimits1D(min(at), max(at), 0, FALSE)
if(inherits(object, "S1.boxplot")) ## extend xlim for boxes
Xlim <- Xlim + c(-1, 1) * abs(diff(range(at))) / (nlevels(fac) + 1)
if(object@adeg.par$p1d$rug$draw) {
ref <- ifelse(object@adeg.par$p1d$reverse, 2, 1)
margin <- Xlim[ref]
if(object@adeg.par$p1d$rug$draw)
margin <- object@adeg.par$p1d$rug$margin * abs(diff(Xlim))
object@s.misc$rug <- Xlim[ref]
Xlim[ref] <- Xlim[ref] + lead * margin
}
object@s.misc$Xlim.update <- Xlim
object@s.misc$p1dReverse.update <- object@adeg.par$p1d$reverse
}
object@g.args$xlim <- Xlim
}
object@g.args$scales <- scalesandlab
object@s.misc$hori.update <- object@adeg.par$p1d$horizontal
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panelbase",
signature = "ADEg.S1",
definition = function(object, x, y) {
## Formula defined in gettrellis
## if horizontal, x is score and y is a vector with repetitions of origin
## if vertical, this is the inverse
grid <- object@adeg.par$pgrid
porigin <- object@adeg.par$porigin
pscore <- object@adeg.par$p1d
lims <- current.panel.limits(unit = "native")
plines <- object@adeg.par$plines
if(!is.null(object@data$fac)) {
## there is a factor in the data (e.g., S1.class)
if(object@data$storeData)
fac <- object@data$fac
else
fac <- as.factor(eval(object@data$fac, envir = sys.frame(object@data$frame)))
plines <- lapply(plines, FUN = function(x) return(rep(x, length.out = nlevels(fac))[fac]))
}
lead <- ifelse(pscore$reverse, -1 , 1)
if(pscore$horizontal) {
## horizontal plot
## draw grid
if(grid$draw)
panel.segments(x0 = object@s.misc$backgrid$x , x1 = object@s.misc$backgrid$x, y0 = lims$ylim[1], y1 = lims$ylim[2], col = grid$col, lty = grid$lty, lwd = grid$lwd)
## draw origin
panel.abline(
v = if(porigin$draw) porigin$origin else NULL,
h = if(pscore$rug$draw & pscore$rug$line) object@s.misc$rug else NULL,
col = porigin$col, lwd = porigin$lwd, lty = porigin$lty, alpha = porigin$alpha)
## draw rug
if(pscore$rug$draw & (pscore$rug$tck != 0)) {
ref <- ifelse(pscore$reverse, lims$ylim[2], lims$ylim[1])
## tick end and starting points
start <- object@s.misc$rug
end <- start - pscore$rug$tck * lead * abs(start - ref)
start <- convertUnit(unit(start, "native"), unitTo = "npc", axisFrom = "y", valueOnly = TRUE)
end <- convertUnit(unit(end, "native"), unitTo = "npc", axisFrom = "y", valueOnly = TRUE)
do.call("panel.rug", c(list(x = y, start = start, end = end), plines))
}
} else {
## vertical plot
## draw grid
if(grid$draw)
panel.segments(y0 = object@s.misc$backgrid$x , y1 = object@s.misc$backgrid$x, x0 = lims$xlim[1], x1 = lims$xlim[2], col = grid$col, lty = grid$lty, lwd = grid$lwd)
## draw origin
panel.abline(
h = if(porigin$draw) porigin$origin else NULL,
v = if(pscore$rug$draw & pscore$rug$line) object@s.misc$rug else NULL,
col = porigin$col, lwd = porigin$lwd, lty = porigin$lty, alpha = porigin$alpha)
## draw rug
if(pscore$rug$draw && (pscore$rug$tck != 0)) {
ref <- ifelse(pscore$reverse, lims$xlim[2], lims$xlim[1])
## tick end and starting points
start <- object@s.misc$rug
end <- start - pscore$rug$tck * lead * abs(start - ref)
start <- convertUnit(unit(start, "native"), unitTo = "npc", axisFrom = "x", valueOnly = TRUE)
end <- convertUnit(unit(end, "native"), unitTo = "npc", axisFrom = "x", valueOnly = TRUE)
do.call("panel.rug", c(list(y = y, start = start, end = end), plines))
}
}
## indicate grid size (d = **)
if(grid$draw & (grid$text$cex > 0)) {
text.pos <- .setposition(grid$text$pos)
textgrid <- textGrob(label = paste("d =", object@s.misc$backgrid$d), x = text.pos$posi[1], y = text.pos$posi[2], gp = gpar(cex = grid$text$cex, col = grid$text$col), name = "gridtext")
grid.rect(x = text.pos$posi[1], y = text.pos$posi[2], width = grobWidth(textgrid), height = grobHeight(textgrid), gp = gpar(fill= object@adeg.par$pbackground$col, alpha = 0.8, col = "transparent"))
grid.draw(textgrid)
}
callNextMethod()
})
setMethod(
f = "setlatticecall",
signature = "ADEg.S1",
definition = function(object) {
## arguments recurrents de la liste, pas les limites car elles seront definis ensuite
name_obj <- deparse(substitute(object))
## grid background and box
object@trellis.par$panel.background$col <- object@adeg.par$pbackground$col
if(!object@adeg.par$pbackground$box)
object@trellis.par$axis.line$col <- "transparent"
else
object@trellis.par$axis.line$col <- "black"
arguments <- list(
par.settings = object@trellis.par,
scales = object@g.args$scales,
aspect = object@adeg.par$paxes$aspectratio,
key = createkey(object),
axis = axis.L, ## see utils.R
panel = function(...) {
panelbase(object,...) ## grid,
panel(object,...) ## call to S1.panel function, for slabel and ADEg.S1 class of graphs
})
object@lattice.call$arguments <- arguments
object@lattice.call$graphictype <- "xyplot"
## get lattice arguments (set unspecified to NULL)
argnames <- c("main", "sub", "xlab", "ylab")
largs <- object@g.args[argnames]
names(largs) <- argnames
## add xlim and ylim if not NULL
if("xlim" %in% names(object@g.args))
largs["xlim"] <- object@g.args["xlim"]
if("ylim" %in% names(object@g.args))
largs["ylim"] <- object@g.args["ylim"]
object@lattice.call$arguments <- c(object@lattice.call$arguments, largs, list(strip = FALSE))
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "gettrellis",
signature = "ADEg.S1",
definition = function(object) {
if(object@data$storeData)
score <- object@data$score
else
score <- eval(object@data$score, envir = sys.frame(object@data$frame))
score <- as.matrix(score)[, 1] ## to manage 'score' when it is a data.frame with only one column
xdata <- rep(1, length(score))
fml <- as.formula(score ~ xdata)
tmptrellis <- do.call(what = object@lattice.call$graphictype, args = c(fml, object@lattice.call$arguments, environment()))
return(tmptrellis)
})
## zoom without center
setMethod(
f = "zoom",
signature = c("ADEg.S1", "numeric", "missing"),
definition = function(object, zoom, center) {
## zoom in xlim
p1d <- object@adeg.par$p1d
nameobj <- deparse(substitute(object))
if(length(zoom) != 1)
stop("zoom factor should be length 1")
center <- ifelse(p1d$horizontal, mean(object@g.args$xlim), mean(object@g.args$ylim))
zoom(object, zoom, center)
})
## zoom with center
setMethod(
f = "zoom",
signature = c("ADEg.S1", "numeric", "numeric"),
definition = function(object, zoom, center) {
nameobj <- deparse(substitute(object))
p1d <- object@adeg.par$p1d
origin <- object@adeg.par$porigin
if(length(center) != 1)
stop("Center should be a numeric")
if(length(zoom) != 1)
stop("Zoom factor should be a numeric")
if(p1d$horizontal) {
diffx <- diff(object@g.args$xlim) / zoom
minX <- center - diffx / 2
maxX <- center + diffx / 2
object@g.args$xlim <- c(minX, maxX)
} else {
diffx <- diff(object@g.args$ylim) / zoom
minX <- center - diffx / 2
maxX <- center + diffx / 2
object@g.args$ylim <- c(minX, maxX)
}
lim <- setlimits1D(minX, maxX, origin = origin$origin[1], includeOr = origin$include)
## compute grid size
tmp <- pretty(lim, n = object@adeg.par$pgrid$nint)
if(!origin$include)
origin$origin[1] <- tmp[1]
cgrid <- diff(tmp)[1]
if(is.na(cgrid))
stop("error while calculating grid")
## compute grid location
v0 <- origin$origin[1]
if((origin$origin[1] + cgrid) <= lim[2])
v0 <- c(v0, seq(origin$origin[1] + cgrid, lim[2], by = cgrid))
if((origin$origin[1] - cgrid >= lim[1]))
v0 <- c(v0, seq(origin$origin[1] - cgrid, lim[1], by = -cgrid))
v0 <- sort(v0[v0 >= lim[1] & v0 <= lim[2]])
object@s.misc$backgrid <- list(x = v0, d = cgrid)
setlatticecall(object)
print(object)
invisible(object)
})
adegraphics/R/ADEgS.R 0000644 0001762 0000144 00000057412 14354572335 013757 0 ustar ligges users ##############################################
## general class ##
##############################################
setClass(
Class = "ADEgS",
slots = c(
ADEglist = "list",
positions = "matrix",
add = "matrix", ## n*n, if xij = 1, j superposed to i
Call = "call"),
## slots checking
validity = function(object) {
ng <- length(object@ADEglist)
add <- object@add
if (ncol(object@positions) != 4)
stop("wrong positions matrix, only 4 columns expected (x0, y0, x1, y1)")
if (nrow(object@positions) != ng)
stop("not enough positions: rows number of the positions matrix should be equal to the number of graphics in the ADEglist")
## checking add:
if ((NROW(add) != NCOL(add)) | (NCOL(add) != ng))
stop("add matrix dimensions are not equal to the number of graphics in ADEglist")
if (any(add != 0 & add != 1))
stop("add matrix can only contain 0/1 values")
for (i in 1:ng) {
j <- 1:i
if (any(add[i, j] != 0))
stop("upper diagonal matrix expected for add, only 0 are allowed for xij, when j > = i")
}
return(TRUE)
})
##############################################
## initialize ##
##############################################
setMethod(
f = "initialize",
signature = "ADEgS",
function(.Object, ADEglist, positions, add, Call) {
## add linking
superpose <- list()
ng <- length(ADEglist)
for (i in 1:ng) {
superpose <- c(superpose, list(which(add[, i] == 1))) ## where i is superposed to 1
if (length((superpose[[i]]))) {
for (j in superpose[[i]]) {
add[superpose[[j]], i] <- 1
superpose[[i]] <- c(superpose[[i]], superpose[[j]])
}}}
.Object@add <- add
## check names of the list ADEglist
if (is.null(names(ADEglist)))
names(ADEglist) <- paste("g", lapply(1:length(ADEglist), function(i) i), sep = "")
else
names(ADEglist) <- make.names(names(ADEglist),unique = TRUE)
## assignation
.Object@ADEglist <- ADEglist
.Object@positions <- positions
.Object@add <- add
.Object@Call <- Call
## checking validations
validObject(.Object)
return(.Object)
})
setClassUnion(name = "ADEgORADEgSORtrellis", members = c("ADEg", "ADEgS", "trellis"))
##############################################
## Get elements/information ##
##############################################
setMethod(
f = "getcall",
signature = "ADEgS",
definition = function(object) {
return(object@Call)
})
setMethod(
f = "getgraphics",
signature = "ADEgS",
definition = function(object) {
return(object@ADEglist)
})
setMethod(
f = "getpositions",
signature = "ADEgS",
definition = function(object) {
return(object@positions)
})
setMethod(
f = "length",
signature = "ADEgS",
definition = function(x) {
return(length(x@ADEglist))
})
setMethod(
f = "names",
signature = "ADEgS",
definition = function(x) {
return(names(x@ADEglist))
})
setMethod(
f = "names<-",
signature = c("ADEgS", "character"),
definition = function(x, value) {
nameobj <- deparse(substitute(x))
names(x@ADEglist) <- value
x
})
##############################################
## Extract graphics ##
##############################################
## [: if drop =TRUE can return a ADEg or a length-1 ADEgS
## else return a ADEgS no manipulation is made on the positions
setMethod(
f = "[",
signature = c("ADEgS", "numeric", "missing", "logical"),
definition = function(x, i, j, drop = TRUE) {
if (drop && length(i) == 1)
return(x@ADEglist[[i]]) ## return(adeG)
else
return(new(Class = "ADEgS", ADEglist = x@ADEglist[i], positions = x@positions[i, , drop = drop], add = x@add[i, i, drop = drop], Call = match.call()))
})
setMethod(
f = "[",
signature = c("ADEgS", "numeric", "missing", "missing"),
definition = function(x, i, j, drop) {
object <- x[i, drop = FALSE]
object@Call <- match.call()
return(object)
})
setMethod(
f = "$",
signature = "ADEgS",
definition = function(x, name) {
invisible(x@ADEglist[[name]])
})
setMethod(
f = "[[",
signature = c("ADEgS", "numeric", "missing"),
definition = function(x, i, j, ...) {
invisible(x@ADEglist[[i]])
})
setMethod(
f = "[[",
signature = c("ADEgS", "character", "missing"),
definition = function(x, i, j, ...) {
invisible(x@ADEglist[[i]])
})
setMethod(
f = "[[<-",
signature = c("ADEgS", "numeric", "missing", "ADEg"),
definition = function(x, i, j, ..., value) {
x@ADEglist[[i]] <- value
invisible(x)
})
setMethod(
f = "[[<-",
signature = c("ADEgS", "numeric", "missing", "ADEgS"),
definition = function(x, i, j, ..., value) {
x@ADEglist[[i]] <- value
invisible(x)
})
##############################################
## superposition ##
##############################################
setMethod(
f = "superpose",
signature = c("ADEgS", "ADEgORtrellis", "numeric", "logical"),
definition = function(g1, g2, which, plot) {
## new ADEgS
ngraph <- length(g1)
if (which > ngraph)
stop("Values in 'which' should be lower than the length of g1")
if (!inherits(g1[[which]], "ADEg"))
stop("superposition is only available between two ADEg")
addi <- cbind(rbind(g1@add, rep(0, ngraph)), rep(0, ngraph + 1))
addi[which, ngraph + 1] <- 1 ## new graph superpose to which
ADEglist <- g1@ADEglist
ADEglist[[ngraph + 1]] <- g2
ADEgS <- new(Class = "ADEgS", ADEglist = ADEglist, positions = rbind(g1@positions, g1@positions[which,]), add = addi, Call = match.call())
if (plot)
print(ADEgS)
invisible(ADEgS)
})
setMethod(
f = "superpose",
signature = c("ADEgS", "ADEgORtrellis", "numeric", "ANY"),
definition = function(g1, g2, which, plot) {
objectnew <- superpose(g1, g2, which = which, plot = FALSE)
objectnew@Call <- match.call()
if (plot)
print(objectnew)
invisible(objectnew)
})
setMethod(
f = "superpose",
signature = c("ADEgS", "ADEgORtrellis", "missing", "ANY"),
definition = function(g1, g2, which, plot) {
if (!inherits(g1[[length(g1)]], "ADEg"))
stop("superposition is only available between two ADEg")
objectnew <- superpose(g1, g2, which = length(g1), plot = FALSE)
objectnew@Call <- match.call()
if (plot)
print(objectnew)
invisible(objectnew)
})
setMethod(
f = "superpose",
signature = c("ADEgS", "ADEgS", "missing", "ANY"),
definition = function(g1, g2, which, plot) {
## superpose two ADEgS which have the same number of graphics and the same positions
if (length(g1) != length(g2))
stop("The two ADEgS objects should contain the same number of graphics")
if (!isTRUE(all.equal(g1@positions, g2@positions, check.attributes = FALSE)))
stop("The two ADEgS objects should have the same 'positions' slot")
f1 <- function(x, y) {
if (inherits(x, "ADEg")) {
addi <- matrix(0, 2, 2)
addi[1,2] <- 1
thecall <- call("superpose", x@Call, y@Call)
obj <- new(Class = "ADEgS", ADEglist = list(x, y), positions = matrix(rep(c(0, 1), each = 4), 2, 4), add = addi, Call = thecall)
} else if (inherits(x, "ADEgS")) {
addi <- x@add
ng <- ncol(addi)
posi <- x@positions
## check that positions in posi are all equal and one 1 in each column of addi (i.e. graphs are still superposed)
checkadd <- all(colSums(addi[, -1, drop = FALSE]) > 0)
checkpos <- isTRUE(all.equal(matrix(posi[1, ], nrow = nrow(posi), ncol = ncol(posi), byrow = TRUE), posi))
if (!checkpos | !checkadd)
stop("ADEgS object should contain only superposition")
## superpose
addi <- rbind(addi, rep(0, ng))
addi <- cbind(addi, rep(0, ng + 1))
addi[ng, ng + 1] <- 1
posi <- rbind(posi, posi[1,])
thecall <- call("superpose", x@Call, y@Call)
obj <- new(Class = "ADEgS", ADEglist = c(x@ADEglist, list(y)), positions = posi, add = addi, Call = thecall)
}
invisible(obj)
}
res <- lapply(1:length(g1), FUN = function(i) {f1(g1[[i]], g2[[i]])})
obj <- new(Class = "ADEgS", ADEglist = res, positions = g1@positions, add = g1@add, Call = match.call())
if (plot)
print(obj)
invisible(obj)
})
setMethod(
f = "+",
signature = c("ADEgS", "ADEg"),
definition = function(e1, e2) {
newobj <- superpose(e1, e2, plot = TRUE)
newobj@Call <- match.call()
return(newobj)
})
setMethod(
f = "+",
signature = c("ADEg", "ADEgS"),
definition = function(e1, e2) {
newobj <- superpose(e2, e1, plot = TRUE)
warning("the second graph is below the first one ; the reverse situation is not yet implemented", call. = FALSE)
newobj@Call <- match.call()
return(newobj)
})
setMethod(
f = "cbindADEg",
signature = c("ADEgORADEgSORtrellis", "ADEgORADEgSORtrellis"),
definition = function(g1, g2, ..., plot = FALSE) {
if (try(is.list(...), silent = TRUE) == TRUE)
glist <- as.list(c(g1, g2, ...))
else
glist <- list(g1, g2, ...)
nbg <- length(glist)
obj <- ADEgS(adeglist = glist, layout = c(1, nbg), add = matrix(0, ncol = nbg, nrow = nbg), plot = FALSE)
obj@Call <- match.call()
if (plot)
print(obj)
invisible(obj)
})
setMethod(
f = "rbindADEg",
signature = c("ADEgORADEgSORtrellis", "ADEgORADEgSORtrellis"),
definition = function(g1, g2, ..., plot = FALSE) {
if (try(is.list(...), silent = TRUE) == TRUE)
glist <- as.list(c(g1, g2, ...))
else
glist <- list(g1, g2, ...)
nbg <- length(glist)
obj <- ADEgS(adeglist = glist, layout = c(nbg, 1), add = matrix(0, ncol = nbg, nrow = nbg), plot = FALSE)
obj@Call <- match.call()
if (plot)
print(obj)
invisible(obj)
})
##############################################
## insertion ##
##############################################
setMethod(
f = "insert",
signature = c("ADEgS", "missing"),
definition = function(graphics, oldgraphics, posi, ratio, inset, plot, which, dispatch) {
positions <- .getposition(posi, w = ratio, h = ratio) + inset
currentgraphic <- get("currentadeg", envir = .ADEgEnv)
if (!(length(currentgraphic)))
stop("no existing graphics")
else
newADEgS <- insert(graphics = graphics, oldgraphics = currentgraphic, posi = posi, ratio = ratio, inset = inset, plot = plot, which = which, dispatch = dispatch)
if (plot)
print(newADEgS[length(newADEgS)], newpage = FALSE)
assign("currentadeg", newADEgS, envir = .ADEgEnv)
invisible(newADEgS)
})
setMethod(
f = "insert",
signature = c("ADEgS", "ADEg"),
definition = function(graphics, oldgraphics, posi, ratio, inset, plot) {
positions <- .getposition(posi, w = ratio, h = ratio) + inset
thecall <- call("insert", graphics@Call, oldgraphics@Call)
newADEgS <- new(Class = "ADEgS", ADEglist = list(oldgraphics, graphics), positions = rbind(c(0, 0, 1, 1), positions), add = matrix(0, ncol = 2, nrow = 2), thecall)
if (plot)
print(newADEgS)
assign("currentadeg", newADEgS, envir = .ADEgEnv)
invisible(newADEgS)
})
setMethod(
f = "insert",
signature = c("ADEgORtrellis", "ADEgS"),
definition = function(graphics, oldgraphics, posi, ratio, inset, plot, which) {
thecall <- call("insert", graphics@Call, oldgraphics@Call)
if (missing(which)) {
positions <- .getposition(posi, w = ratio, h = ratio) + inset
newADEgS <- new(Class = "ADEgS", ADEglist = c(oldgraphics@ADEglist, list(graphics)), positions = rbind(oldgraphics@positions, positions), add = rbind(cbind(oldgraphics@add, rep(0, length.out = nrow(oldgraphics@add))), rep(0, length.out = ncol(oldgraphics@add) + 1)), Call = thecall)
} else {
l <- sapply(1:length(oldgraphics), FUN = function(i) {if (i %in% which) {insert(graphics, oldgraphics@ADEglist[[i]], posi = posi, ratio = ratio, inset = inset, plot = FALSE)} else oldgraphics@ADEglist[[i]]})
newADEgS <- new(Class = "ADEgS", ADEglist = l, positions = oldgraphics@positions, add = oldgraphics@add, Call = thecall)
}
if (plot)
print(newADEgS)
assign("currentadeg", newADEgS, envir = .ADEgEnv)
invisible(newADEgS)
})
setMethod(
f = "insert",
signature = c("ADEgS", "ADEgS"),
definition = function(graphics, oldgraphics, posi, ratio, inset, plot, which, dispatch) {
thecall <- call("insert", graphics@Call, oldgraphics@Call)
if (!dispatch){
if (missing(which)) {
positions <- .getposition(posi, w = ratio, h = ratio) + inset
newADEgS <- new(Class = "ADEgS", ADEglist = c(oldgraphics@ADEglist, list(graphics)), positions = rbind(oldgraphics@positions, positions), add = rbind(cbind(oldgraphics@add, rep(0, length.out = nrow(oldgraphics@add))), rep(0, length.out = ncol(oldgraphics@add) + 1)), Call = thecall)
} else {
l <- sapply(1:length(oldgraphics), FUN = function(i) {if (i %in% which) {insert(graphics, oldgraphics@ADEglist[[i]], posi = posi, ratio = ratio, inset = inset, plot = FALSE)} else oldgraphics@ADEglist[[i]]})
newADEgS <- new(Class = "ADEgS", ADEglist = l, positions = oldgraphics@positions, add = oldgraphics@add, Call = thecall)
}
} else {
if (length(graphics) != length(oldgraphics))
stop("dispatch option is not allowed with ADEgS object of different length")
else {
l <- sapply(1:length(oldgraphics), FUN = function(i) {insert(graphics@ADEglist[[i]], oldgraphics@ADEglist[[i]], posi = posi, ratio = ratio, inset = inset, plot = FALSE)})
newADEgS <- new(Class = "ADEgS", ADEglist = l, positions = oldgraphics@positions, add = oldgraphics@add, Call = thecall)
}
}
if (plot)
print(newADEgS)
assign("currentadeg", newADEgS, envir = .ADEgEnv)
invisible(newADEgS)
})
##############################################
## Update ##
##############################################
## update the modified parameters
setMethod(
f = "update",
signature = "ADEgS",
definition = function(object, ..., plot = TRUE) {
nameobj <- deparse(substitute(object, env = parent.frame()))
## object is in parent.frame() because 'update' method pattern is different with 'update' generic method pattern
## see https://stat.ethz.ch/pipermail/r-help/2008-January/152296.html
slots <- list()
slots$names <- names(object)
slots$positions <- object@positions
## extract specific slots used in function call
pattern <- c("names", "positions")
lpattern <- as.list(rep("", length(pattern)))
names(lpattern) <- pattern
## sort parameters
sep <- separation(..., pattern = lpattern)
slots <- modifyList(slots, sep[[1]], keep.null = TRUE)
sep[[2]] <- sortparamADEgS(sep[[2]], graphsnames = slots$names)
ADEglist <- sapply(1:length(object@ADEglist), FUN = function(x) {if (inherits(object@ADEglist[[x]], "ADEg") | inherits(object@ADEglist[[x]], "ADEgS")) update(object@ADEglist[[x]], plot = FALSE, sep[[2]][[x]]) else do.call("update", c(list(object = object@ADEglist[[x]]), sep[[2]][[x]]))})
object <- new("ADEgS", ADEglist = ADEglist, positions = slots$positions, add = object@add, Call = match.call())
names(object) <- slots$names
if (plot)
print(object)
assign(nameobj, object, envir = parent.frame(n = 2))
## see also https://stat.ethz.ch/pipermail/r-help/2008-January/152296.html
assign("currentadeg", object, envir = .ADEgEnv)
})
##############################################
## Display ##
##############################################
setMethod(
f = "show",
signature = "ADEgS",
definition = function(object) {
print(object)
})
setMethod(
f = "plot",
signature = c("ADEgS", "ANY"),
definition = function(x, y) {
print(x)
})
setMethod(
f = "print",
signature = "ADEgS",
definition = function(x, closeViewport = TRUE, square = NULL) {
oldtextcex <- trellis.par.get("fontsize")$text
oldpointcex <- trellis.par.get("fontsize")$points
oldmarginH <- trellis.par.get("layout.heights")
oldmarginW <- trellis.par.get("layout.widths")
trellis.par.set(layout.heights = list(top.padding = .2 + oldmarginH$top.padding, bottom.padding = .2 + oldmarginH$bottom.padding), layout.widths = list(left.padding = .2 + oldmarginW$left.padding, right.padding = .2 + oldmarginW$right.padding))
on.exit(trellis.par.set(list("fontsize" = list("text" = oldtextcex, "points" = oldpointcex), "layout.widths" = list("left.padding" = oldmarginW$left.padding, "right.padding" = oldmarginW$right.padding), "layout.heights" = list("top.padding" = oldmarginH$top.padding, "bottom.padding" = oldmarginH$bottom.padding))))
gettextsize <- function(widG, heigG) {
## Adjust text size to viewport size
if (widG < 1 / 2 || heigG < 1 / 2)
return(0.66 / 1.25)
if (widG == 1 / 2 && heigG == 1 / 2)
return(0.83 / 1.25)
if (widG == 1 && heigG == 1)
return(1)
else return(1 / 1.25)
}
getxscale <- function(object) {
## Obtain limits for x
res <- c(0, 1)
if (inherits(object, "ADEg"))
object <- gettrellis(object)
if (inherits(object, "trellis")) {
if (is.numeric(object$x.limits))
res <- object$x.limits
}
return(res)
}
getyscale <- function(object) {
## Obtain limits for y
res <- c(0, 1)
if (inherits(object, "ADEg"))
object <- gettrellis(object)
if (inherits(object, "trellis")) {
if (is.numeric(object$y.limits))
res <- object$y.limits
}
return(res)
}
printADEGs <- function(adegobject, closeViewport, square) {
if (closeViewport)
grid.newpage()
positions <- adegobject@positions
listG <- adegobject@ADEglist
## create the list of viewport and push it
unit.vpL <- "npc"
if (isTRUE(square))
unit.vpL <- "snpc"
vpL <- do.call("vpList", lapply(1:length(listG), function(i) do.call("viewport", args = list(x = positions[i, 1], y = positions[i, 2], width = positions[i, 3] - positions[i, 1], height = positions[i, 4] - positions[i, 2], just = c(0, 0), name = names(listG)[i], xscale = getxscale(listG[[i]]), yscale = getyscale(listG[[i]]), default.units = unit.vpL))))
pushViewport(vpL)
upViewport(0)
width.root <- convertWidth(unit(1, unit.vpL), "inches", valueOnly = TRUE)
height.root <- convertHeight(unit(1, unit.vpL), "inches", valueOnly = TRUE)
for (i in 1:length(listG)) {
object <- listG[[i]]
seekViewport(names(listG)[i])
if (inherits(object, "ADEg") | inherits(object, "trellis")) {
if (inherits(object, "ADEg"))
trobject <- gettrellis(object)
else
trobject <- object
square.i <- ifelse(is.null(square), !trobject$aspect.fill, square)
unit.vpi <- "npc"
if (isTRUE(square.i))
unit.vpi <- "snpc"
vp <- viewport(x = 0, y = 0, width = 1, height = 1, just = c(0, 0), name = "current", xscale = getxscale(listG[[i]]), yscale = getyscale(listG[[i]]), default.units = unit.vpi)
pushViewport(vp)
width.current <- convertWidth(unit(1, unit.vpi), "inches", valueOnly = TRUE)
height.current <- convertHeight(unit(1, unit.vpi), "inches", valueOnly = TRUE)
ratio.width <- width.current / width.root
ratio.height <- height.current / height.root
cst <- gettextsize(ratio.width, ratio.height)
sup <- adegobject@add[, i]
trellis.par.set(list("fontsize" = list("text" = oldtextcex * cst, "points" = oldpointcex * cst)))
if (any(sup == 1))
printSuperpose(g1 = object, refg = listG[[which(adegobject@add[, i] == 1)[1]]])
else
print(object, newpage = FALSE)
popViewport()
} else if (inherits(object, "ADEgS")) {
names(object) <- paste(names(listG)[i], names(object), sep = ".")
printADEGs(object, closeViewport = FALSE, square = square)
} else {
stop(paste("Not implemented for class:", class(object), sep = " "))
}
popViewport()
}
}
printADEGs(x, closeViewport = closeViewport, square = square)
assign("currentadeg", x, envir = .ADEgEnv)
})
##############################################
## Creation ##
##############################################
ADEgS <- function(adeglist, positions, layout, add = NULL, plot = TRUE) {
m <- matrix(0, length(adeglist), length(adeglist))
if (missing(layout) & (is.null(add) | identical(add, m)) & missing(positions))
layout <- .n2mfrow(length(adeglist))
if (missing(positions) & !missing(layout)) {
if (is.list(layout)) ## in layout: width and heights informations, layout is a list
positions <- do.call("layout2position", layout)
else
positions <- layout2position(layout, ng = length(adeglist))
}
if (missing(positions))
positions <- matrix(rep(c(0, 0, 1, 1), length.out = length(adeglist) * 4), byrow = TRUE, ncol = 4)
if (is.null(add))
add <- m
ADEgObject <- new(Class = "ADEgS", ADEglist = adeglist, positions = positions, add = add, Call = match.call())
if (plot)
print(ADEgObject)
invisible(ADEgObject)
}
adegraphics/R/S2.label.R 0000644 0001762 0000144 00000007764 14354572662 014446 0 ustar ligges users #########################################################
### s.label ##
#########################################################
setClass(
Class = "S2.label",
contains = "ADEg.S2"
)
setMethod(
f = "initialize",
signature = "S2.label",
definition = function(.Object, data = list(dfxy = NULL, labels = NULL, xax = 1, yax = 2, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.S2 initialize
.Object@data$labels <- data$labels
return(.Object)
})
setMethod(
f = "prepare",
signature = "S2.label",
definition = function(object) {
name_obj <- deparse(substitute(object))
if(object@data$storeData) {
labels <- object@data$labels
} else {
labels <- eval(object@data$labels, envir = sys.frame(object@data$frame))
}
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
## change default for some parameters
if((is.null(object@adeg.par$plabels$boxes$draw) & adegtot$plabels$optim) || (is.null(object@adeg.par$plabels$boxes$draw) & length(labels) > 1000))
adegtot$plabels$boxes$draw <- FALSE
if(is.null(object@adeg.par$porigin$include) & (any(names(object@g.args) %in% c("Sp", "nbobject"))))
adegtot$porigin$include <- FALSE
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "S2.label",
definition = function(object, x, y) {
## draw labels
if(any(object@adeg.par$ppoints$cex > 0))
panel.points(x, y, pch = object@adeg.par$ppoints$pch, cex = object@adeg.par$ppoints$cex, col = object@adeg.par$ppoints$col, alpha = object@adeg.par$ppoints$alpha, fill = object@adeg.par$ppoints$fill)
if(object@data$storeData)
labels <- object@data$labels
else
labels <- eval(object@data$labels, envir = sys.frame(object@data$frame))
if(any(object@adeg.par$plabels$cex > 0) & (!is.null(labels)))
adeg.panel.label(x, y, labels, object@adeg.par$plabels)
})
s.label <- function(dfxy, labels = rownames(dfxy), xax = 1, yax = 2, facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters
thecall <- .expand.call(match.call())
df <- try(as.data.frame(eval(thecall$dfxy, envir = sys.frame(sys.nframe() + pos))), silent = TRUE)
if(inherits(df, "try-error") | is.null(thecall$dfxy)) ## non convenient dfxy argument
stop("non convenient selection for dfxy (can not be converted to dataframe)")
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if((length(xax) == 1 & length(yax) == 1))
object <- multi.facets.S2(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple xax/yax")
}
## multiple axes
else if((length(xax) > 1 | length(yax) > 1)) {
object <- multi.ax.S2(thecall)
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
if(storeData)
tmp_data <- list(dfxy = dfxy, xax = xax, yax = yax, labels = labels, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(dfxy = thecall$dfxy, xax = xax, yax = yax, labels = thecall$labels, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "S2.label", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = sortparameters$g.args, Call = as.call(thecall))
## preparation
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/S2.distri.R 0000644 0001762 0000144 00000020420 14354572640 014641 0 ustar ligges users ##########################################################################
## s.distri ##
##########################################################################
setClass(
Class = "S2.distri",
contains = "ADEg.S2"
)
setMethod(
f = "initialize",
signature = "S2.distri",
definition = function(.Object, data = list(dfxy = NULL, dfdistri = NULL, xax = 1, yax = 2, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...)
.Object@data$dfdistri <- data$dfdistri
return(.Object)
})
setMethod(
## prepare computations for ellipses, stars and labels
f = "prepare",
signature = "S2.distri",
definition = function(object) {
name_obj <- deparse(substitute(object))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
if(!object@data$storeData) {
dfxy <- eval(object@data$dfxy, envir = sys.frame(object@data$frame))
dfdistri <- eval(object@data$dfdistri, envir = sys.frame(object@data$frame))
} else {
dfxy <- object@data$dfxy
dfdistri <- object@data$dfdistri
}
## change default for some parameters
if(is.null(colnames(dfdistri)))
adegtot$plabels$cex <- 0 ## no labels if no colnames in original data
if(is.null(object@adeg.par$porigin$include) & (any(names(object@g.args) %in% c("Sp", "nbobject"))))
adegtot$porigin$include <- FALSE
## setting colors
paramsToColor <- list(plabels = list(col = object@adeg.par$plabels$col, boxes = list(border = object@adeg.par$plabels$boxes$border)),
plines = list(col = object@adeg.par$plines$col),
pellipses = list(border = object@adeg.par$pellipses$border, col = object@adeg.par$pellipses$col))
if(!(is.null(object@g.args$col) || (is.logical(object@g.args$col) && !object@g.args$col)))
adegtot <- modifyList(adegtot, col2adepar(ccol = object@g.args$col, pparamsToColor = paramsToColor, nnlev = NCOL(dfdistri)))
## statistics calculus
object@stats$means <- t(apply(as.data.frame(dfdistri), 2, FUN = function(x) {apply(dfxy[, c(object@data$xax, object@data$yax)], 2, weighted.mean , w = x)}))
if(object@g.args$ellipseSize)
object@stats$covvar <- lapply(as.data.frame(dfdistri), FUN = function(x) {covwt(dfxy[, c(object@data$xax, object@data$yax)], wt = x)})
else
object@stats$covvar <- NULL
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
## compute ellipses
if(object@g.args$ellipseSize > 0) {
object@s.misc$ellipses <- lapply(1:nrow(object@stats$means), FUN = function(i) {
.util.ellipse(object@stats$means[i, 1], object@stats$means[i, 2], vx = object@stats$covvar[[i]][1, 1], vy = object@stats$covvar[[i]][2, 2],
cxy = object@stats$covvar[[i]][1, 2], coeff = object@g.args$ellipseSize)
})
}
## never optimized labels for s.distri
object@adeg.par$plabels$optim <- FALSE
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "S2.distri",
definition = function(object, x, y) {
if(object@data$storeData)
dfdistri <- object@data$dfdistri
else
dfdistri <- eval(object@data$dfdistri, envir = sys.frame(object@data$frame))
## ellipses
if(object@g.args$ellipseSize > 0) {
ellip <- object@s.misc$ellipses
pellip <- object@adeg.par$pellipses
pellip <- lapply(pellip, FUN = function(x) {if(is.list(x)) return(x) else rep(x, length.out = length(ellip))})
pellip$axes <- lapply(pellip$axes, FUN = function(x) {rep(x, length.out = length(ellip))})
for(group in 1:NCOL(dfdistri)) { ## for each group
ell <- ellip[[group]]
if(!(any(is.null(ell))))
if(!any(is.na(ell))) {
panel.polygon(ell$x, ell$y, col = pellip$col[group], lwd = pellip$lwd[group],
lty = pellip$lty[group], alpha = pellip$alpha[group], border = pellip$border[group])
if(pellip$axes$draw[group]) {
## axes drawing
panel.segments(ell$seg1[1], ell$seg1[2], ell$seg1[3], ell$seg1[4], lwd = pellip$axes$lwd[group],
lty = pellip$axes$lty[group], col = pellip$axes$col[group])
panel.segments(ell$seg2[1], ell$seg2[2], ell$seg2[3], ell$seg2[4], lwd = pellip$axes$lwd[group],
lty = pellip$axes$lty[group], col = pellip$axes$col[group])
}
}
}
}
## stars
if(object@g.args$starSize > 0) {
plines <- lapply(object@adeg.par$plines, FUN = function(x) {rep(x, length.out = NCOL(dfdistri))})
for(group in 1:NCOL(dfdistri)) {
if(all(is.finite(object@stats$means[group, ]))) {
xbase <- object@stats$means[group, 1]
ybase <- object@stats$means[group, 2]
xlev <- x[which(as.data.frame(dfdistri)[, group] > 0)]
ylev <- y[which(as.data.frame(dfdistri)[, group] > 0)]
panel.segments(
x0 = xbase,
y0 = ybase,
x1 = xbase + object@g.args$starSize * (xlev - xbase),
y1 = ybase + object@g.args$starSize * (ylev - ybase),
lty = plines$lty[group], lwd = plines$lwd[group], col = plines$col[group])
}
}
}
## plot points
if(any(object@adeg.par$ppoints$cex > 0)) {
ppoints <- lapply(object@adeg.par$ppoints, function(x) rep(x, length.out = NROW(dfdistri)))
if(any(is.na(ppoints$pch))) {
indx <- 1:length(x)
indx <- indx[- which(is.na(ppoints$pch))]
panel.points(x = x[indx], y = y[indx], type = "p", pch = ppoints$pch[indx], cex = ppoints$cex[indx],
col = ppoints$col[indx], alpha = ppoints$alpha[indx], fill = ppoints$fill[indx])}
else
panel.points(x = x, y = y, type = "p", pch = ppoints$pch, cex = ppoints$cex, col = ppoints$col,
alpha = ppoints$alpha, fill = ppoints$fill)
}
## plot of labels
if(any(object@adeg.par$plabels$cex > 0)) {
labX <- object@stats$means[, 1]
labY <- object@stats$means[, 2]
adeg.panel.label(x = labX, y = labY, labels = colnames(dfdistri), object@adeg.par$plabels)
}
})
s.distri <- function(dfxy, dfdistri, xax = 1, yax = 2, starSize = 1, ellipseSize = 1.5, col = NULL, facets = NULL, plot = TRUE,
storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters (required for multiplot)
thecall <- .expand.call(match.call())
df <- try(as.data.frame(eval(thecall$dfxy, envir = sys.frame(sys.nframe() + pos))), silent = TRUE)
if(inherits(df, "try-error") | is.null(dfxy))
stop("dfxy, can not be converted as dataframe or is NULL")
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if((length(xax) == 1 & length(yax) == 1))
object <- multi.facets.S2(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple xax/yax")
}
## multiple axes
else if((length(xax) > 1 | length(yax) > 1)) {
object <- multi.ax.S2(thecall)
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(ellipseSize = ellipseSize, starSize = starSize, col = col))
if(storeData)
tmp_data <- list(dfxy = dfxy, dfdistri = dfdistri, xax = xax, yax = yax, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(dfxy = thecall$dfxy, dfdistri = thecall$dfdistri, xax = xax, yax = yax, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "S2.distri", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = as.call(thecall))
## preparation of the graph
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(! add & plot)
print(object)
invisible(object)
}
adegraphics/R/ade4-kplot.R 0000644 0001762 0000144 00000052016 13747033141 015023 0 ustar ligges users "kplot.mcoa" <- function(object, xax = 1, yax = 2, which.tab = 1:nrow(object$cov2), option = c("points", "axis", "columns"), pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(object, "mcoa"))
stop("Object of class 'mcoa' expected")
if((xax == yax) || (object$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > object$nf)
stop("Non convenient xax")
if(yax > object$nf)
stop("Non convenient yax")
option <- match.arg(option)
## parameters management
sortparameters <- sortparamADEg(...)
if(option == "points") {
params1 <- list()
params1$adepar <- list(psub = list(text = "Reference"), plabels = list(cex = 1.25))
sortparameters1 <- modifyList(params1, sortparameters, keep.null = TRUE)
ref <- do.call("s.label", c(list(dfxy = substitute(object$SynVar), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters1$adepar, sortparameters1$trellis, sortparameters1$g.args))
params2 <- list()
params2$adepar <- list(plabels = list(cex = 0))
params2$g.args <- list(samelimits = FALSE)
sortparameters2 <- modifyList(params2, sortparameters, keep.null = TRUE)
facets1 <- substitute(object$TL[,1])
coolig <- call("as.data.frame", call("matrix", call("kronecker", rep(1,nrow(object$cov2)), substitute(as.matrix(object$SynVar))), nrow = nrow(object$Tl1), ncol = ncol(object$Tl1), dimnames = substitute(list(rownames(object$Tl1), colnames(object$Tl1)))))
g1 <- do.call("s.match", c(list(dfxy1 = coolig, dfxy2 = substitute(object$Tl1), facets = facets1, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters2$adepar, sortparameters2$trellis, sortparameters2$g.args))[which.tab]
## ADEgS creation
ADEglist <- c(list(ref), g1@ADEglist)
nrow_lay <- floor(sqrt(length(ADEglist))) + 1
ncol_lay <- -floor(-(length(ADEglist)) / nrow_lay)
lay <- matrix(c(seq(1, length(ADEglist)), rep(0, nrow_lay * ncol_lay - length(ADEglist))), nrow = nrow_lay, byrow = TRUE)
obj <- new(Class = "ADEgS", ADEglist = ADEglist, positions = layout2position(lay), add = matrix(0, ncol = length(ADEglist), nrow = length(ADEglist)), Call = match.call())
names(obj) <- c("ref", names(g1))
} else if(option == "axis") {
params <- list()
params$adepar <- list(pbackground = list(box = FALSE), plabels = list(cex = 1.25))
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
facets2 <- substitute(object$T4[, 1])
obj <- do.call("s.corcircle", c(list(dfxy = substitute(object$Tax), facets = facets2, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$adepar, sortparameters$trellis, sortparameters$g.args))[which.tab]
} else if(option == "columns") {
params <- list()
params$adepar <- list(plabels = list(cex = 1.25))
params$g.args <- list(samelimits = FALSE)
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
facets3 <- substitute(object$TC[, 1])
obj <- do.call("s.arrow", c(list(dfxy = substitute(object$Tco), facets = facets3, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$adepar, sortparameters$trellis, sortparameters$g.args))[which.tab]
}
obj@Call <- match.call()
if(plot)
print(obj)
invisible(obj)
}
"kplot.mfa" <- function(object, xax = 1, yax = 2, which.tab = 1:length(object$blo), traject = FALSE, permute = FALSE, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(object, "mfa"))
stop("Object of class 'mfa' expected")
if((xax == yax) || (object$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > object$nf)
stop("Non convenient xax")
if(yax > object$nf)
stop("Non convenient yax")
## sort parameters for each graph
graphsnames <- c("row", "col", "traj")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## parameters management
params <- list()
params$row <- list(plabels = list(cex = 0), ppoints = list(cex = 1.5), samelimits = FALSE)
params$col <- list(psub = list(cex = 0), plabels = list(cex = 1.25))
params$traj <- list(plabels = list(cex = 0), psub = list(cex = 0))
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## prepare
if(permute) {
dfxy_row <- substitute(object$co)
dfxy_col <- substitute(object$lisup)
facets_row <- substitute(object$TC[,1])
facets_col <- substitute(object$TL[,1])
} else {
dfxy_row <- substitute(object$lisup)
dfxy_col <- substitute(object$co)
facets_row <- substitute(object$TL[,1])
facets_col <- substitute(object$TC[,1])
}
## create g1
g1 <- do.call("s.label", c(list(dfxy = dfxy_row, facets = facets_row, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$row))[which.tab]
## prepare and create g2
if(permute)
dcol <- object$lisup
else
dcol <- object$co
k <- c(min(dcol[, xax]), max(dcol[, xax]), min(dcol[, yax]), max(dcol[, yax])) / c(g1[[1]]@g.args$xlim, g1[[1]]@g.args$ylim)
dcol <- substitute(dfxy_col * 0.7 / max(k))
g2 <- do.call("s.arrow", c(list(dfxy = dcol, facets = facets_col, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$col))[which.tab]
obj <- do.call("superpose", list(g1, g2))
obj@Call <- call("superpose", g1@Call, g2@Call)
## create g3
if(traject) {
g3 <- do.call("s.traject", c(list(dfxy = dfxy_row, facets = facets_row, xax = xax, yax = yax, plot = FALSE, storeData = FALSE, pos = pos - 2), sortparameters$traj))[which.tab]
obj <- do.call("superpose", list(obj, g3))
obj@Call <- call("superpose", obj@Call, g3@Call)
}
## ADEgS creation
names(obj) <- object$tab.names[which.tab]
obj@Call <- match.call()
if(plot)
print(obj)
invisible(obj)
}
"kplot.pta" <- function(object, xax = 1, yax = 2, which.tab = 1:nrow(object$RV), which.graph = 1:4, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(object, "pta"))
stop("Object of class 'pta' expected")
if((xax == yax) || (object$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(!is.numeric(which.graph) || any(which.graph < 1) || any(which.graph > 4))
stop("'which' must be in 1:4")
if(xax > object$nf)
stop("Non convenient xax")
if(yax > object$nf)
stop("Non convenient yax")
## sort parameters for each graph
graphsnames <- c("axis", "row", "col", "components")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## parameters management
params <- list()
params$axis <- list(pbackground = list(box = FALSE), plabels = list(alpha = 1, cex = 1.25))
params$rows <- list(plabels = list(alpha = 1, cex = 1.25))
params$columns <- list(plabels = list(cex = 1.25))
params$components <- list(pbackground = list(box = FALSE), plabels = list(cex = 1.25))
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
g <- as.null()
adeglist <- as.null()
## creation of each individual ADEg
if(1 %in% which.graph) {
facets1 <- substitute(object$T4[, 1])
g1 <- do.call("s.corcircle", c(list(dfxy = substitute(object$Tax), labels = substitute(object$T4[, 2]), facets = facets1, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$axis))[which.tab]
names(g1) <- paste(graphsnames[1], "_", object$tab.names, sep = "")[which.tab]
g <- c(g, g1)
adeglist <- c(adeglist, g1@ADEglist)
}
if(2 %in% which.graph) {
facets2 <- substitute(object$TL[, 1])
g2 <- do.call("s.label", c(list(dfxy = substitute(object$Tli), labels = substitute(object$TL[,2]), facets = facets2, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$rows))[which.tab]
names(g2) <- paste(graphsnames[2], "_", object$tab.names, sep = "")[which.tab]
g <- c(g, g2)
adeglist <- c(adeglist, g2@ADEglist)
}
if(3 %in% which.graph) {
facets3 <- substitute(object$TC[, 1])
g3 <- do.call("s.arrow", c(list(dfxy = substitute(object$Tco), labels = substitute(object$TC[,2]), facets = facets3, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$columns))[which.tab]
names(g3) <- paste(graphsnames[3], "_", object$tab.names, sep = "")[which.tab]
g <- c(g, g3)
adeglist <- c(adeglist, g3@ADEglist)
}
if(4 %in% which.graph) {
facets4 <- substitute(object$T4[, 1])
g4 <- do.call("s.corcircle", c(list(dfxy = substitute(object$Tcomp), labels = substitute(object$T4[, 2]), facets = facets4, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$components))[which.tab]
names(g4) <- paste(graphsnames[4], "_", object$tab.names, sep = "")[which.tab]
g <- c(g, g4)
adeglist <- c(adeglist, g4@ADEglist)
}
## ADEgS creation
ng <- sum(sapply(g, function(x) length(x)))
lay <- matrix(1:ng, ncol = length(which.graph))
obj <- new(Class = "ADEgS", ADEglist = c(adeglist), positions = layout2position(lay), add = matrix(0, ncol = ng, nrow = ng), Call = match.call())
if(plot)
print(obj)
invisible(obj)
}
"kplot.sepan" <- function(object, xax = 1, yax = 2, which.tab = 1:length(object$blo), permute = FALSE, traject = FALSE, posieig = "bottomleft", pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(object, "sepan"))
stop("Object of class 'sepan' expected")
if((xax == yax) || (length(object$Eig) == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > length(object$Eig))
stop("Non convenient xax")
if(yax > length(object$Eig))
stop("Non convenient yax")
## prepare
if(permute) {
dfxy_row <- substitute(object$Co)
dfxy_col <- substitute(object$Li)
names_row <- substitute(object$TC[,2])
names_col <- substitute(object$TL[,2])
facets_row <- substitute(object$TC[,1])
facets_col <- substitute(object$TL[,1])
} else {
dfxy_row <- substitute(object$Li)
dfxy_col <- substitute(object$Co)
names_row <- substitute(object$TL[,2])
names_col <- substitute(object$TC[,2])
facets_row <- substitute(object$TL[,1])
facets_col <- substitute(object$TC[,1])
}
## sort parameters for each graph
graphsnames <- c("row", "col", "traj", "eig")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## parameters management
params <- list()
params$row <- list(psub = list(position = "bottomright"), samelimits = FALSE)
params$traj <- list(psub = list(position = "bottomright"), plabels = list(cex = 0), samelimits = FALSE)
params$col <- list(psub = list(cex = 0, position = "bottomright"), plabels = list(cex = 1.25))
params$eig <- list(psub = list(text = ""), pbackground = list(box = TRUE), samelimits = FALSE)
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## create g1
if(!traject)
g1 <- do.call("s.label", c(list(dfxy = dfxy_row, labels = names_row, facets = facets_row, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$row))[which.tab]
else
g1 <- do.call("s.traject", c(list(dfxy = dfxy_row, facets = facets_row, xax = xax, yax = yax, plot = FALSE, storeData = FALSE, pos = pos - 2), sortparameters$traj))[which.tab]
## prepare and create g2
if(permute)
dcol <- object$Li
else
dcol <- object$Co
k <- c(min(dcol[, xax]), max(dcol[, xax]), min(dcol[, yax]), max(dcol[, yax])) / c(g1[[1]]@g.args$xlim, g1[[1]]@g.args$ylim)
dcol <- substitute(dfxy_col * 0.7 / max(k))
g2 <- do.call("s.arrow", c(list(dfxy = dcol, labels = names_col, facets = facets_col, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$col))[which.tab]
obj <- do.call("superpose", list(g1, g2))
obj@Call <- call("superpose", g1@Call, g2@Call)
## prepare and create g3
facets_eig <- reorder(as.factor(rep(levels(object$TL[, 1]), object$rank)), rep(1:length(object$rank), object$rank))
if(!any(posieig == "none")) {
g3 <- do.call("plotEig", c(list(eigvalue = substitute(object$Eig), nf = 1:ncol(object$Li), facets = facets_eig, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$eig))[which.tab]
obj <- do.call("insert", list(g3, obj, posi = posieig, plot = FALSE, ratio = 0.2, inset = 0, dispatch = TRUE))
}
## ADEgS creation
names(obj) <- object$tab.names[which.tab]
obj@Call <- match.call()
if(plot)
print(obj)
invisible(obj)
}
"kplotsepan.coa" <- function(object, xax = 1, yax = 2, which.tab = 1:length(object$blo), permute = FALSE, posieig = "bottomleft", pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(object, "sepan"))
stop("Object of class 'sepan' expected")
if((xax == yax) || (length(object$Eig) == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > length(object$Eig))
stop("Non convenient xax")
if(yax > length(object$Eig))
stop("Non convenient yax")
## prepare
if(permute) {
dfxy_row <- substitute(object$C1)
dfxy_col <- substitute(object$Li)
names_row <- substitute(object$TC[,2])
names_col <- substitute(object$TL[,2])
facets_row <- substitute(object$TC[,1])
facets_col <- substitute(object$TL[,1])
} else {
dfxy_row <- substitute(object$Li)
dfxy_col <- substitute(object$C1)
names_row <- substitute(object$TL[,2])
names_col <- substitute(object$TC[,2])
facets_row <- substitute(object$TL[,1])
facets_col <- substitute(object$TC[,1])
}
## sort parameters for each graph
graphsnames <- c("row", "col", "eig")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## parameters management
params <- list()
params$col <- list(psub = list(position = "bottomright"), plabels = list(cex = 1.25), samelimits = FALSE)
params$row <- list(psub = list(cex = 0, position = "bottomright"))
params$eig <- list(psub = list(text = ""), pbackground = list(box = TRUE))
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation and create g1 and g2
g1 <- do.call("s.label", c(list(dfxy = dfxy_col, labels = names_col, facets = facets_col, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$col))[which.tab]
g2 <- do.call("s.label", c(list(dfxy = dfxy_row, labels = names_row, facets = facets_row, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$row))[which.tab]
obj <- do.call("superpose", c(list(g1, g2)))
obj@Call <- call("superpose", g1@Call, g2@Call)
## prepare and create g3
facets_eig <- reorder(as.factor(rep(levels(object$TL[, 1]), object$rank)), rep(1:length(object$rank), object$rank))
if(!any(posieig == "none")) {
g3 <- do.call("plotEig", c(list(eigvalue = substitute(object$Eig), nf = 1:ncol(object$Li), facets = facets_eig, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$eig))[which.tab]
obj <- do.call("insert", list(g3, obj, posi = posieig, plot = FALSE, ratio = 0.2, inset = 0, dispatch = TRUE))
}
## ADEgS creation
names(obj) <- object$tab.names[which.tab]
obj@Call <- match.call()
if(plot)
print(obj)
invisible(obj)
}
"kplot.statis" <- function(object, xax = 1, yax = 2, which.tab = 1:length(object$tab.names), traject = FALSE, arrow = TRUE, class = NULL, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(object, "statis"))
stop("Object of class 'statis' expected")
if((xax == yax) || (object$C.nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > object$C.nf)
stop("Non convenient xax")
if(yax > object$C.nf)
stop("Non convenient yax")
## sort parameters for each graph
graphsnames <- c("col", "traj", "class")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## parameters management
params <- list()
params$col <- list(plabels = list(cex = 1.25))
params$traj <- list(plabels = list(cex = 0), psub = list(cex = 0))
params$class <- list(plabels = list(cex = 1.5), ppoints = list(cex = 2), pellipses = list(alpha = 0, axes = list(draw = FALSE)), psub = list(cex = 0))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## prepare
facets <- substitute(object$TC[, 1])
## creation of each individual ADEg
if(arrow)
g1 <- do.call("s.arrow", c(list(dfxy = substitute(object$C.Co), facets = facets, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$col))[which.tab]
else
g1 <- do.call("s.label", c(list(dfxy = substitute(object$C.Co), xax = xax, yax = yax, facets = facets, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$col))[which.tab]
if(traject) {
g2 <- do.call("s.traject", c(list(dfxy = substitute(object$C.Co), xax = xax, yax = yax, facets = facets, plot = FALSE, storeData = FALSE, pos = pos - 2), sortparameters$traj))[which.tab]
obj <- do.call("superpose", list(g1, g2))
obj@Call <- call("superpose", g1@Call, g2@Call)
} else
obj <- g1
if(!is.null(class)) {
if(length(class) == 1) {
if(class)
g3 <- do.call("s.class", c(list(dfxy = substitute(object$C.Co), fac = object$TC[, 1], xax = xax, yax = yax, facets = facets, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$class))[which.tab]
} else {
if(length(class) == length(object$TC[, 1]))
g3 <- do.call("s.class", c(list(dfxy = substitute(object$C.Co), fac = factor(class), xax = xax, yax = yax, facets = facets, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$class))[which.tab]
}
obj <- do.call("superpose", list(obj, g3))
obj@Call <- call("superpose", g3@Call, obj@Call)
}
## ADEgS creation
names(obj) <- object$tab.names[which.tab]
obj@Call <- match.call()
if(plot)
print(obj)
invisible(obj)
}
"kplot.foucart" <- function(object, xax = 1, yax = 2, which.tab = 1:length(object$blo), pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(object, "foucart"))
stop("Object of class 'foucart' expected")
if((xax == yax) || (object$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > object$nf)
stop("Non convenient xax")
if(yax > object$nf)
stop("Non convenient yax")
## sort parameters for each graph
graphsnames <- c("row", "col")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## limits calcul
df <- rbind(as.matrix(object$li), as.matrix(object$Tli), as.matrix(object$Tco))
adegtot <- adegpar()
lim.global <- setlimits2D(minX = min(df[, xax]), maxX = max(df[, xax]), minY = min(df[, yax]), maxY = max(df[, yax]), origin = adegtot$porigin$origin, aspect.ratio = adegtot$paxes$aspectratio, includeOr = adegtot$porigin$include)
## parameters management
params <- list()
params$row <- list(plabels = list(cex = 1), xlim = lim.global$xlim, ylim = lim.global$ylim, plabels = list(cex = 1.25))
params$col <- list(plabels = list(cex = 1.25), psub = list(text = ""), xlim = lim.global$xlim, ylim = lim.global$ylim, plabels = list(cex = 1.25))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g1 <- do.call("s.label", c(list(dfxy = substitute(object$Tli), facets = substitute(object$TL[, 1]), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$row))[which.tab]
g2 <- do.call("s.label", c(list(dfxy = substitute(object$Tco), facets = substitute(object$TC[, 1]), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$col))[which.tab]
## ADEgS creation
obj <- do.call("superpose", list(g1, g2))
names(obj) <- object$tab.names
obj@Call <- match.call()
if(plot)
print(obj)
invisible(obj)
}
"kplot.mbpcaiv" <- function(object, xax = 1, yax = 2, which.tab = 1:length(object$blo), pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(object, "mbpcaiv"))
stop("Object of class 'mbpcaiv' expected")
if((xax == yax) || (object$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > object$nf)
stop("Non convenient xax")
if(yax > object$nf)
stop("Non convenient yax")
sortparameters <- sortparamADEg(...)
obj <- do.call("s.label", c(list(dfxy = substitute(object$Tli), xax = xax, yax = yax, facets = substitute(object$TL[, 1]), plot = plot, storeData = storeData, pos = pos - 2), adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = sortparameters$g.args))[which.tab]
obj@Call <- match.call()
if(plot)
print(obj)
invisible(obj)
}
adegraphics/R/C1.hist.R 0000644 0001762 0000144 00000012167 13742303021 014263 0 ustar ligges users setClass(
Class = "C1.hist",
contains = "ADEg.C1"
)
setMethod(
f = "initialize",
signature = "C1.hist",
definition = function(.Object, data = list(score = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.C1 initialize
validObject(.Object)
return(.Object)
})
setMethod(
f = "prepare",
signature = "C1.hist",
definition = function(object) {
nameobj <- deparse(substitute(object))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
## check if the input data is an histogram or not
isHist <- ifelse(inherits(object@data$score, "histogram"), TRUE, FALSE)
if(object@data$storeData)
score <- object@data$score
else
score <- eval(object@data$score, envir = sys.frame(object@data$frame))
if(isHist) {
h <- object@data$score
object@data$score <- runif(100, min = object@g.args$xlim[1], max = object@g.args$xlim[2])
} else {
score <- as.matrix(score)[, 1] ## to manage 'score' when it is a data.frame with only one column
}
## change default for some parameters
adegtot$p1d$rug$draw <- FALSE
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
## compute histogram
if(!isHist)
h <- hist(score, breaks = if(is.null(object@g.args$breaks)) object@g.args$nclass else object@g.args$breaks, right = object@g.args$right, plot = FALSE)
y <- switch(object@g.args$type, count = h$counts, percent = 100 * h$counts / length(score), density = h$density)
object@stats$heights <- y
object@stats$breaks <- h$breaks
if(object@adeg.par$p1d$horizontal && is.null(object@g.args$ylim))
object@g.args$ylim <- c(0, 1.1 * max(y))
if(!object@adeg.par$p1d$horizontal && is.null(object@g.args$xlim))
object@g.args$xlim <- c(0, 1.1 * max(y))
if(object@adeg.par$p1d$horizontal)
object@g.args$scales$y$at <- pretty(object@g.args$ylim, n = 5)
else
object@g.args$scales$x$at <- pretty(object@g.args$xlim, n = 5)
assign(nameobj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "C1.hist",
definition = function(object, x, y) {
## Drawing hist
## y is the score
## get some parameters
pscore <- object@adeg.par$p1d
ppoly <- lapply(object@adeg.par$ppolygons, FUN = function(x) {rep(x, length.out = length(x))})
breaks <- object@stats$breaks
heights <- object@stats$heights
## Starts the display
## depends on the parametres horizontal
## reverse and rug.draw are always considered as FALSE
if(pscore$horizontal) {
panel.rect(x = breaks[-length(breaks)], y = 0, height = heights, width = diff(breaks),
col = ppoly$col, alpha = ppoly$alpha, border = ppoly$border, lty = ppoly$lty,
lwd = ppoly$lwd, just = c("left", "bottom"))
} else {
panel.rect(x = 0, y = breaks[-length(breaks)], height = diff(breaks), width = heights,
col = ppoly$col, alpha = ppoly$alpha, border = ppoly$border, lty = ppoly$lty,
lwd = ppoly$lwd, just = c("left", "bottom"))
}
})
s1d.hist <- function(score, breaks = NULL, nclass = round(log2(length(score)) + 1), type = c("count", "density", "percent"), right = TRUE,
facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters
thecall <- .expand.call(match.call())
score <- eval(thecall$score, envir = sys.frame(sys.nframe() + pos))
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if(!inherits(score, "histogram")) {
if(NCOL(score) == 1)
object <- multi.facets.C1(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple scores")
} else {
stop("Facets are not allowed with histogram data")
}
}
## multiple scores
else if(NCOL(score) > 1) {
if(!inherits(score, "histogram"))
object <- multi.score.C1(thecall)
else
stop("Multiple scores are not allowed with histogram data")
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(type = match.arg(type), nclass = nclass, breaks = breaks, right = right))
if(storeData)
tmp_data <- list(score = score, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(score = thecall$score, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "C1.hist", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = match.call())
## preparation
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/S2.corcircle.R 0000644 0001762 0000144 00000011222 14354572613 015310 0 ustar ligges users ##########################################################################
## s.corcircle ##
##########################################################################
setClass(
Class = "S2.corcircle",
contains = "ADEg.S2"
)
setMethod(
f = "initialize",
signature = "S2.corcircle",
definition = function(.Object, data = list(dfxy = NULL, xax = 1, yax = 2, labels = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.S2 initialize
.Object@data$labels <- data$labels
return(.Object)
})
setMethod(
f = "prepare",
signature = "S2.corcircle",
definition = function(object) {
name_obj <- deparse(substitute(object))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
## prepare grid
getgrid <- function(nbgrid = 10) {
cgrid <- signif(2 / nbgrid, 2)
h0 <- c(rev(seq(0, -1, by = -cgrid)), seq(0 + cgrid, 1, by = cgrid)) ## force that 0 is represented by the grid
cgrid <- diff(h0)[1]
coord <- rep(0, length(h0))
for(i in 1:length(h0))
coord[i] <- sqrt(1 - h0[i] * h0[i])
return(list(x0 = c(h0, -coord), x1 = c(h0, coord), y0 = c(-coord, h0), y1 = c(coord, h0), d = cgrid))
}
## change default for some parameters
if(adegtot$pgrid$draw || adegtot$paxes$draw)
object@s.misc$backgrid <- getgrid(adegtot$pgrid$nint)
if(is.null(object@adeg.par$ppoints$cex))
adegtot$ppoints$cex <- 0
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
## never optimized labels for s.corcircle
object@adeg.par$plabels$optim <- FALSE
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "S2.corcircle",
definition = function(object, x, y) {
panel.arrows(x0 = 0, y0 = 0, y1 = y, x1 = x, angle = object@adeg.par$parrows$angle,
length = object@adeg.par$parrows$length, ends = object@adeg.par$parrows$end,
lwd = object@adeg.par$plines$lwd, col = object@adeg.par$plines$col, lty = object@adeg.par$plines$lty)
## labels and boxes
plabels <- object@adeg.par$plabels
pos <- .textpos(x, y, origin = c(0, 0))
if(object@data$storeData)
labels <- object@data$labels
else
labels <- eval(object@data$labels, envir = sys.frame(object@data$frame))
test <- .textsize(labels, plabels)
w <- test$w
h <- test$h
adeg.panel.label(x = x + pos[1, ] * w / 2, y = y + pos[2, ] * h / 2, labels = labels, plabels = plabels)
})
s.corcircle <- function(dfxy, xax = 1, yax = 2, labels = row.names(as.data.frame(dfxy)), fullcircle = TRUE,
facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters (required for multiplot)
thecall <- .expand.call(match.call())
df <- try(as.data.frame(eval(thecall$dfxy, envir = sys.frame(sys.nframe() + pos))), silent = TRUE)
if(inherits(df, "try-error") | is.null(thecall$dfxy)) ## non convenient dfxy argument
stop("non convenient selection for dfxy (can not be converted to dataframe)")
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if((length(xax) == 1 & length(yax) == 1))
object <- multi.facets.S2(thecall, sortparameters$adepar)
else
stop("Facets are not allowed with multiple xax/yax")
}
## multiple axes
else if((length(xax) > 1 | length(yax) > 1)) {
object <- multi.ax.S2(thecall)
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(fullcircle = fullcircle))
if(storeData)
tmp_data <- list(dfxy = dfxy, xax = xax, yax = yax, labels = labels, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(dfxy = thecall$dfxy, xax = xax, yax = yax, labels = thecall$labels, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "S2.corcircle", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = as.call(thecall))
## preparation of the graph
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(! add & plot)
print(object)
invisible(object)
}
adegraphics/R/s.Spatial.R 0000644 0001762 0000144 00000012467 13742303021 014713 0 ustar ligges users s.Spatial <- function(spObj, col = TRUE, nclass = 5, scale = TRUE, plot = TRUE, storeData = TRUE, pos = -1, ...) {
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
sortparameters <- sortparamADEg(...)
adegtot <- adegpar(sortparameters$adepar)
xy.spObj <- coordinates(spObj)[, , drop = FALSE] ## to access 'coordinates' in the 'imports' environment of 'adegraphics'
## different cases (data or not, points or polygons)
## s.value is used for points with numeric data
## s.class is used for points with factor data
## s.label in other cases
nvar <- 0
if(length(grep("DataFrame", class(spObj))) > 0)
nvar <- ncol(spObj)
points.or.poly <- ifelse(length(grep("Poly", class(spObj))) > 0, "poly", "points")
## default values for parameters
defaultpar <- list(pgrid = list(draw = FALSE), porigin = list(include = FALSE),
plegend = list(drawKey = ifelse(nvar == 1, TRUE, FALSE)), psub = list(position = "topleft"))
sortparameters$adepar <- modifyList(defaultpar, sortparameters$adepar, keep.null = TRUE)
## limits management
limsSp <- bbox(spObj)
lim.global <- setlimits2D(minX = limsSp[1, 1], maxX = limsSp[1, 2], minY = limsSp[2, 1], maxY = limsSp[2, 2], includeOr = FALSE)
if(is.null(sortparameters$g.args$xlim))
sortparameters$g.args$xlim <- lim.global$xlim
if(is.null(sortparameters$g.args$ylim))
sortparameters$g.args$ylim <- lim.global$ylim
if(nvar == 0){
if(is.logical(col)){
if(col)
colnew <- adegtot$pSp$col
else
colnew <- "transparent" ## col == FALSE
} else {
colnew <- col
}
sortparameters$adepar$pSp$col <- colnew
sortparameters$adepar$ppoint$cex <- 0
## create map
if(points.or.poly == "points")
object <- do.call("s.label", c(list(dfxy = xy.spObj, plot = FALSE, storeData = storeData, pos = pos - 2),
sortparameters$adepar, sortparameters$trellis, sortparameters$g.args, sortparameters$rest))
else
object <- do.call("s.label", c(list(dfxy = xy.spObj, Sp = substitute(spObj), plot = FALSE, storeData = storeData, pos = pos - 2),
sortparameters$adepar, sortparameters$trellis, sortparameters$g.args, sortparameters$rest))
} else if(nvar > 0) {
listGraph <- list()
for(i in 1:nvar) {
defaultpar <- list(psub = list(text = names(spObj)[i]), plabels = list(cex = 0))
adepar.i <- modifyList(defaultpar, sortparameters$adepar, keep.null = TRUE)
if(points.or.poly == "points" & is.numeric(spObj@data[, i])){
## points and numeric -> s.value
if(is.logical(col))
colnew <- NULL ## default in s.value
else colnew <- col
listGraph <- c(listGraph, do.call("s.value", c(list(dfxy = xy.spObj, z = if(scale) scale (spObj@data[, i]) else spObj@data[, i], plot = FALSE,
col = colnew, storeData = storeData, pos = pos - 2), adepar.i, sortparameters$trellis, sortparameters$g.args, sortparameters$rest)))
} else if(points.or.poly == "points" & is.factor(spObj@data[, i])) {
if(is.logical(col))
colnew <- adegtot$ppalette$quali(nlevels(as.factor(spObj@data[, i])))
adepar.i <- modifyList(list(ppoints = list(cex = 2)), adepar.i , keep.null = TRUE)
listGraph <- c(listGraph, do.call("s.class", c(list(dfxy = xy.spObj, starSize = 0, ellipseSize = 0, fac = spObj@data[, i], plot = FALSE,
col = colnew, storeData = storeData, pos = pos - 2), adepar.i, sortparameters$trellis, sortparameters$g.args, sortparameters$rest)))
} else {
if(is.logical(col)) {
if(col) {
if(is.numeric(spObj@data[, i])) {
nclasspretty <- length(pretty(spObj@data[, i], nclass)) - 1
nclasspretty <- length(pretty(spObj@data[, i], nclasspretty)) - 1 ## repeated in order to have always the same number of class
colnew <- adegtot$ppalette$quanti(nclasspretty)
} else
colnew <- adegtot$ppalette$quali(nlevels(as.factor(spObj@data[, i])))[as.factor(spObj@data[, i])]
}
} else {
colnew <- col
}
adepar.i$pSp$col <- colnew
adepar.i$ppoint$cex <- 0
## create map
listGraph <- c(listGraph, do.call("s.label", c(list(dfxy = xy.spObj, Sp = substitute(spObj[,i]), plot = FALSE, storeData = storeData, pos = pos - 2), adepar.i, sortparameters$trellis, sortparameters$g.args, sortparameters$rest)))
}
}
if(nvar == 1)
object <- listGraph[[1]]
else {
names(listGraph) <- names(spObj)
posmatrix <- layout2position(.n2mfrow(nvar), ng = nvar)
object <- new(Class = "ADEgS", ADEglist = listGraph, positions = posmatrix, add = matrix(0, ncol = nvar, nrow = nvar), Call = match.call())
}
}
if(plot)
print(object)
invisible(object)
}
adegraphics/R/S2.match.R 0000644 0001762 0000144 00000012546 14354572056 014452 0 ustar ligges users #########################################################
### s.match ##
#########################################################
## in S2.match, the two data set are combined (using rbind) and kept as the same one...
## We know that the two data sets have the same row number, so we can easily retrieve and distinguish the two set (the first (nrow/2) rows are from dfxy1 the rest from dfxy2
setClass(
Class = "S2.match",
contains = "ADEg.S2"
)
setMethod(
f = "initialize",
signature = "S2.match",
definition = function(.Object, data = list(dfxy = NULL, xax = 1, yax = 2, labels = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.S2 initialize
.Object@data$labels <- data$labels
return(.Object)
})
setMethod(
f = "prepare",
signature = "S2.match",
definition = function(object) {
name_obj <- deparse(substitute(object))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
## change default for some parameters
if(!object@g.args$arrows)
adegtot$parrows$angle <- 0
else
if(is.null(object@adeg.par$parrows$angle) || (object@adeg.par$parrows$angle == 0))
adegtot$parrows$angle <- oldparamadeg$parrows$angle
if(is.null(object@adeg.par$porigin$include) & (any(names(object@g.args) %in% c("Sp", "nbobject"))))
adegtot$porigin$include <- FALSE
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
## never optimized labels for s.match
object@adeg.par$plabels$optim <- FALSE
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "S2.match",
definition = function(object, x, y) {
n <- length(x) / 2
if(length(x) %% 2) ## x non multiple de 2
stop("error in spanel, not finding two datasets with equal row numbers please see with dev")
## arrows from dfxy to dfxy2
panel.arrows(x0 = x[1:n], y0 = y[1:n] , y1 = y[n + 1:(2 * n)], x1 = x[n + 1:(2 * n)], angle = object@adeg.par$parrows$angle,
length = object@adeg.par$parrows$length, ends = object@adeg.par$parrows$end,
lwd = object@adeg.par$plines$lwd, col = object@adeg.par$plines$col, lty = object@adeg.par$plines$lty)
do.call("panel.points", c(list(x = x[1:n], y = y[1:n]), object@adeg.par$ppoints))
## dessins labels
if(any(object@adeg.par$plabels$cex > 0)) {
xlab <- ((x[1:n] + x[(n + 1):(2 * n)]) / 2)
ylab <- ((y[1:n] + y[(n + 1):(2 * n)]) / 2)
if(object@data$storeData)
labels <- object@data$labels
else
labels <- eval(object@data$labels, envir = sys.frame(object@data$frame))
adeg.panel.label(xlab, ylab ,labels, object@adeg.par$plabels)
}
})
## if arrows= TRUE arrows are plotted, otherwise only the segments are drawn
s.match <- function(dfxy1, dfxy2, xax = 1, yax = 2, labels = row.names(as.data.frame(dfxy1)), arrows = TRUE, facets = NULL, plot = TRUE,
storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters
thecall <- .expand.call(match.call())
data1 <- try(as.data.frame(eval(thecall$dfxy1, envir = sys.frame(sys.nframe() + pos))), silent = TRUE)
data2 <- try(as.data.frame(eval(thecall$dfxy2, envir = sys.frame(sys.nframe() + pos))), silent = TRUE)
if(inherits(data1, "try-error") || inherits(data2, "try-error") || is.null(thecall$dfxy1) || is.null(thecall$dfxy2)) ## wrong conversion
stop("non convenient selection for dfxy1 or dfxy2 (can not be converted to dataframe)")
if(any(is.na(pmatch(colnames(data1), colnames(data2)))))
stop("column names should be identical")
if(any(is.na(data1)))
stop("NA in first dataframe") ## TODO
if(any(is.na(data2)))
stop("NA in second dataframe") ## TODO
if(nrow(data1) != nrow(data2))
stop("non equal row numbers")
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if((length(xax) == 1 & length(yax) == 1))
object <- multi.facets.S2(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple xax/yax")
}
## multiple axes
else if((length(xax) > 1 | length(yax) > 1)) {
object <- multi.ax.S2(thecall)
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(arrows = arrows))
if(storeData)
tmp_data <- list(dfxy = rbind(dfxy1, dfxy2), xax = xax, yax = yax, labels = labels, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(dfxy = call("rbind", thecall$dfxy1, thecall$dfxy2), xax = xax, yax = yax, labels = thecall$labels, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "S2.match", data = tmp_data , adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = as.call(thecall))
## preparation
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/ade4-plot.R 0000644 0001762 0000144 00000315552 14520213466 014657 0 ustar ligges users "screeplot.dudi" <- function(x, col.kept = "grey", col = "white", pos = -1, plot = TRUE, ...) {
if(!inherits(x, "dudi"))
stop("Object of class 'dudi' expected")
## prepare
nf <- 1:x$nf
col <- rep(col, length(x$eig))
col[nf] <- col.kept
## default values for parameters
sortparameters <- sortparamADEg(...)
params <- list()
params$adepar <- list(ppolygons = list(col = col), porigin = list(origin = c(0, 0)), pgrid = list(draw = FALSE), p1d = list(horizontal = FALSE), paxes = list(draw = TRUE, x = list(draw = FALSE)))
params$g.args <- list(main = deparse(substitute(x)), xlab = "Axis", ylab = "Inertia", ylim = c(min(0, min(x$eig)), max(x$eig) * 1.1))
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## ADEg creation
object <- do.call("s1d.barchart", c(list(score = substitute(x$eig), pos = pos - 2, plot = FALSE), sortparameters$adepar, sortparameters$trellis, sortparameters$g.args))
object@Call <- match.call()
if(plot)
print(object)
invisible(object)
}
"biplot.dudi" <- function(x, pos = -1, plot = TRUE, ...) {
if(!inherits(x, "dudi"))
stop("Object of class 'dudi' expected")
object <- do.call("scatter", c(list(substitute(x), pos = pos - 3, plot = FALSE, ...)))
object@Call <- match.call()
if(plot)
print(object)
invisible(object)
}
"plot.acm" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "dudi"))
stop("Object of class 'dudi' expected")
if(!inherits(x, "acm"))
stop("Object of class 'acm' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
## prepare
oritab <- as.list(x$call)[[2]]
## parameter management
sortparameters <- sortparamADEg(...)
params <- list()
params$g.args <- list(starSize = 0)
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
object <- do.call("s.class", c(list(dfxy = substitute(x$li), fac = oritab, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$adepar, sortparameters$trellis, sortparameters$g.args, sortparameters$rest))
object@Call <- match.call()
if(plot)
print(object)
invisible(object)
}
"plot.fca" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "dudi"))
stop("Object of class 'dudi' expected")
if(!inherits(x, "fca"))
stop("Object of class 'fca' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
## prepare
oritab <- as.list(x$call)[[2]]
evTab <- eval.parent(oritab)
indica <- factor(rep(names(x$blo), x$blo))
ng <- length(levels(indica))
## parameter management
graphsnames <- as.character(levels(indica))
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
params <- list()
params <- lapply(1:length(graphsnames), function(i) {params[[i]] <- list(starSize = 0.5, ellipseSize = 0, plabels = list(cex = 1.25), psub = list(text = graphsnames[i]))})
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
l <- list()
l <- sapply(1:length(levels(indica)), function(i) {do.call("s.distri", c(list(dfxy = substitute(x$l1, env = sys.frame(-3)), dfdistri = call("[", oritab, call(":", 1, nrow(evTab)), which(indica == levels(indica)[i])), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[i]]))})
## ADEgS creation
object <- new(Class = "ADEgS", ADEglist = l, positions = layout2position(.n2mfrow(ng), ng = ng), add = matrix(0, ncol = ng, nrow = ng), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.coinertia" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "coinertia"))
stop("Object of class 'coinertia' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
## sort parameters for each graph
graphsnames <- c("Xax", "Yax", "eig", "XYmatch", "Yloadings", "Xloadings")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## default values for parameters
params <- list()
params[[1]] <- list(psub = list(text = "Unconstrained axes (X)"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
params[[2]] <- list(psub = list(text = "Unconstrained axes (Y)"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
params[[3]] <- list(psub = list(text = "Eigenvalues"))
params[[4]] <- list(psub = list(text = "Row scores (X -> Y)"))
params[[5]] <- list(psub = list(text = "Y loadings"), plabels = list(cex = 1.25))
params[[6]] <- list(psub = list(text = "X loadings"), plabels = list(cex = 1.25))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## Creation of each individual ADEg
g1 <- do.call("s.corcircle", c(list(dfxy = substitute(x$aX), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g2 <- do.call("s.corcircle", c(list(dfxy = substitute(x$aY), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g4 <- do.call("s.match", c(list(dfxy1 = substitute(x$mX), dfxy2 = substitute(x$mY), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
g5 <- do.call("s.arrow", c(list(dfxy = substitute(x$l1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[5]]))
g6 <- do.call("s.arrow", c(list(dfxy = substitute(x$c1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[6]]))
## ADEgS creation
lay <- matrix(c(1, 2, 3, 4, 4, 5, 4, 4, 6), 3, 3)
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4, g5, g6), positions = layout2position(lay), add = matrix(0, ncol = 6, nrow = 6), Call = match.call() )
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.pcaiv" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "pcaiv"))
stop("Object of class 'pcaiv' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
## sort parameters for each graph
graphsnames <- c("Xloadings", "Xcor", "eig", "XYmatch", "Yax", "Ycol")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## default values for parameters
params <- list()
params[[1]] <- list(psub = list(text = "X loadings"), plabels = list(cex = 1.25))
params[[2]] <- list(psub = list(text = "X correlation"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
params[[3]] <- list(psub = list(text = "Eigenvalues"))
params[[4]] <- list(psub = list(text = "Predictions (X) -> Scores (Y)"))
params[[5]] <- list(psub = list(text = "Unconstrained axes (Y)"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
params[[6]] <- list(psub = list(text = "Y columns"), plabels = list(cex = 1.25))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## Creation of each individual ADEg
g1 <- do.call("s.arrow", c(list(dfxy = substitute(na.omit(x$fa)), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g2 <- do.call("s.corcircle", c(list(dfxy = substitute(na.omit(x$cor)), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g4 <- do.call("s.match", c(list(dfxy1 = substitute(x$li), dfxy2 = substitute(x$ls), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]] ))
g5 <- do.call("s.corcircle", c(list(dfxy = substitute(x$as), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[5]]))
g6 <- do.call("s.arrow", c(list(dfxy = substitute(x$c1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[6]]))
## ADEgS creation
lay <- matrix(c(1, 2, 3, 4, 4, 5, 4, 4, 6), 3, 3)
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4, g5, g6), positions = layout2position(lay), add = matrix(0, ncol = 6, nrow = 6), Call = match.call() )
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.betcoi" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "betcoi"))
stop("Object of class 'betcoi' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
appel <- as.list(x$call)
fac <- eval.parent(appel$fac)
## sort parameters for each graph
graphsnames <- c("Xax", "Yax", "eig", "XYmatch", "Yloadings", "Xloadings")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames, nbsubgraphs = c(1, 1, 1, 3, 1, 1))
## compute limits for the ADEgS 'XYmatch' (two s.class and one s.match)
mat <- rbind(x$msX, x$msY, x$mX)
minmat <- apply(mat, 2, min)
maxmat <- apply(mat, 2, max)
limdefault <- setlimits2D(minmat[1], maxmat[1], minmat[2], maxmat[2], origin = c(0, 0), includeOr = TRUE)
## default values for parameters
params <- list()
params[[1]] <- list(psub = list(text = "Unconstrained axes (X)"), plabels = list(cex = 1.25))
params[[2]] <- list(psub = list(text = "Unconstrained axes (Y)"), plabels = list(cex = 1.25))
params[[3]] <- list(psub = list(text = "Eigenvalues"))
params[[4]] <- list()
params[[4]]$l1 <- list(psub = list(text = "Row scores (X -> Y)"), xlim = limdefault$xlim, ylim = limdefault$ylim, chullSize = 1, ppoints = list(pch = 16, cex = 0.5), plines = list(lwd = 1), plabels = list(alpha = 0, boxes = list(draw = FALSE)), ppolygon = list(lwd = 0.5, alpha = 0.2), pellipses = list(alpha = 0, axes = list(draw = FALSE)), col = adegpar()$ppalette$quali(nlevels(fac)))
params[[4]]$l2 <- list(xlim = limdefault$xlim, ylim = limdefault$ylim, chullSize = 1, ppoints = list(pch = 15, cex = 0.5), plines = list(lwd = 1), plabels = list(alpha = 0, boxes = list(draw = FALSE)), ppolygon = list(lwd = 0.5, alpha = 0.2), pellipses = list(alpha = 0.0, axes = list(draw = FALSE)), col = adegpar()$ppalette$quali(nlevels(fac)))
params[[4]]$l3 <- list(xlim = limdefault$xlim, ylim = limdefault$ylim, ppoints = list(cex = 0.7), plines = list(lwd = 2), plabels = list(alpha = 1, boxes = list(draw = TRUE), cex = 1.25))
params[[5]] <- list(psub = list(text = "Y loadings"), plabels = list(cex = 1.25))
params[[6]] <- list(psub = list(text = "X loadings"), plabels = list(cex = 1.25))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g1 <- do.call("s.arrow", c(list(dfxy = substitute(x$aX), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g2 <- do.call("s.arrow", c(list(dfxy = substitute(x$aY), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g41 <- do.call("s.class", c(list(dfxy = substitute(x$msX), fac = appel$fac, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]][[1]]))
g42 <- do.call("s.class", c(list(dfxy = substitute(x$msY), fac = appel$fac, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]][[2]]))
g43 <- do.call("s.match", c(list(dfxy1 = substitute(x$mX), dfxy2 = substitute(x$mY), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]][[3]]))
g4 <- do.call("superpose", list(g41, g42))
g4@Call <- call("superpose", g41@Call, g42@Call)
g4 <- do.call("superpose", list(g4, g43))
g4@Call <- call("superpose", g4@Call, g43@Call)
g5 <- do.call("s.arrow", c(list(dfxy = substitute(x$l1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[5]]))
g6 <- do.call("s.arrow", c(list(dfxy = substitute(x$c1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[6]]))
## ADEgS creation
lay <- matrix(c(1, 2, 3, 4, 4, 5, 4, 4, 6), 3, 3)
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4, g5, g6), positions = layout2position(lay), add = matrix(0, ncol = 6, nrow = 6), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.betrlq" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "betrlq"))
stop("Object of class 'betrlq' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
appel <- as.list(x$call)
## sort parameters for each graph
graphsnames <- c("Rrow", "Qrow", "Rax", "Rloadings", "Qloadings", "Qax", "eig")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## default values for parameters
params <- list()
params[[1]] <- list(psub = list(text = "R row scores and classes"), plabels = list(cex = 1.25))
params[[2]] <- list(psub = list(text = "Q row scores"), plabels = list(cex = 1.25))
params[[3]] <- list(psub = list(text = "Unconstrained axes (R)"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
params[[4]] <- list(psub = list(text = "R loadings"), plabels = list(cex = 1.25))
params[[5]] <- list(psub = list(text = "Q loadings"), plabels = list(cex = 1.25))
params[[6]] <- list(psub = list(text = "Unconstrained axes (Q)"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
params[[7]] <- list(psub = list(text = "Eigenvalues"))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g1 <- do.call("s.class", c(list(dfxy = substitute(x$lsR), fac = appel$fac, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g2 <- do.call("s.label", c(list(dfxy = substitute(x$lQ), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("s.corcircle", c(list(dfxy = substitute(x$aR), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g4 <- do.call("s.arrow", c(list(dfxy = substitute(x$l1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
g5 <- do.call("s.arrow", c(list(dfxy = substitute(x$c1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[6]]))
g6 <- do.call("s.corcircle", c(list(dfxy = substitute(x$aQ), xax, yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[5]]))
g7 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[7]]))
## ADEgS creation
lay <- matrix(c(1, 1, 3, 1, 1, 4, 2, 2, 5, 2, 2, 6, 0, 0, 7), 3, 5)
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4, g5, g6, g7), positions = layout2position(lay), add = matrix(0, ncol = 7, nrow = 7), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.between" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "between"))
stop("Object of class 'between' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
appel <- as.list(x$call)
## sort parameters for each graph
graphsnames <- c("loadings", "col", "eig", "row", "Xax", "class")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## default values for parameters
params <- list()
params[[1]] <- list(psub = list(text = "Loadings"), plabels = list(cex = 1.25))
params[[2]] <- list(psub = list(text = "Columns"), plabels = list(cex = 1.25))
params[[3]] <- list(psub = list(text = "Eigenvalues"))
params[[4]] <- list(psub = list(text = "Row scores and classes"), plabels = list(cex = 1.25))
params[[5]] <- list(psub = list(text = "Unconstrained axes"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
params[[6]] <- list(psub = list(text = "Classes"), plabels = list(cex = 1.25))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g1 <- do.call("s.arrow", c(list(dfxy = substitute(x$c1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g2 <- do.call("s.arrow", c(list(dfxy = substitute(x$co), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g4 <- do.call("s.class", c(list(dfxy = substitute(x$ls), wt = call("$", appel$x, "lw"), fac = appel$fac, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
g5 <- do.call("s.corcircle", c(list(dfxy = substitute(x$as), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[5]]))
g6 <- do.call("s.label", c(list(dfxy = substitute(x$li), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[6]]))
## ADEgS creation
lay <- matrix(c(1, 2, 3, 4, 4, 5, 4, 4, 6), 3, 3)
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4, g5, g6), positions = layout2position(lay), add = matrix(0, ncol = 6, nrow = 6), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.discrimin" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "discrimin"))
stop("Object of class 'discrimin' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
appel <- as.list(x$call)
## sort parameters for each graph
graphsnames <- c("loadings", "col", "eig", "row", "Xax", "class")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## default values for parameters
params <- list()
params[[1]] <- list(psub = list(text = "Loadings"), plabels = list(cex = 1.25))
params[[2]] <- list(psub = list(text = "Columns"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
params[[3]] <- list(psub = list(text = "Eigenvalues"))
params[[4]] <- list(psub = list(text = "Row scores and classes"), plabels = list(cex = 1.25))
params[[5]] <- list(psub = list(text = "Unconstrained axes"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
params[[6]] <- list(psub = list(text = "Classes scores"), plabels = list(cex = 1.25))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g1 <- do.call("s.arrow", c(list(dfxy = substitute(x$fa), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g2 <- do.call("s.corcircle", c(list(dfxy = substitute(x$va), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g4 <- do.call("s.class", c(list(dfxy = substitute(x$li), fac = appel$fac, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
g5 <- do.call("s.corcircle", c(list(dfxy = substitute(x$cp), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[5]]))
g6 <- do.call("s.label", c(list(dfxy = substitute(x$gc), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[6]]))
## ADEgS creation
lay <- matrix(c(1, 2, 3, 4, 4, 5, 4, 4, 6), 3, 3)
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4, g5, g6), positions = layout2position(lay), add = matrix(0, ncol = 6, nrow = 6), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.within" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "within"))
stop("Object of class 'within' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
appel <- as.list(x$call)
## sort parameters for each graph
graphsnames <- c("loadings", "col", "eig", "row", "Xax", "ccrow")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## default values for parameters
params <- list()
params[[1]] <- list(psub = list(text = "Loadings"), plabels = list(cex = 1.25))
params[[2]] <- list(psub = list(text = "Columns"), plabels = list(cex = 1.25))
params[[3]] <- list(psub = list(text = "Eigenvalues"))
params[[4]] <- list(psub = list(text = "Row scores and classes"), plabels = list(cex = 1.25))
params[[5]] <- list(psub = list(text = "Unconstrained axes"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
params[[6]] <- list(psub = list(text = "Row scores (common centring)"), pellipses = list(axes = list(draw = FALSE)), plines = list(lwd = 0), plabels = list(alpha = 0, boxes = list(draw = FALSE), cex = 1.25))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g1 <- do.call("s.arrow", c(list(dfxy = substitute(x$c1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g2 <- do.call("s.arrow", c(list(dfxy = substitute(x$co), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g4 <- do.call("s.class", c(list(dfxy = substitute(x$ls), wt = substitute(x$lw), fac = appel$fac, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
g5 <- do.call("s.corcircle", c(list(dfxy = substitute(x$as), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[5]]))
g6 <- do.call("s.class", c(list(dfxy = substitute(x$li), wt = substitute(x$lw), fac = appel$fac, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[6]]))
## ADEgS creation
lay <- matrix(c(1, 2, 3, 4, 4, 5, 4, 4, 6), 3, 3)
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4, g5, g6), positions = layout2position(lay), add = matrix(0, ncol = 6, nrow = 6), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.witcoi" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "witcoi"))
stop("Object of class 'witcoi' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
appel <- as.list(x$call)
fac <- eval.parent(appel$fac)
## sort parameters for each graph
graphsnames <- c("Xax", "Yax", "eig", "XYmatch", "Yloadings", "Xloadings")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames, nbsubgraphs = c(1, 1, 1, 3, 1, 1))
## compute limits for the ADEgS (two s.class and one s.match)
mat <- rbind(x$msX, x$msY, x$mX)
minmat <- apply(mat, 2, min)
maxmat <- apply(mat, 2, max)
limdefault <- setlimits2D(minmat[1], maxmat[1], minmat[2], maxmat[2], origin = c(0, 0), includeOr = TRUE)
## default values for parameters
params <- list()
params[[1]] <- list(psub = list(text = "Unconstrained axes (X)"), plabels = list(cex = 1.25))
params[[2]] <- list(psub = list(text = "Unconstrained axes (Y)"), plabels = list(cex = 1.25))
params[[3]] <- list(psub = list(text = "Eigenvalues"))
params[[4]] <- list()
params[[4]]$l1 <- list(psub = list(text = "Row scores (X -> Y)"), xlim = limdefault$xlim, ylim = limdefault$ylim, chullSize = 1, ppoints = list(pch = 16, cex = 0.5), plabels = list(alpha = 0, boxes = list(draw = FALSE)), ppolygon = list(lwd = 0.5, alpha = 0.2), pellipses = list(alpha = 0.0, axes = list(draw = FALSE)), col = adegpar()$ppalette$quali(nlevels(fac)))
params[[4]]$l2 <- list(xlim = limdefault$xlim, ylim = limdefault$ylim, chullSize = 1, ppoints = list(pch = 15, cex = 0.5), plabels = list(alpha = 0, boxes = list(draw = FALSE)), ppolygon = list(lwd = 0.5, alpha = 0.2), pellipses = list(alpha = 0.0, axes = list(draw = FALSE)), col = adegpar()$ppalette$quali(nlevels(fac)))
params[[4]]$l3 <- list(xlim = limdefault$xlim, ylim = limdefault$ylim, ppoints = list(cex = 0.7), plines = list(lwd = 2), plabels = list(alpha = 1, boxes = list(draw = TRUE), cex = 1.25))
params[[5]] <- list(psub = list(text = "Y loadings"), plabels = list(cex = 1.25))
params[[6]] <- list(psub = list(text = "X loadings"), plabels = list(cex = 1.25))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g1 <- do.call("s.arrow", c(list(dfxy = substitute(x$aX), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g2 <- do.call("s.arrow", c(list(dfxy = substitute(x$aY), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g41 <- do.call("s.class", c(list(dfxy = substitute(x$msX), fac = appel$fac, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]][[1]]))
g42 <- do.call("s.class", c(list(dfxy = substitute(x$msY), fac = appel$fac, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]][[2]]))
g43 <- do.call("s.match", c(list(dfxy1 = g41@stats$means, dfxy2 = g42@stats$means, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]][[3]]))
g4 <- do.call("superpose", list(g41, g42))
g4@Call <- call("superpose", g41@Call, g42@Call)
g4 <- do.call("superpose", list(g4, g43))
g4@Call <- call("superpose", g4@Call, g43@Call)
g5 <- do.call("s.arrow", c(list(dfxy = substitute(x$l1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[5]]))
g6 <- do.call("s.arrow", c(list(dfxy = substitute(x$c1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[6]]))
## ADEgS creation
lay <- matrix(c(1, 2, 3, 4, 4, 5, 4, 4, 6), 3, 3)
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4, g5, g6), positions = layout2position(lay), add = matrix(0, ncol = 6, nrow = 6), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.witrlq" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "witrlq"))
stop("Object of class 'witrlq' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
appel <- as.list(x$call)
## sort parameters for each graph
graphsnames <- c("Rrow", "Qrow", "Rax", "Rloadings", "Qloadings", "Qax", "eig")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## default values for parameters
params <- list()
params[[1]] <- list(psub = list(text = "R row scores and classes"), plabels = list(cex = 1.25))
params[[2]] <- list(psub = list(text = "Q row scores"), plabels = list(cex = 1.25))
params[[3]] <- list(psub = list(text = "Unconstrained axes (R)"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
params[[4]] <- list(psub = list(text = "R loadings"), plabels = list(cex = 1.25))
params[[5]] <- list(psub = list(text = "Q loadings"), plabels = list(cex = 1.25))
params[[6]] <- list(psub = list(text = "Unconstrained axes (Q)"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
params[[7]] <- list(psub = list(text = "Eigenvalues"))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g1 <- do.call("s.class", c(list(dfxy = substitute(x$lsR), fac = appel$fac, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g2 <- do.call("s.label", c(list(dfxy = substitute(x$lQ), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("s.corcircle", c(list(dfxy = substitute(x$aR), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g4 <- do.call("s.arrow", c(list(dfxy = substitute(x$l1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
g5 <- do.call("s.arrow", c(list(dfxy = substitute(x$c1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[6]]))
g6 <- do.call("s.corcircle", c(list(dfxy = substitute(x$aQ), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[5]]))
g7 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[7]]))
## ADEgS creation
lay <- matrix(c(1, 1, 3, 1, 1, 4, 2, 2, 5, 2, 2, 6, 0, 0, 7), 3, 5)
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4, g5, g6, g7), positions = layout2position(lay), add = matrix(0, ncol = 7, nrow = 7), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.dpcoa" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "dpcoa"))
stop("Object of class 'dpcoa' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
appel <- as.list(x$call)
dfX <- appel$df
## sort parameters for each graph
graphsnames <- c("axes", "categories", "categcoll", "collections")
vec <- c(2, 1, 1, 1)
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames, nbsubgraphs = vec)
## default values for parameters
params <- list()
params[[1]] <- list()
params[[1]]$l1 <- list(psub = list(text = "Principal axes", position = "topleft"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
params[[1]]$l2 <- list(psub = list(text = "Eigenvalues"), pbackground = list(box = TRUE))
params[[2]] <- list(psub = list(text = "Categories"), plabels = list(cex = 1.25))
params[[3]] <- list(psub = list(text = "Categories and collections"), ppoints = list(pch = 16, cex = 1.2), plines = list(col = "transparent"), pellipses = list(axes = list(draw = FALSE)), ellipseSize = 1, plabels = list(cex = 1.25))
if(!is.null(x$RaoDiv))
params[[4]] <- list(psub = list(text = "Rao Divcs", position = "topleft"))
else
params[[4]] <- list(psub = list(text = "Collections", position = "bottomleft"))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g11 <- do.call("s.corcircle", c(list(dfxy = substitute(x$c1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]][[1]]))
g12 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]][[2]]))
g1 <- do.call("insert", list(g12@Call, g11@Call, posi = "bottomleft", plot = FALSE, ratio = 0.25, inset = 0))
g2 <- do.call("s.label", c(list(dfxy = substitute(x$dls), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("s.distri", c(list(dfxy = substitute(x$dls), dfdistri = substitute(t(dfX)), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
if(!is.null(x$RaoDiv))
g4 <- do.call("s.value", c(list(dfxy = substitute(x$li), z = substitute(x$RaoDiv), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
else
g4 <- do.call("s.label", c(list(dfxy = substitute(x$li), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
## ADEgS creation
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4), positions = layout2position(matrix(c(1, 2, 3, 4), 2, 2)), add = matrix(0, ncol = 4, nrow = 4), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.betdpcoa" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!(inherits(x, "betdpcoa") | inherits(x, "betwitdpcoa")))
stop("Object of class 'betdpcoa' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
appel <- as.list(x$call)
dfX <- as.list(eval.parent(appel$x)$call)$df
## sort parameters for each graph
graphsnames <- c("axes", "class", "categories", "Xax")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames, nbsubgraphs = c(2, 1, 1, 1))
## default values for parameters
params <- list()
params[[1]] <- list()
params[[1]]$l1 <- list(psub = list(text = "Principal axes", position = "topleft"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
params[[1]]$l2 <- list(psub = list(text = "Eigenvalues"), pbackground = list(box = TRUE))
params[[2]] <- list(psub = list(text = "Classes and collections"), plabels = list(cex = 1.25))
params[[3]] <- list(psub = list(text = "Categories and collections"), ppoints = list(pch = 16, cex = 1.2), plines = list(col = "transparent"), pellipses = list(axes = list(draw = FALSE)), ellipseSize = 1, plabels = list(cex = 1.25))
params[[4]] <- list(psub = list(text = "Unconstrained axes"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g11 <- do.call("s.corcircle", c(list(dfxy = substitute(x$c1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]][[1]]))
g12 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]][[2]]))
g1 <- do.call("insert", list(g12@Call, g11@Call, posi = "bottomleft", plot = FALSE, ratio = 0.25, inset = 0))
g2 <- do.call("s.class", c(list(dfxy = substitute(x$ls), fac = appel$fac, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("s.distri", c(list(dfxy = substitute(x$dls), dfdistri = substitute(t(dfX)), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g4 <- do.call("s.corcircle", c(list(dfxy = substitute(x$as), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4), positions = layout2position(matrix(c(1, 2, 3, 4), 2, 2)), add = matrix(0, ncol = 4, nrow = 4), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.witdpcoa" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "witdpcoa"))
stop("Object of class 'witdpcoa' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
appel <- as.list(x$call)
dfX <- as.list(eval.parent(appel$x)$call)$df
## sort parameters for each graph
graphsnames <- c("axes", "class", "categories", "Xax")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames, nbsubgraphs = c(2, 1, 1, 1))
## default values for parameters
params <- list()
params[[1]] <- list()
params[[1]]$l1 <- list(psub = list(text = "Principal axes", position = "topleft"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
params[[1]]$l2 <- list(psub = list(text = "Eigenvalues"), pbackground = list(box = TRUE))
params[[2]] <- list(psub = list(text = "Classes and collections"), plabels = list(cex = 1.25))
params[[3]] <- list(psub = list(text = "Categories and collections"), ppoints = list(pch = 16, cex = 1.2), plines = list(col = "transparent"), pellipses = list(axes = list(draw = FALSE)), ellipseSize = 1, plabels = list(cex = 1.25))
params[[4]] <- list(psub = list(text = "Unconstrained axes"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g11 <- do.call("s.corcircle", c(list(dfxy = substitute(x$c1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]][[1]]))
g12 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]][[2]]))
g1 <- do.call("insert", list(g12@Call, g11@Call, posi = "bottomleft", plot = FALSE, ratio = 0.25, inset = 0))
g2 <- do.call("s.class", c(list(dfxy = substitute(x$ls), fac = appel$fac, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("s.distri", c(list(dfxy = substitute(x$dls), dfdistri = substitute(t(dfX)), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g4 <- do.call("s.corcircle", c(list(dfxy = substitute(x$as), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4), positions = layout2position(matrix(c(1, 2, 3, 4), 2, 2)), add = matrix(0, ncol = 4, nrow = 4), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.betwitdpcoa" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "betwitdpcoa"))
stop("Object of class 'betwitdpcoa' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
appel <- as.list(x$call)
dfX <- as.list(eval.parent(appel$x)$call)$df
## sort parameters for each graph
graphsnames <- c("axes", "class", "categories", "Xax")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames, nbsubgraphs = c(2, 1, 1, 1))
## default values for parameters
params <- list()
params[[1]] <- list()
params[[1]]$l1 <- list(psub = list(text = "Principal axes", position = "topleft"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
params[[1]]$l2 <- list(psub = list(text = "Eigenvalues"), pbackground = list(box = TRUE))
params[[2]] <- list(psub = list(text = "Classes and collections"), plabels = list(cex = 1.25))
params[[3]] <- list(psub = list(text = "Categories and collections"), ppoints = list(pch = 16, cex = 1.2), plines = list(col = "transparent"), pellipses = list(axes = list(draw = FALSE)), ellipseSize = 1, plabels = list(cex = 1.25))
params[[4]] <- list(psub = list(text = "Unconstrained axes"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g11 <- do.call("s.corcircle", c(list(dfxy = substitute(x$c1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]][[1]]))
g12 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]][[2]]))
g1 <- do.call("insert", list(g12@Call, g11@Call, posi = "bottomleft", plot = FALSE, ratio = 0.25, inset = 0))
g2 <- do.call("s.class", c(list(dfxy = substitute(x$ls), fac = appel$fac, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("s.distri", c(list(dfxy = substitute(x$dls), dfdistri = substitute(t(dfX)), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g4 <- do.call("s.corcircle", c(list(dfxy = substitute(x$as), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4), positions = layout2position(matrix(c(1, 2, 3, 4), 2, 2)), add = matrix(0, ncol = 4, nrow = 4), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.mcoa" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "mcoa"))
stop("Object of class 'mcoa' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
## prepare - TODO find better Call for rownames and colnames
coolig <- call("as.data.frame", call("matrix", call("kronecker", rep(1, nrow(x$cov2)), substitute(as.matrix(x$SynVar))), nrow = nrow(x$Tl1), ncol = ncol(x$Tl1), dimnames = list(rownames(x$Tl1), colnames(x$Tl1))))
## sort parameters for each graph
graphsnames <- c("row", "axes", "col", "pseudoeig")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames, nbsubgraphs = c(2, 2, 1, 1))
## default values for parameters
params <- list()
params[[1]] <- list()
params[[1]]$l1 <- list(psub = list(text = "Rows"), parrows = list(angle = 0), plabels = list(alpha = 0, boxes = list(draw = FALSE)))
params[[1]]$l2 <- list(plabels = list(cex = 1.25))
params[[2]] <- list()
params[[2]]$l1 <- list(psub = list(text = "Axes (separate analyses)", position = "topleft"), pbackground = list(box = FALSE), fullcircle = FALSE, plabels = list(cex = 1.25))
params[[2]]$l2 <- list(psub = list(text = "Eigenvalues"), pbackground = list(box = TRUE))
params[[3]] <- list(psub = list(text = "Columns"), plabels = list(cex = 1.25))
params[[4]] <- list(porigin = list(include = FALSE), paxes = list(aspectratio = "fill", draw = TRUE), main = "Pseudo eigenvalues", xlab = "cov21", ylab = "cov22", plabels = list(cex = 1.25))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g11 <- do.call("s.match", c(list(dfxy1 = substitute(x$Tl1), dfxy2 = coolig, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]][[1]]))
g12 <- do.call("s.label", c(list(dfxy = substitute(x$SynVar), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]][[2]]))
g1 <- do.call("superpose", list(g11, g12))
g1@Call <- call("superpose", g11@Call, g12@Call)
g21 <- do.call("s.corcircle", c(list(dfxy = substitute(x$Tax[x$T4[, 2] == 1, ]), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]][[1]]))
g22 <- do.call("plotEig", c(list(eigvalue = substitute(x$pseudoeig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]][[2]]))
g2 <- do.call("insert", list(g22@Call, g21@Call, posi = "bottomleft", plot = FALSE, ratio = 0.25, inset = 0))
g3 <- do.call("s.arrow", c(list(dfxy = substitute(x$Tco), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g4 <- do.call("s.label", c(list(dfxy = substitute(x$cov2), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
## ADEgS creation
lay <- matrix(c(1, 2, 3, 4), 2, 2)
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4), positions = layout2position(lay), add = matrix(0, ncol = 4, nrow = 4), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.foucart" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "foucart"))
stop("Object of class 'foucart' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
## sort parameters for each graph
graphsnames <- c("rowB", "colB", "row", "col")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## compute limits
df <- rbind(as.matrix(x$li), as.matrix(x$co), as.matrix(x$Tli), as.matrix(x$Tco))
adegtot <- adegpar()
lim.global <- setlimits2D(minX = min(df[, xax]), maxX = max(df[, xax]), minY = min(df[, yax]), maxY = max(df[, yax]), origin = adegtot$porigin$origin, aspect.ratio = adegtot$paxes$aspectratio, includeOr = adegtot$porigin$include)
## pdefault values for parameters
params <- list()
params[[1]] <- list(psub = list(text = "Rows (Base)"), xlim = lim.global$xlim, ylim = lim.global$ylim, plabels = list(cex = 1.25))
params[[2]] <- list(psub = list(text = "Columns (Base)"), xlim = lim.global$xlim, ylim = lim.global$ylim, plabels = list(cex = 1.25))
params[[3]] <- list(psub = list(text = "Rows"), xlim = lim.global$xlim, ylim = lim.global$ylim, pellipses = list(axes = list(draw = FALSE)))
params[[4]] <- list(psub = list(text = "Columns"), xlim = lim.global$xlim, ylim = lim.global$ylim, pellipses = list(axes = list(draw = FALSE)), plabels = list(cex = 1.25))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g1 <- do.call("s.label", c(list(dfxy = substitute(x$li), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g2 <- do.call("s.label", c(list(dfxy = substitute(x$co), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("s.class", c(list(dfxy = substitute(x$Tli), fac = substitute(x$TL[, 2]), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g4 <- do.call("s.class", c(list(dfxy = substitute(x$Tco), fac = substitute(x$TC[, 2]), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
## ADEgS creation
lay <- matrix(c(1, 3, 2, 4), 2, 2)
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4), positions = layout2position(lay), add = matrix(0, ncol = 4, nrow = 4), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.mfa" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "mfa"))
stop("Object of class 'mfa' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
## sort parameters for each graph
graphsnames <- c("row", "comp", "col", "link")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames, nbsubgraphs = c(1, 2, 1, 1))
## default values for parameters
params <- list()
params[[1]] <- list(psub = list(text = "Rows"), pellipses = list(alpha = 0, axes = list(draw = FALSE)), label = row.names(x$li), plabels = list(cex = 1.25))
params[[2]] <- list()
params[[2]]$l1 <- list(psub = list(text = "Components (separate analyses)", position = "topleft"), pbackground = list(box = FALSE), fullcircle = FALSE, plabels = list(cex = 1.25))
params[[2]]$l2 <- list(psub = list(text = "Eigenvalues"), pbackground = list(box = TRUE))
params[[3]] <- list(psub = list(text = "Columns"), plabels = list(cex = 1.25))
params[[4]] <- list(porigin = list(include = FALSE), paxes = list(aspectratio = "fill", draw = TRUE), main = "Link", xlab = "Comp1", ylab = "Comp2", plabels = list(cex = 1.25))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g1 <- do.call("s.class", c(list(dfxy = substitute(x$lisup), fac = substitute(as.factor(x$TL[, 2])), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g21 <- do.call("s.corcircle", c(list(dfxy = substitute(x$T4comp[x$T4[, 2] == 1, ]), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]][[1]]))
g22 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]][[2]]))
g2 <- do.call("insert", list(g22@Call, g21@Call, posi = "bottomleft", plot = FALSE, inset = 0, ratio = 0.2))
g3 <- do.call("s.arrow", c(list(dfxy = substitute(x$co), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g4 <- do.call("s.label", c(list(dfxy = substitute(x$link), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
## ADEgS creation
lay <- matrix(c(1, 2, 3, 4), 2, 2)
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4), positions = layout2position(lay), add = matrix(0, ncol = 4, nrow = 4), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.multispati" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "multispati"))
stop("Object of class 'multispati' expected")
if((xax == yax) || ((x$nfposi + x$nfnega) == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > (x$nfposi + x$nfnega))
stop("Non convenient xax")
if(yax > (x$nfposi + x$nfnega))
stop("Non convenient yax")
## sort parameters for each graph
graphsnames <- c("row", "eig", "loadings", "Xax")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## default values for parameters
params <- list()
params[[1]] <- list(psub = list(text = "Scores and lag scores"))
params[[2]] <- list(psub = list(text = "Eigenvalues"), paxes = list(draw = TRUE, x = list(draw = FALSE), y = list(draw = TRUE)))
params[[3]] <- list(psub = list(text = "Loadings"))
params[[4]] <- list(psub = list(text = "Unconstrained axes"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g1 <- do.call("s.match", c(list(dfxy1 = substitute(x$li), dfxy2 = substitute(x$ls), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g2 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = c(1:x$nfposi, length(x$eig):(length(x$eig) - x$nfnega + 1)), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("s.arrow", c(list(dfxy = substitute(x$c1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g4 <- do.call("s.corcircle",c(list(dfxy = substitute(x$as), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
## ADEgS creation
lay <- matrix(c(rep(0, 4), 2, 2, rep(1, 4), 2, 2, rep(1, 4), 3, 3, rep(1, 4), 3, 3, rep(1, 4), 4, 4, rep(0, 4), 4, 4), 6, 6)
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4), positions = layout2position(lay), add = matrix(0, ncol = 4, nrow = 4), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.niche" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "niche"))
stop("Object of class 'niche' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
## sort parameters for each graph
graphsnames <- c("Xax", "var", "eig", "species", "samples", "niches")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames, nbsubgraphs = c(1, 1, 1, 2, 1, 1))
## default values for parameters
params <- list()
params[[1]] <- list(psub = list(text = "Unconstrained axes"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
params[[2]] <- list(psub = list(text = "Variables"), plabels = list(cex = 1.25))
params[[3]] <- list(psub = list(text = "Eigenvalues"))
params[[4]] <- list()
params[[4]]$l1 <- list(psub = list(text = "Samples and Species"), plabels = list(alpha = 0, boxes = list(draw = FALSE)))
params[[4]]$l2 <- list(plabels = list(cex = 1.25))
params[[5]] <- list(psub = list(text = "Samples"))
params[[6]] <- list(psub = list(text = "Niches"), plines = list(col = "transparent"), pellipses = list(axes = list(draw = FALSE)), ellipseSize = 1, plabels = list(alpha = 0, boxes = list(draw = FALSE)))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g1 <- do.call("s.corcircle", c(list(dfxy = substitute(x$as), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g2 <- do.call("s.arrow", c(list(dfxy = substitute(x$c1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g41 <- do.call("s.label", c(list(dfxy = substitute(x$ls), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]][[1]]))
g42 <- do.call("s.label", c(list(dfxy = substitute(x$li), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]][[2]]))
g4 <- do.call("superpose", list(g41, g42))
g4@Call <- call("superpose", g41@Call, g42@Call)
g5 <- do.call("s.label", c(list(dfxy = substitute(x$ls), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[5]]))
g6 <- do.call("s.distri", c(list(dfxy = substitute(x$ls), dfdistri = as.list(x$call)[[3]], xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[6]]))
## ADEgS creation
lay <- matrix(c(1, 2, 3, 4, 4, 5, 4, 4, 6), 3, 3)
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4, g5, g6), positions = layout2position(lay), add = matrix(0, ncol = 6, nrow = 6), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.procuste" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "procuste"))
stop("Object of class 'procuste' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
## sort parameters for each graph
graphsnames <- c("Xloadings", "Yloadings", "eig", "XYmatch", "Xrow", "Yrow")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## default values for parameters
params <- list()
params[[1]] <- list(psub = list(text = "X loadings"), plabels = list(cex = 1.25))
params[[2]] <- list(psub = list(text = "Y loadings"), plabels = list(cex = 1.25))
params[[3]] <- list(psub = list(text = "Eigenvalues"))
params[[4]] <- list(psub = list(text = "Row scores (X -> Y)"))
params[[5]] <- list(psub = list(text = "X row scores"))
params[[6]] <- list(psub = list(text = "Y row scores"))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g1 <- do.call("s.arrow", c(list(dfxy = substitute(x$loadX), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g2 <- do.call("s.arrow", c(list(dfxy = substitute(x$loadY), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("plotEig", c(list(eigvalue = substitute(x$d^2), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g4 <- do.call("s.match", c(list(dfxy1 = substitute(x$scorX), dfxy2 = substitute(x$scorY), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
g5 <- do.call("s.label", c(list(dfxy = substitute(x$scorX), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[5]]))
g6 <- do.call("s.label", c(list(dfxy = substitute(x$scorY), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[6]]))
## ADEgS creation
lay <- matrix(c(1, 2, 3, 4, 4, 5, 4, 4, 6), 3, 3)
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4, g5, g6), positions = layout2position(lay), add = matrix(0, ncol = 6, nrow = 6), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.rlq" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "rlq"))
stop("Object of class 'rlq' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
appel <- as.list(x$call)
## sort parameters for each graph
graphsnames <- c("Rrow", "Qrow", "Rax", "Rloadings","Qloadings", "Qax", "eig")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## default values for parameters
params <- list()
params[[1]] <- list(psub = list(text = "R row scores"), plabels = list(cex = 1.25))
params[[2]] <- list(psub = list(text = "Q row scores"), plabels = list(cex = 1.25))
params[[3]] <- list(psub = list(text = "Unconstrained axes (R)"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
params[[4]] <- list(psub = list(text = "R loadings"))
params[[5]] <- list(psub = list(text = "Unconstrained axes (Q)"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
params[[6]] <- list(psub = list(text = "Q loadings"))
params[[7]] <- list(psub = list(text = "Eigenvalues"))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g1 <- do.call("s.label", c(list(dfxy = substitute(x$lR), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g2 <- do.call("s.label", c(list(dfxy = substitute(x$lQ), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("s.corcircle", c(list(dfxy = substitute(x$aR), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g4 <- do.call("s.arrow", c(list(dfxy = substitute(x$l1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
g5 <- do.call("s.corcircle", c(list(dfxy = substitute(x$aQ), xax, yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[5]]))
g6 <- do.call("s.arrow", c(list(dfxy = substitute(x$c1), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[6]]))
g7 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[7]]))
## ADEgS creation
lay <- matrix(c(1, 1, 3, 1, 1, 4, 2, 2, 5, 2, 2, 6, 0, 0, 7), 3, 5)
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4, g6, g5, g7), positions = layout2position(lay), add = matrix(0, ncol = 7, nrow = 7), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.pta" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "pta"))
stop("Object of class 'pta' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
## prepare
dfxy <- substitute(matrix(c(x$tabw, x$cos2), nrow = length(x$tabw), ncol = 2, dimnames = list(rownames(x$RV))))
## sort parameters for each graph
graphsnames <- c("inter", "col", "row", "typo")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames, nbsubgraphs = c(2, 1, 2, 1))
## default values for parameters
params <- list()
params[[1]] <- list()
params[[1]]$l1 <- list(psub = list(text = "Interstructure", position = "topleft"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
params[[1]]$l2 <- list(psub = list(text = "Eigenvalues"), pbackground = list(box = TRUE), p1d = list(horizontal = FALSE))
params[[2]] <- list(psub = list(text = "Columns (compromise)", position = "topleft"), plabels = list(cex = 1.25))
params[[3]] <- list()
params[[3]]$l1 <- list(psub = list(text = "Rows (compromise)", position = "topleft"), plabels = list(cex = 1.25))
params[[3]]$l2 <- list(psub = list(text = "Eigenvalues"), pbackground = list(box = TRUE), p1d = list(horizontal = FALSE))
params[[4]] <- list(porigin = list(include = FALSE), paxes = list(aspectratio = "fill", draw = TRUE), main = "Typological value", xlab = "Tables weights", ylab = "Cos 2", plabels = list(cex = 1.25))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g11 <- do.call("s.corcircle", c(list(dfxy = substitute(x$RV.coo), xax = 1, yax = 2, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]$l1))
g12 <- do.call("plotEig", c(list(eigvalue = substitute(x$RV.eig), nf = 1:length(x$RV.eig), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]$l2))
g1 <- do.call("insert", list(g12@Call, g11@Call, posi = "bottomleft", plot = FALSE, ratio = 0.25, inset = 0))
g2 <- do.call("s.arrow", c(list(dfxy = substitute(x$co), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g31 <- do.call("s.label", c(list(dfxy = substitute(x$li), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]$l1))
g32 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]$l2))
g3 <- do.call("insert", list(g32@Call, g31@Call, posi = "bottomleft", plot = FALSE, ratio = 0.25, inset = 0))
g4 <- do.call("s.label", c(list(dfxy = dfxy, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
## ADEgS creation
lay <- matrix(c(1, 2, 3, 4), 2, 2)
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4), positions = layout2position(lay), add = matrix(0, ncol = 4, nrow = 4), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.sepan" <- function(x, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "sepan"))
stop("Object of class 'sepan' expected")
## prepare
facets <- substitute(reorder(as.factor(rep(x$tab.names, x$rank)), rep(1:length(x$rank), x$rank)))
## default values for parameters
sortparameters <- sortparamADEg(...)
params <- list()
params$adepar <- list(pbackground = list(box = TRUE), pgrid = list(draw = TRUE, text = list(cex = 0)), paxes = list(draw = TRUE, x = list(draw = FALSE)))
if(isTRUE(sortparameters$adepar$p1d$horizontal))
params$g.args <- list(ylim = c(0, max(x$rank) + 1))
else
params$g.args <- list(xlim = c(0, max(x$rank) + 1))
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## ADEgS creation
object <- do.call("plotEig", c(list(eigvalue = substitute(x$Eig), nf = 1:ncol(x$Li), xax = 1, yax = 2, pos = pos, storeData = storeData, plot = FALSE, facets = facets), sortparameters$adepar, sortparameters$trellis, sortparameters$g.args))
object@Call <- match.call()
if(plot)
print(object)
invisible(object)
}
"plot.statis" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "statis"))
stop("Object of class 'statis' expected")
if((xax == yax) || (x$C.nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$C.nf)
stop("Non convenient xax")
if(yax > x$C.nf)
stop("Non convenient yax")
## prepare
dfxy <- substitute(matrix(c(x$RV.tabw, x$cos2), nrow = length(x$RV.tabw), ncol = 2, dimnames = list(rownames(x$RV))))
## sort parameters for each graph
graphsnames <- c("inter", "typo", "row", "comp")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames, nbsubgraphs = c(1, 1, 2, 1))
## default values for parameters
params <- list()
params[[1]] <- list(psub = list(text = "Interstructure", position = "topleft"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
params[[2]] <- list(porigin = list(include = FALSE), paxes = list(aspectratio = "fill", draw = TRUE), main = "Typological Value", xlab = "Tables Weights", ylab = "Cos 2", plabels = list(cex = 1.25))
params[[3]] <- list()
params[[3]]$l1 <- list(psub = list(text = "Rows (compromise)", position = "topleft"), plabels = list(cex = 1.25))
params[[3]]$l2 <- list(psub = list(text = "Eigenvalues"), pbackground = list(box = TRUE))
params[[4]] <- list(psub = list(text = "Components (separate analyses)", position = "topleft"), pbackground = list(box = FALSE), plabels = list(cex = 1.25))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g1 <- do.call("s.corcircle", c(list(dfxy = substitute(x$RV.coo), xax = 1, yax = 2, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g2 <- do.call("s.label", c(list(dfxy = dfxy, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g31 <- do.call("s.label", c(list(dfxy = substitute(x$C.li), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]][[1]]))
g32 <- do.call("plotEig", c(list(eigvalue = substitute(x$C.eig), nf = 1:x$C.nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData), sortparameters[[3]][[2]]))
g3 <- do.call("insert", list(g32@Call, g31@Call, posi = "bottomleft", plot = FALSE, ratio = 0.25, inset = 0))
g4 <- do.call("s.corcircle", c(list(dfxy = substitute(x$C.T4[x$T4[, 2] == 1, ]), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
## ADEgS creation
lay <- matrix(c(1, 2, 3, 4), 2, 2)
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4), positions = layout2position(lay), add = matrix(0, ncol = 4, nrow = 4), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.multiblock" <- function(x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "multiblock"))
stop("Object of class 'multiblock' expected")
if((xax == yax) || (x$nf == 1))
stop("One axis only : not yet implemented")
if(length(xax) > 1 | length(yax) > 1)
stop("Not implemented for multiple xax/yax")
if(xax > x$nf)
stop("Non convenient xax")
if(yax > x$nf)
stop("Non convenient yax")
## sort parameters for each graph
graphsnames <- c("Xrow", "eig", "cov2", "Ycol", "Xloadings")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## default values for parameters
params <- list()
params[[1]]<- list(psub = list(text = "Row scores (X)"), plabels = list(cex = 1.25))
params[[2]]<- list(psub = list(text = "Eigenvalues"))
params[[3]] <- list(psub = list(text = "Cov^2"), plabels = list(cex = 1.25))
params[[4]] <- list(psub = list(text = "Y columns"), plabels = list(cex = 1.25))
params[[5]] <- list(psub = list(text = "X loadings"), plabels = list(cex = 1.25))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g1 <- do.call("s.label", c(list(dfxy = substitute(x$lX), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g2 <- do.call("plotEig", c(list(eigvalue = substitute(x$eig), nf = 1:x$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("s.arrow", c(list(dfxy = substitute(x$cov2), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g4 <- do.call("s.arrow", c(list(dfxy = substitute(x$Yco), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
g5 <- do.call("s.arrow", c(list(dfxy = substitute(x$faX), xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[5]]))
## ADEgS creation
lay <- matrix(c(rep(c(0, 0, 2, 2, 3, 3), 2), rep(c(rep(1, 4), 4, 4), 2), rep(c(rep(1, 4), 5, 5), 2)), 6, 6)
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4, g5), positions = layout2position(lay), add = matrix(0, ncol = 5, nrow = 5), Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.randxval" <- function(x, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "randxval"))
stop("Object of class 'randxval' expected")
## Plot results
graphsnames <- c("RMSEcMean", "RMSEcQuantiles", "RMSEvMean", "RMSEvQuantiles")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## compute common limits
lim <- range(x$stats)
origin <- if(is.null(sortparameters[[1]]$porigin)) list(origin = 0, include = FALSE) else sortparameters[[1]]$porigin
lim <- setlimits1D(lim[1], lim[2], origin = origin$origin[1], includeOr = origin$include)
## default values for parameters
params <- list()
params[[1]] <- list(plines = list(col = "red"), ppoints = list(col = "red", cex = 2), p1d = list(horizontal = FALSE), paxes = list(draw = TRUE), pgrid = list(text = list(cex = 0)), ylab = "Root Mean Square Error", ylim = lim, porigin = origin)
params[[2]] <- list(plines = list(col = "red"), ppolygons = list(col = "red"), p1d = list(horizontal = FALSE), paxes = list(draw = TRUE), pgrid = list(text = list(cex = 0)), method = "bars")
params[[3]] <- list(plines = list(col = "blue"), ppoints = list(col = "blue", cex = 2), p1d = list(horizontal = FALSE), paxes = list(draw = TRUE), pgrid = list(text = list(cex = 0)))
params[[4]] <- list(plines = list(col = "blue"), ppolygons = list(col = "blue"), p1d = list(horizontal = FALSE), paxes = list(draw = TRUE), pgrid = list(text = list(cex = 0)), method = "bars")
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g1 <- do.call("s1d.curve", c(list(score = substitute(x$stats[1, 1]), plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g2 <- do.call("s1d.interval", c(list(score1 = substitute(x$stats[1, 2]), score2 = substitute(x$stats[1, 3]), plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("s1d.curve", c(list(score = substitute(x$stats[2, 1]), plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g4 <- do.call("s1d.interval", c(list(score1 = substitute(x$stats[2, 2]), score2 = substitute(x$stats[2, 3]), plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
## ADEgS creation
add.mat <- matrix(0, nrow = 4, ncol = 4)
add.mat[upper.tri(add.mat)] <- 1
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4), positions = matrix(rep(c(0, 0, 1, 1), 4), nrow = 4, byrow = TRUE), add = add.mat, Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.krandxval" <- function(x, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "krandxval"))
stop("Object of class 'krandxval' expected")
## Plot results
graphsnames <- c("RMSEcMean", "RMSEcQuantiles", "RMSEvMean", "RMSEvQuantiles")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## compute common limits
lim <- range(x$statsRMSEc[, -1], x$statsRMSEv[, -1])
origin <- if(is.null(sortparameters[[1]]$porigin)) list(origin = 0, include = FALSE) else sortparameters[[1]]$porigin
lim <- setlimits1D(lim[1], lim[2], origin = origin$origin[1], includeOr = origin$include)
## default values for parameters
params <- list()
params[[1]] <- list(plines = list(col = "red"), ppoints = list(col = "red", cex = 2), p1d = list(horizontal = FALSE), paxes = list(draw = TRUE), pgrid = list(text = list(cex = 0)), ylab = "Root Mean Square Error", ylim = lim, porigin = origin)
params[[2]] <- list(plines = list(col = "red"), ppolygons = list(col = "red"), p1d = list(horizontal = FALSE), paxes = list(draw = TRUE), pgrid = list(text = list(cex = 0)), method = "area")
params[[3]] <- list(plines = list(col = "blue"), ppoints = list(col = "blue", cex = 2), p1d = list(horizontal = FALSE), paxes = list(draw = TRUE), pgrid = list(text = list(cex = 0)))
params[[4]] <- list(plines = list(col = "blue"), ppolygons = list(col = "blue"), p1d = list(horizontal = FALSE), paxes = list(draw = TRUE), pgrid = list(text = list(cex = 0)), method = "area")
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g1 <- do.call("s1d.curve", c(list(score = substitute(x$statsRMSEc[, 1]), key = list(corner = c(0,1), text = list(c("RMSEc", "RMSEv"), col = c(sortparameters[[1]]$plines$col, sortparameters[[3]]$plines$col))), plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g2 <- do.call("s1d.interval", c(list(score1 = substitute(x$statsRMSEc[, 2]), score2 = substitute(x$statsRMSEc[, 3]), plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
g3 <- do.call("s1d.curve", c(list(score = substitute(x$statsRMSEv[, 1]), plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[3]]))
g4 <- do.call("s1d.interval", c(list(score1 = substitute(x$statsRMSEv[, 2]), score2 = substitute(x$statsRMSEv[, 3]), plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[4]]))
## ADEgS creation
add.mat <- matrix(0, nrow = 4, ncol = 4)
add.mat[upper.tri(add.mat)] <- 1
object <- new(Class = "ADEgS", ADEglist = list(g1, g2, g3, g4), positions = matrix(rep(c(0, 0, 1, 1), 4), nrow = 4, byrow = TRUE), add = add.mat, Call = match.call())
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.randboot" <- function(x, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "randboot"))
stop("Object of class 'randboot' expected")
## Plot results
graphsnames <- c("obs", "quantiles")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## compute common limits
lim <- range(c(x$obs, x$stats))
origin <- if(is.null(sortparameters[[1]]$porigin)) list(origin = 0, include = FALSE) else sortparameters[[1]]$porigin
lim <- setlimits1D(lim[1], lim[2], origin = origin$origin[1], includeOr = origin$include)
## default values for parameters
params <- list()
params[[1]] <- list(p1d = list(horizontal = FALSE), paxes = list(draw = TRUE), pgrid = list(text = list(cex = 0)), ppoints = list(cex = 2), ylim = lim, porigin = origin)
params[[2]] <- list(p1d = list(horizontal = FALSE), paxes = list(draw = TRUE), pgrid = list(text = list(cex = 0)), method = "bars")
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## creation of each individual ADEg
g1 <- do.call("s1d.curve", c(list(score = substitute(x$obs), plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g2 <- do.call("s1d.interval", c(list(score1 = substitute(x$stats[1]), score2 = substitute(x$stats[2]), plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
## ADEgS creation
object <- superpose(g1, g2)
object@Call <- match.call()
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.krandboot" <- function(x, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "krandboot"))
stop("Object of class 'krandboot' expected")
## Plot results
graphsnames <- c("obs", "quantiles")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## compute common limits
lim <- range(c(x$obs, range(x$stats)))
origin <- if(is.null(sortparameters[[1]]$porigin)) list(origin = 0, include = FALSE) else sortparameters[[1]]$porigin
lim <- setlimits1D(lim[1], lim[2], origin = origin$origin[1], includeOr = origin$include)
## default values for parameters
params <- list()
params[[1]] <- list(p1d = list(horizontal = FALSE), pgrid = list(text = list(cex = 0)), paxes = list(draw = TRUE), ppoints = list(cex = 2), ylim = lim, porigin = origin)
params[[2]] <- list(p1d = list(horizontal = FALSE), pgrid = list(text = list(cex = 0)), paxes = list(draw = TRUE), method = "bars")
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
lab <- list(list(labels = rownames(x$stats), at = 1:length(rownames(x$stats)), rot = 90))
names(lab)[1] <- ifelse(sortparameters[[1]]$p1d$horizontal == FALSE, "x", "y")
## creation of each individual ADEg
g1 <- do.call("s1d.curve", c(list(score = substitute(x$obs), scales = lab, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[1]]))
g2 <- do.call("s1d.interval", c(list(score1 = substitute(x$stats[, 1]), score2 = substitute(x$stats[, 2]), plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters[[2]]))
## ADEgS creation
object <- superpose(g1, g2)
object@Call <- match.call()
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.inertia" <- function(x, xax = 1, yax = 2, threshold = 0.1, contrib = c("abs", "rel"), type = c("label", "cross", "ellipse", "both"), ellipseSize = 1.5,
posieig = "none", plot = TRUE, storeData = TRUE, pos = -1, ...) {
if(!inherits(x, "inertia"))
stop("Object of class 'inertia' expected")
## data management
ori <- as.list(x$call)
evTab <- eval.parent(ori[[2]])
if(length(xax) > 1)
stop("Not implemented for multiple xax")
if(xax > evTab$nf)
stop("Non convenient xax")
if(length(yax) > 1)
stop("Not implemented for multiple yax")
if(yax > evTab$nf)
stop("Non convenient yax")
adegtot <- adegpar()
position <- .getposition(posieig[1:min(2, length(posieig))])
type <- match.arg(type)[1]
contrib <- match.arg(contrib)[1]
## sort parameters for each graph
graphsnames <- c("light_row", "heavy_row", "light_col", "heavy_col", "eig")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## parameters management
adegtot <- adegpar()
params <- list()
params$light_row <- list(plabels = list(cex = 0), ppoints = list(col = "grey20", alpha = 0.45, cex = 1.2, pch = 19))
params$light_col <- list(plabels = list(cex = 0), ppoints = list(col = "grey20", alpha = 0.45, cex = 1.2, pch = 19))
if(type == "label") {
params$heavy_row <- list(plabels = list(boxes = list(draw = FALSE), col = "red"), ppoints = list(cex = 0))
params$heavy_col <- list(plabels = list(boxes = list(draw = FALSE), col = "blue"), ppoints = list(cex = 0))
} else if(type == "cross") {
params$heavy_row <- list(ellipseSize = ellipseSize, plabels = list(boxes = list(draw = FALSE), col = "red"), ppoints = list(cex = 0), pellipses = list(lwd = 0, axes = list(col = "red", lty = 1)), plines = list(lwd = 0), plegend = list(drawKey = FALSE))
params$heavy_col <- list(ellipseSize = ellipseSize, plabels = list(boxes = list(draw = FALSE), col = "blue"), ppoints = list(cex = 0), pellipses = list(lwd = 0, axes = list(col = "blue", lty = 1)), plines = list(lwd = 0), plegend = list(drawKey = FALSE))
} else if(type == "ellipse") {
params$heavy_row <- list(ellipseSize = ellipseSize, plabels = list(boxes = list(draw = FALSE), col = "red"), ppoints = list(cex = 0), pellipses = list(border = "red", axes = list(lwd = 0)), plines = list(col = 0))
params$heavy_col <- list(ellipseSize = ellipseSize, plabels = list(boxes = list(draw = FALSE), col = "blue"), ppoints = list(cex = 0), pellipses = list(border = "blue", axes = list(lwd = 0)), plines = list(lwd = 0))
} else if(type == "both") {
params$heavy_row <- list(ellipseSize = 1.5, plabels = list(boxes = list(draw = FALSE), col = "red"), ppoints = list(cex = 0), pellipses = list(border = "red", axes = list(col = "red", lty = 1)), plines = list(lwd = 0))
params$heavy_col <- list(ellipseSize = 1.5, plabels = list(boxes = list(draw = FALSE), col = "blue"), ppoints = list(cex = 0), pellipses = list(border = "blue", axes = list(col = "blue", lty = 1)), plines = list(lwd = 0))
}
params$eig <- list(pbackground = list(box = TRUE), psub = list(text = "Eigenvalues"))
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
# never display points under contribution threshold
sortparameters$light_row$plabels$cex <- 0
sortparameters$light_col$plabels$cex <- 0
## management of the data and the parameters about the rows' contribution (individuals) on axes
if(!is.null(x$row.rel)) {
datacontrib <- x[[ifelse(contrib == "abs", "row.abs", "row.rel")]]
datacontrib <- datacontrib[, c(xax, yax)]
if(type != "label") {
inertrow <- abs(datacontrib) / 100
lightrow <- subset(evTab$li[, c(xax, yax)], inertrow[, 1] < threshold & inertrow[, 2] < threshold)
heavyrow <- subset(evTab$li[, c(xax, yax)], inertrow[, 1] >= threshold | inertrow[, 2] >= threshold)
if(nrow(heavyrow) == 0)
stop("No points to draw, try lowering 'threshold'")
heavy_inertrow <- subset(inertrow, inertrow[, 1] >= threshold | inertrow[, 2] >= threshold)
limglobal <- setlimits2D(minX = min(c(heavyrow[, 1], lightrow[, 1])), maxX = max(c(heavyrow[, 1], lightrow[, 1])),
minY = min(c(heavyrow[, 2], lightrow[, 2])), maxY = max(c(heavyrow[, 2], lightrow[, 2])),
origin = adegtot$porigin$origin, aspect.ratio = adegtot$paxes$aspectratio, includeOr = adegtot$porigin$include)
# if ellipses or crosses are drawn, the limits are re-calculated and the elipses size are normalized
heavy_inertrowmax <- apply(heavy_inertrow, 2, max)
heavy_inertrownorm <- matrix(NA, NROW(heavy_inertrow), 2)
for (i in 1:2) {heavy_inertrownorm[, i] <- (heavy_inertrow[, i] / heavy_inertrowmax[i]) * (diff(limglobal[[i]]) / 10)}
# TODO
# add 0.00001 to the coordinates to avoid the bug in the '.util.ellipse' function (waiting to correct it)
cont_row <- cbind(c(heavyrow[, 1] - heavy_inertrownorm[, 1]/2, heavyrow[, 1] + heavy_inertrownorm[, 1]/2, heavyrow[, 1], heavyrow[, 1] + 0.00001),
c(heavyrow[, 2] + 0.00001, heavyrow[, 2], heavyrow[, 2] - heavy_inertrownorm[, 2]/2, heavyrow[, 2] + heavy_inertrownorm[, 2]/2))
fac_row <- as.factor(rep(rownames(heavyrow), 4))
limglobal <- setlimits2D(minX = min(c(cont_row[, 1], lightrow[, 1])), maxX = max(c(cont_row[, 1], lightrow[, 1])),
minY = min(c(cont_row[, 2], lightrow[, 2])), maxY = max(c(cont_row[, 2], lightrow[, 2])),
origin = adegtot$porigin$origin, aspect.ratio = adegtot$paxes$aspectratio, includeOr = adegtot$porigin$include)
} else {
if(contrib == "abs") {
temp <- sweep(datacontrib, 2, x$tot.inertia$inertia[c(xax, yax)], "*") / 100
tempsum <- apply(temp, 1, sum)
lambdasum <- sum(x$tot.inertia$inertia[c(xax, yax)])
inertrow_cumul <- tempsum / lambdasum
} else {
inertrow <- abs(datacontrib) / 100
inertrow_cumul <- apply(inertrow, 1, sum)
}
lightrow <- subset(evTab$li[, c(xax, yax)], inertrow_cumul < threshold)
heavyrow <- subset(evTab$li[, c(xax, yax)], inertrow_cumul >= threshold)
heavy_inertrow <- subset(inertrow_cumul, inertrow_cumul >= threshold)
if(nrow(heavyrow) == 0)
stop("No points to draw, try lowering 'threshold'")
if(is.null(sortparameters$heavy_row$plabels$cex)) {
sortparameters$heavy_row$plabels$cex <- heavy_inertrow / (max(heavy_inertrow) / 2)
} else {
sortparameters$heavy_row$plabels$cex <- sortparameters$heavy_row$plabels$cex * heavy_inertrow / (max(heavy_inertrow) / 2)
}
limglobal <- setlimits2D(minX = min(c(heavyrow[, 1], lightrow[, 1])), maxX = max(c(heavyrow[, 1], lightrow[, 1])),
minY = min(c(heavyrow[, 2], lightrow[, 2])), maxY = max(c(heavyrow[, 2], lightrow[, 2])),
origin = adegtot$porigin$origin, aspect.ratio = adegtot$paxes$aspectratio, includeOr = adegtot$porigin$include)
}
params <- list()
params$light_row <- list(xlim = limglobal$xlim, ylim = limglobal$ylim)
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
}
## management of the data and the parameters about the columns' contribution (variables) on axes
if(!is.null(x$col.rel)) {
datacontrib <- x[[ifelse(contrib == "abs", "col.abs", "col.rel")]]
datacontrib <- datacontrib[, c(xax, yax)]
if(type != "label") {
inertcol <- abs(datacontrib) / 100
lightcol <- subset(evTab$co[, c(xax, yax)], inertcol[, 1] < threshold & inertcol[, 2] < threshold)
heavycol <- subset(evTab$co[, c(xax, yax)], inertcol[, 1] >= threshold | inertcol[, 2] >= threshold)
if(nrow(heavycol) == 0)
stop("No points to draw, try lowering 'threshold'")
heavy_inertcol <- subset(inertcol, inertcol[, 1] >= threshold | inertcol[, 2] >= threshold)
limglobal <- setlimits2D(minX = min(c(heavycol[, 1], lightcol[, 1])), maxX = max(c(heavycol[, 1], lightcol[, 1])),
minY = min(c(heavycol[, 2], lightcol[, 2])), maxY = max(c(heavycol[, 2], lightcol[, 2])),
origin = adegtot$porigin$origin, aspect.ratio = adegtot$paxes$aspectratio, includeOr = adegtot$porigin$include)
# if ellipses or crosses are drawn, the limits are re-calculated and the ellipse size are normalized
heavy_inertcolmax <- apply(heavy_inertcol, 2, max)
heavy_inertcolnorm <- matrix(NA, NROW(heavy_inertcol), 2)
for (i in 1:2) {heavy_inertcolnorm[, i] <- (heavy_inertcol[, i] / heavy_inertcolmax[i]) * (diff(limglobal[[i]]) / 10)}
# TODO
# add 0.00001 to the coordinates to avoid the bug in the '.util.ellipse' function (waiting to correct it)
cont_col <- cbind(c(heavycol[, 1] - heavy_inertcolnorm[, 1]/2, heavycol[, 1] + heavy_inertcolnorm[, 1]/2, heavycol[, 1], heavycol[, 1] + 0.00001),
c(heavycol[, 2] + 0.00001, heavycol[, 2], heavycol[, 2] - heavy_inertcolnorm[, 2]/2, heavycol[, 2] + heavy_inertcolnorm[, 2]/2))
fac_col <- as.factor(rep(rownames(heavycol), 4))
limglobal <- setlimits2D(minX = min(c(cont_col[, 1], lightcol[, 1])), maxX = max(c(cont_col[, 1], lightcol[, 1])),
minY = min(c(cont_col[, 2], lightcol[, 2])), maxY = max(c(cont_col[, 2], lightcol[, 2])),
origin = adegtot$porigin$origin, aspect.ratio = adegtot$paxes$aspectratio, includeOr = adegtot$porigin$include)
} else {
if(contrib == "abs") {
temp <- sweep(datacontrib, 2, x$tot.inertia$inertia[c(xax, yax)], "*") / 100
tempsum <- apply(temp, 1, sum)
lambdasum <- sum(x$tot.inertia$inertia[c(xax, yax)])
inertcol_cumul <- tempsum / lambdasum
} else {
inertcol <- abs(datacontrib) / 100
inertcol_cumul <- apply(inertcol, 1, sum)
}
lightcol <- subset(evTab$co[, c(xax, yax)], inertcol_cumul < threshold)
heavycol <- subset(evTab$co[, c(xax, yax)], inertcol_cumul >= threshold)
heavy_inertcolnorm <- subset(inertcol_cumul, inertcol_cumul >= threshold)
if(nrow(heavycol) == 0)
stop("No points to draw, try lowering 'threshold'")
if(is.null(sortparameters$heavy_col$plabels$cex)) {
sortparameters$heavy_col$plabels$cex <- heavy_inertcolnorm / (max(heavy_inertcolnorm) / 2)
} else {
sortparameters$heavy_col$plabels$cex <- sortparameters$heavy_col$plabels$cex * heavy_inertcolnorm / (max(heavy_inertcolnorm) / 2)
}
limglobal <- setlimits2D(minX = min(c(heavycol[, 1], lightcol[, 1])), maxX = max(c(heavycol[, 1], lightcol[, 1])),
minY = min(c(heavycol[, 2], lightcol[, 2])), maxY = max(c(heavycol[, 2], lightcol[, 2])),
origin = adegtot$porigin$origin, aspect.ratio = adegtot$paxes$aspectratio, includeOr = adegtot$porigin$include)
}
params <- list()
params$light_col <- list(xlim = limglobal$xlim, ylim = limglobal$ylim)
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
}
## displaying of the eigen values
if(!is.null(position))
geig <- do.call("plotEig", c(list(eigvalue = call("$", ori[[2]], "eig"), nf = 1:evTab$nf, xax = xax, yax = yax, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$eig))
## function to create the graphics about the row' contribution (individuals) on axes
f_row <- function(posi = NULL, pos){
graphnames <- c(if(length(lightrow) > 0) {"light_row"}, "heavy_row", if(!is.null(posi)) {"eig"})
g1 <- do.call("s.label", c(list(dfxy = lightrow, xax = 1, yax = 2, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$light_row))
if(type == "label")
g2 <- do.call("s.label", c(list(dfxy = heavyrow, xax = 1, yax = 2, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$heavy_row))
else
g2 <- do.call("s.class", c(list(dfxy = cont_row, fac = fac_row, xax = 1, yax = 2, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$heavy_row))
grow <- do.call("superpose", list(g1, g2))
grow@Call <- call("superpose", list(g1@Call, g2@Call))
if(!is.null(posi))
grow <- do.call("insert", list(geig, grow, posi = posi, plot = FALSE, ratio = 0.25))
names(grow) <- graphnames
return(grow)
}
# function to create the graphics about the columns' contribution (variables) on axes
f_col <- function(posi = NULL, pos) {
graphnames <- c(if(length(lightcol) > 0) {"light_col"}, "heavy_col", if(!is.null(posi)) {"eig"})
g3 <- do.call("s.label", c(list(dfxy = lightcol, xax = 1, yax = 2, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$light_col))
if(type == "label")
g4 <- do.call("s.label", c(list(dfxy = heavycol, xax = 1, yax = 2, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$heavy_col))
else
g4 <- do.call("s.class", c(list(dfxy = cont_col, fac = fac_col, xax = 1, yax = 2, plot = FALSE, storeData = storeData, pos = pos - 2), sortparameters$heavy_col))
gcol <- do.call("superpose", list(g3, g4))
gcol@Call <- call("superpose", list(g3@Call, g4@Call))
if(!is.null(posi))
gcol <- do.call("insert", list(geig, gcol, posi = posi, plot = FALSE, ratio = 0.25))
names(gcol) <- graphnames
return(gcol)
}
## function to create a layout of the graphics about the contribution of rows (individuals) and columns (variables) on axes
f_both <- function(posi = NULL, pos) {
object <- do.call("cbindADEg", c(list(f_row(posi = NULL, pos = pos - 1), f_col(posi = posi, pos = pos - 1))))
names(object) <- c("row", "col")
return(object)
}
## creation of the appropriate plot according to the input data
if(!is.null(x$row.rel) & is.null(x$col.rel))
object <- f_row(posi = position, pos = pos)
if(!is.null(x$col.rel) & is.null(x$row.rel))
object <- f_col(posi = position, pos = pos)
if(!is.null(x$row.rel) & !is.null(x$col.rel))
object <- f_both(posi = position, pos = pos)
if(is.null(x$row.rel) & is.null(x$col.rel))
stop(paste("No inertia was calculated in the ", substitute(x), " object", sep = ""))
object@Call <- match.call()
if(plot)
print(object)
invisible(object)
}
"plot.randtest" <- function(x, nclass = 10, coeff = 1, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if(!inherits(x, "randtest"))
stop("Object of class 'randtest' expected")
# by default, in ade4, as.randtest computes the histogram with 10 class
# x$sim is available only if !inherits(x, "lightrandtest")
if(!inherits(x, "lightrandtest") & nclass != 10){
h0 <- hist(x$sim, plot = FALSE, nclass = nclass)
} else {
h0 <- x$plot$hist
}
## common limits
mylim <- x$plot$xlim
## parameter management
graphsnames <- c("sim", "obs")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
params <- list()
params[[1]] <- list(p1d = list(horizontal = TRUE), pgrid = list(draw = FALSE), paxes = list(draw = TRUE), xlim = mylim, main = "Histogram of sim", xlab = "sim", ylab = "Frequency")
params[[2]] <- list(plines = list(lwd = 1.5), ppoints = list(pch = 18, cex = 1.5))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
## plot creation
object <- plotRandTest(hist = h0, nclass = nclass, obs = x$obs, params = sortparameters)
names(object) <- graphsnames
object@Call <- match.call()
if(plot)
print(object)
invisible(object)
}
"plot.krandtest" <- function (x, nclass = 10, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if (!inherits(x, "krandtest"))
stop("Object of class 'krandtest' expected")
ng <- x$ntest
maintitle <- x$names
## parameter management
graphsnames <- paste0("g", seq_len(ng))
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
params <- list()
params <- lapply(seq_len(ng), function(i) {params[[i]] <- list(p1d = list(horizontal = TRUE), pgrid = list(draw = FALSE), paxes = list(draw = TRUE),
xlim = x$plot[[i]]$xlim, main = maintitle[i], xlab = "", ylab = "",
plines = list(lwd = 1.5), ppoints = list(pch = 18, cex = 1.5))})
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
if(inherits(x, "lightkrandtest")) {
l <- list()
l <- sapply(seq_len(ng), function(i) {do.call("plotRandTest", c(list(hist = x$plot[[i]]$hist, nclass = nclass, obs = x$obs[i], params = sortparameters[[i]])))})
## ADEgS creation
object <- new(Class = "ADEgS", ADEglist = l, positions = layout2position(rev(.n2mfrow(ng)), ng = ng), add = matrix(0, ncol = ng, nrow = ng), Call = match.call())
names(object) <- graphsnames
} else {
l <- list()
for (k in 1:x$ntest) {
rd <- as.randtest(x$sim[, k], x$obs[k], output = "full")
l[[k]] <- do.call("plot.randtest", c(list(rd, nclass = nclass, plot = FALSE), sortparameters[[k]]))
}
## ADEgS creation
object <- new(Class = "ADEgS", ADEglist = l, positions = layout2position(rev(.n2mfrow(ng)), ng = ng), add = matrix(0, ncol = ng, nrow = ng), Call = match.call())
names(object) <- graphsnames
}
object@Call <- match.call()
if(plot)
print(object)
invisible(object)
}
"plot.bcaloocv" <- function (x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if (!inherits(x, "bcaloocv"))
stop("Use only with 'bcaloocv' objects")
bca1 <- eval(x$call[[2]])
fac1 <- eval(bca1$call[[3]])
if (bca1$nf == 1) {
warnings("One axis only : not yet implemented")
return(invisible())
}
# Permutation test
rt1 <- ade4::randtest(bca1)
# Compute cross-validated coordinates
Oijbga <- x$Oij_bca
Oijxval <- x$Oij_XVal
dOij <- x$DeltaOij
## sort parameters for each graph
graphsnames <- c("BCA", "XVal")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## default values for parameters
params <- list()
params[[1]] <- list(psub = list(text = "BCA"), pbackground = list(box = TRUE), plabels = list(cex = 1.25))
params[[2]] <- list(psub = list(text = "Cross-validation"), pbackground = list(box = TRUE), plabels = list(cex = 1.25))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
# Character string: graph title, permutation test p-value and variance ratio
pst1 <- paste0("Permutation test p = ", rt1$pvalue, ", Expl.Var = ", round(bca1$ratio, 2), ", Oij = ", round(Oijbga,2))
# Draw BGA factor map
sc1 <- do.call("s.class", c(list(dfxy = bca1$ls[,c(xax, yax)], fac = fac1, col = TRUE, psub.text = pst1, ellipseSize = 0, chullSize = 1, plot = FALSE), storeData = storeData, pos = pos - 2, sortparameters[[1]]))
# Compute cross-validated coordinates
# Character string for graph title
pst2 <- paste0("Cross-validation Oij = ", round(Oijxval,2), ", dOij = ", round(dOij), "%")
# Cross-validated factor map
sc2 <- do.call("s.class", c(list(x$XValCoord[,c(xax, yax)], fac1, col = TRUE, psub.text = pst2, ellipseSize = 0, chullSize = 1, plot = FALSE), storeData = storeData, pos = pos - 2, sortparameters[[2]]))
# Display both factor maps side by side
sc2 <- update(sc2, xlim = sc1@g.args$xlim, ylim = sc1@g.args$ylim)
lay <- c(1, 2)
object <- new(Class = "ADEgS", ADEglist = list(sc1, sc2), positions = layout2position(lay), add = matrix(0, ncol = 2, nrow = 2), Call = match.call() )
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
"plot.discloocv" <- function (x, xax = 1, yax = 2, pos = -1, storeData = TRUE, plot = TRUE, ...) {
if (!inherits(x, "discloocv"))
stop("Use only with 'discloocv' objects")
disc1 <- eval(x$call[[2]])
fac1 <- eval(disc1$call[[3]])
if (disc1$nf == 1) {
warnings("One axis only : not yet implemented")
return(invisible())
}
# Permutation test
rt1 <- ade4::randtest(disc1)
# Compute cross-validated coordinates
Oijdisc <- x$Oij_disc
Oijxval <- x$Oij_XVal
dOij <- x$DeltaOij
## sort parameters for each graph
graphsnames <- c("Discrimin", "XVal")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
## default values for parameters
params <- list()
params[[1]] <- list(psub = list(text = "Discrimin"), pbackground = list(box = TRUE), plabels = list(cex = 1.25))
params[[2]] <- list(psub = list(text = "Cross-validation"), pbackground = list(box = TRUE), plabels = list(cex = 1.25))
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
# Character string: graph title, permutation test p-value and variance ratio
pst1 <- paste0("Permutation test p = ", rt1$pvalue, ", Oij = ", round(Oijdisc,2))
# Draw discrimin factor map
sc1 <- do.call("s.class", c(list(dfxy = disc1$li[,c(xax, yax)], fac = fac1, col = TRUE, psub.text = pst1, ellipseSize = 0, chullSize = 1, plot = FALSE), storeData = storeData, pos = pos - 2, sortparameters[[1]]))
# Compute cross-validated coordinates
# Character string for graph title
pst2 <- paste0("Cross-validation Oij = ", round(Oijxval,2), ", dOij = ", round(dOij), "%")
# Cross-validated factor map
sc2 <- do.call("s.class", c(list(x$XValCoord[,c(xax, yax)], fac1, col = TRUE, psub.text = pst2, ellipseSize = 0, chullSize = 1, plot = FALSE), storeData = storeData, pos = pos - 2, sortparameters[[2]]))
# Display both factor maps side by side
sc2 <- update(sc2, xlim = sc1@g.args$xlim, ylim = sc1@g.args$ylim)
lay <- c(1, 2)
object <- new(Class = "ADEgS", ADEglist = list(sc1, sc2), positions = layout2position(lay), add = matrix(0, ncol = 2, nrow = 2), Call = match.call() )
names(object) <- graphsnames
if(plot)
print(object)
invisible(object)
}
adegraphics/R/Tr.class.R 0000644 0001762 0000144 00000023716 13742303021 014545 0 ustar ligges users ######################################################
## Tr.class ###
## Triangular representation with a factor ###
######################################################
setClass(
Class = "Tr.class",
contains = "ADEg.Tr"
)
setMethod(
f = "initialize",
signature = "Tr.class",
definition = function(.Object, data = list(dfxyz = NULL, fac = NULL, wt = NULL, labels = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...)
.Object@data$fac <- data$fac
.Object@data$wt <- data$wt
.Object@data$labels <- data$labels
return(.Object)
})
setMethod(
f = "prepare",
signature = "Tr.class",
definition = function(object) {
name_obj <- deparse(substitute(object))
if(object@data$storeData) {
df <- object@data$dfxyz
fac <- as.factor(object@data$fac)
wt <- object@data$wt
} else {
fac <- as.factor(eval(object@data$fac, envir = sys.frame(object@data$frame)))
df <- eval(object@data$dfxyz, envir = sys.frame(object@data$frame))
wt <- eval(object@data$wt, envir = sys.frame(object@data$frame))
}
nlev <- nlevels(fac)
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
## change default for some parameters
if(any(adegtot$plabels$cex > 0) & is.null(object@adeg.par$plegend$drawKey)) ## if labels, no legend
adegtot$plegend$drawKey <- FALSE
## setting colors
paramsToColor <- list(ppoints = list(col = object@adeg.par$ppoints$col, fill = object@adeg.par$ppoints$fill),
plabels = list(col = object@adeg.par$plabels$col, boxes = list(border = object@adeg.par$plabels$boxes$border)),
plines = list(col = object@adeg.par$plines$col),
pellipses = list(border = object@adeg.par$pellipses$border, col = object@adeg.par$pellipses$col),
ppolygons = list(border = object@adeg.par$ppolygons$border, col = object@adeg.par$ppolygons$col))
if(!(is.null(object@g.args$col) || (is.logical(object@g.args$col) && !object@g.args$col)))
adegtot <- modifyList(adegtot, col2adepar(ccol = object@g.args$col, pparamsToColor = paramsToColor, nnlev = nlev))
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
## calculate 2D coordinates
df <- sweep(df, 1, rowSums(df), "/")
object@stats$coords2d <- .coordtotriangleM(df, mini3 = object@g.args$min3d, maxi3 = object@g.args$max3d)[, 2:3]
## compute means for the 3 variables (for getstats)
object@stats$means <- matrix(meanfacwt(df, fac, wt), nrow = nlev)
## mean2d: columns: axes, row: levels
object@stats$mean2d <- matrix(meanfacwt(object@stats$coords2d, fac, wt), nrow = nlev)
mean.x <- object@stats$mean2d[, 1] ## all means rows as levels, columns as variables
mean.y <- object@stats$mean2d[, 2]
## ellipses
if(object@g.args$ellipseSize > 0) {
object@stats$covvar <- covfacwt(df, fac, wt)
object@stats$covvar2d <- covfacwt(object@stats$coords2d, fac, wt)
covvartotal <- object@stats$covvar2d
object@s.misc$ellipses <- lapply(1:nlev,
FUN = function(i) {
.util.ellipse(mean.x[i], mean.y[i], vx = covvartotal[[i]][1, 1], vy = covvartotal[[i]][2, 2], cxy = covvartotal[[i]][1, 2],
coeff = object@g.args$ellipseSize)
})
}
## convex hull
if(!is.null(object@g.args$chullSize))
if(any(object@g.args$chullSize > 0))
object@s.misc$chullcoord <- .util.chull(object@stats$coords2d[, 1], object@stats$coords2d[, 2], mean.x, mean.y, fac = fac, chullSize = object@g.args$chullSize)
## never optimized labels for triangle.class
object@adeg.par$plabels$optim <- FALSE
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "Tr.class",
definition = function(object, x, y) {
if(object@data$storeData) {
df <- object@data$dfxyz
fac <- object@data$fac
labels <- object@data$labels
} else {
fac <- eval(object@data$fac, envir = sys.frame(object@data$frame))
df <- eval(object@data$dfxyz, envir = sys.frame(object@data$frame))
labels <- eval(object@data$labels, envir = sys.frame(object@data$frame))
}
fac <- as.factor(fac)
nlev <- nlevels(fac)
## draw convex hulls
if(any(object@g.args$chullSize > 0)) {
chullpo <- object@s.misc$chullcoord
ppolygons <- lapply(object@adeg.par$ppolygons, FUN = function(x) rep(x, length.out = length(chullpo)))
for(level in 1:nlev) {
chull <- chullpo[[level]]
for(j in 1:length(chull))
panel.polygon(x = chull[[j]][, 1], y = chull[[j]][, 2], border = ppolygons$border[level], col = ppolygons$col[level], lty = ppolygons$lty[level], lwd = ppolygons$lwd[level], alpha = ppolygons$alpha[level])
}}
## draw ellipses
if(object@g.args$ellipseSize > 0) {
ellip <- object@s.misc$ellipses
pellip <- object@adeg.par$pellipses
## setting parameters, number of levels
pellip <- lapply(pellip, FUN = function(x) {if(is.list(x)) return(x) else rep(x, length.out = length(ellip))})
pellip$axes <- lapply(pellip$axes, FUN = function(x) {rep(x, length.out = length(ellip))})
for(level in 1:nlev) {
ell <- ellip[[level]]
if(!(any(is.null(ell))))
if(!any(is.na(ell))) {
panel.polygon(ell$x, ell$y, col = pellip$col[level], lwd = pellip$lwd[level], lty = pellip$lty[level], alpha = pellip$alpha[level], border = pellip$border[level])
if(pellip$axes$draw[level]) {
## draw axes
panel.segments(ell$seg1[1], ell$seg1[2], ell$seg1[3], ell$seg1[4], lwd = pellip$axes$lwd[level], lty = pellip$axes$lty[level], col = pellip$axes$col[level])
panel.segments(ell$seg2[1], ell$seg2[2], ell$seg2[3], ell$seg2[4], lwd = pellip$axes$lwd[level], lty = pellip$axes$lty[level], col = pellip$axes$col[level])
}
}
}
}
## draw stars
if(object@g.args$starSize > 0) {
plines <- lapply(object@adeg.par$plines, FUN = function(x) {rep(x, length.out = nlev)})
xlx <- split(object@stats$coords2d[, 1], fac)
ylx <- split(object@stats$coords2d[, 2], fac)
for(level in 1:nlev) {
xbase <- object@stats$mean2d[level, 1]
ybase <- object@stats$mean2d[level, 2]
xlev <- xlx[[level]]
ylev <- ylx[[level]]
panel.segments(
x0 = xbase, y0 = ybase,
x1 = xbase + object@g.args$starSize * (xlev - xbase),
y1 = ybase + object@g.args$starSize * (ylev - ybase),
lty = plines$lty[level], lwd = plines$lwd[level], col = plines$col[level])
}
}
## draw points
npoints <- nrow(object@stats$coords2d)
ppoints <- object@adeg.par$ppoints
if(length(fac) > 1) {
ppoints <- lapply(object@adeg.par$ppoints, function(x, fac) {
if(length(x) > length(fac))
return(x)
else {
xlev <- rep(x, length.out = nlev)
return(xlev[fac])
}
}, fac = fac)
}
panel.points(x = object@stats$coords2d[, 1], y = object@stats$coords2d[, 2], type = "p", pch = ppoints$pch, cex = ppoints$cex, col = ppoints$col, alpha = ppoints$alpha, fill = ppoints$fill)
## draw labels
if(any(object@adeg.par$plabels$cex > 0)) {
center <- object@stats$mean2d
adeg.panel.label(x = center[, 1], y = center[, 2] , labels = labels, object@adeg.par$plabels)
}
})
triangle.class <- function(dfxyz, fac, wt = rep(1, NROW(fac)), labels = levels(fac), col = NULL, ellipseSize = 1, starSize = 1, chullSize = NULL, adjust = TRUE,
min3d = NULL, max3d = NULL, showposition = TRUE, facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## dfxyz: matrix/data.frame with 3 columns
## min3d, max3d: limits by default: c(0,0,0), c(1,1,1)
thecall <- .expand.call(match.call())
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if(NCOL(fac) == 1)
object <- multi.facets.Tr(thecall, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed multiple fac")
}
## multiple fac
else if(NCOL(fac) > 1) {
object <- multi.variables.Tr(thecall, "fac")
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(adjust = adjust, min3d = min3d, max3d = max3d, ellipseSize = ellipseSize, starSize = starSize, chullSize = chullSize, col = col))
if(storeData)
tmp_data <- list(dfxyz = dfxyz, fac = fac, wt = wt, labels = labels, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(dfxyz = thecall$dfxyz, fac = thecall$fac, wt = thecall$wt, labels = thecall$labels, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "Tr.class", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = match.call())
## preparation
prepare(object)
setlatticecall(object)
if(showposition & add) {
print("cannot show position and add") ## can be done, but modifies the meaning of the superposition
showposition <- FALSE
}
if(showposition)
object <- new(Class = "ADEgS", ADEglist = list("triangle" = object, "positions" = .showpos(object)), positions = rbind(c(0, 0, 1, 1), c(0, 0.7, 0.3, 1)), add = matrix(0, ncol = 2, nrow = 2), Call = match.call())
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/C1.curves.R 0000644 0001762 0000144 00000005126 13742303021 014620 0 ustar ligges users setClass(
Class = "C1.curves",
contains = "C1.curve"
)
setMethod(
f = "panel",
signature = "C1.curves",
definition = function(object, x, y) {
## Drawing dotchart
## x is the index
## y is the score
## get some parameters
nr <- NROW(object@data$score)
nc <- NCOL(object@data$score)
pscore <- object@adeg.par$p1d
ppoints <- lapply(object@adeg.par$ppoints, FUN = function(x) {rep(rep(x, length.out = nc), each = nr)})
plines <- lapply(object@adeg.par$plines, FUN = function(x) {rep(rep(x, length.out = nc), each = nr)})
ymat <- matrix(y, nrow = nr, ncol = nc)
## reorder the values
y <- as.vector(ymat[order(x), ])
x <- sort(x)
## Starts the display
## depends on the parametres horizontal
## rug.draw and reverse are always considered as FALSE
for(i in 1:nc){
idx <- (i - 1)*nr + (1:nr)
if(pscore$horizontal) {
x.tmp <- y[idx]
y.tmp <- x
} else {
x.tmp <- x
y.tmp <- y[idx]
}
panel.lines(x = x.tmp, y = y.tmp, lwd = plines$lwd[idx], lty = plines$lty[idx], col = plines$col[idx])
panel.points(x = x.tmp, y = y.tmp, pch = ppoints$pch[idx], cex = ppoints$cex[idx], col = ppoints$col[idx], alpha = ppoints$alpha[idx])
}
})
s1d.curves <- function(score, at = 1:NROW(score), facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters
thecall <- .expand.call(match.call())
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if(NCOL(score) == 1)
object <- multi.facets.C1(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple scores")
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
if(storeData)
tmp_data <- list(score = score, at = at, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(score = thecall$score, at = thecall$at, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "C1.curves", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = sortparameters$g.args, Call = match.call())
## preparation
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/C1.interval.R 0000644 0001762 0000144 00000013522 13742303021 015134 0 ustar ligges users setClass(
Class = "C1.interval",
contains = "ADEg.C1"
)
setMethod(
f = "initialize",
signature = "C1.interval",
definition = function(.Object, data = list(score = NULL, at = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.C1 initialize
.Object@data$at <- data$at
validObject(.Object)
return(.Object)
})
setMethod(
f = "prepare",
signature = "C1.interval",
definition = function(object) {
name_obj <- deparse(substitute(object))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
if(object@data$storeData) {
score <- object@data$score
at <- object@data$at
} else {
score <- eval(object@data$score, envir = sys.frame(object@data$frame))
at <- eval(object@data$at, envir = sys.frame(object@data$frame))
}
score <- as.matrix(score)[, 1] ## to manage 'score' when it is a data.frame with only one column
## change default for some parameters
adegtot$p1d$rug$draw <- FALSE
if(object@g.args$method == "bars") {
if(is.null(object@adeg.par$parrows$ends))
adegtot$parrows$ends <- "both"
if(is.null(object@adeg.par$parrows$angle))
adegtot$parrows$angle <- 90
}
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
if(object@adeg.par$p1d$horizontal && is.null(object@g.args$ylim))
object@g.args$ylim <- setlimits1D(min(at), max(at), 0, FALSE)
if(!object@adeg.par$p1d$horizontal && is.null(object@g.args$xlim))
object@g.args$xlim <- setlimits1D(min(at), max(at), 0, FALSE)
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f= "panel",
signature = "C1.interval",
definition = function(object, x, y) {
## Drawing interval
## x is the index
## y is the score
lims <- current.panel.limits(unit = "native")
pscore <- object@adeg.par$p1d
plines <- object@adeg.par$plines
parrows <- object@adeg.par$parrows
ppoly <- object@adeg.par$ppolygons
nval <- length(y) %/% 2
score2 <- y[(nval + 1):length(y)]
score1 <- y[1 : nval]
## reorder the values
score1 <- score1[order(x)]
score2 <- score2[order(x)]
x <- sort(x)
## Starts the display
## depends on the parametres horizontal
## rug.draw and reverse are always considered as FALSE
if(pscore$horizontal) {
if(object@g.args$method == "area") {
panel.polygon(x = c(score1, rev(score2)), y = c(x, rev(x)), border = "transparent", col = ppoly$col, alpha = ppoly$alpha)
panel.lines(x = score1, y = x, col = ppoly$border, lty = ppoly$lty, lwd = ppoly$lwd)
panel.lines(x = score2, y = x, col = ppoly$border, lty = ppoly$lty, lwd = ppoly$lwd)
} else if(object@g.args$method == "bars") {
panel.arrows(x0 = score1, y0 = x, x1 = score2, y1 = x, lwd = plines$lwd, col = plines$col,
lty = plines$lty, angle = parrows$angle, length = parrows$length, ends = parrows$ends)
}
} else {
if(object@g.args$method == "area") {
panel.polygon(x = c(x, rev(x)), y = c(score1, rev(score2)), border = "transparent", col = ppoly$col, alpha = ppoly$alpha)
panel.lines(x = x, y = score1, col = ppoly$border, lty = ppoly$lty, lwd = ppoly$lwd)
panel.lines(x = x, y = score2, col = ppoly$border, lty = ppoly$lty, lwd = ppoly$lwd)
} else if(object@g.args$method == "bars") {
panel.arrows(x0 = x, y0 = score1, x1 = x, y1 = score2, lwd = plines$lwd, col = plines$col,
lty = plines$lty, angle = parrows$angle, length = parrows$length, ends = parrows$ends)
}
}
})
s1d.interval <- function(score1, score2, at = 1:NROW(score1), method = c("bars", "area"), facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters
thecall <- .expand.call(match.call())
score1 <- eval(thecall$score1, envir = sys.frame(sys.nframe() + pos))
score2 <- eval(thecall$score2, envir = sys.frame(sys.nframe() + pos))
if(NROW(score1) != NROW(score2))
stop("score1 and score2 should have the same length")
if(NCOL(score1) != NCOL(score2))
stop("score1 and score2 should have the same number of columns")
if((is.data.frame(score1) & NCOL(score1) == 1) | (is.data.frame(score2) & NCOL(score2) == 1))
stop("Not yet implemented for data.frame with only one column, please convert into vector")
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if(NCOL(score1) == 1)
object <- multi.facets.C1(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple scores")
}
## multiple scores
else if(NCOL(score1) > 1) {
object <- multi.score.C1(thecall)
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(method = match.arg(method)))
if(storeData)
tmp_data <- list(score = c(score1, score2), at = at, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(score = call("c", thecall$score1, thecall$score2), at = thecall$at, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "C1.interval", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = match.call())
## preparation
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/S1.class.R 0000644 0001762 0000144 00000021141 13742303021 014431 0 ustar ligges users ###########################################################
## s1d.class ##
###########################################################
setClass(
Class = "S1.class",
contains = "ADEg.S1",
)
setMethod(
f = "initialize",
signature = "S1.class",
definition = function(.Object, data = list(score = NULL, fac = NULL, wt = NULL, labels = NULL, at = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.S1 initialize
.Object@data$fac <- data$fac
.Object@data$wt <- data$wt
.Object@data$labels <- data$labels
return(.Object)
})
setMethod(
f = "prepare",
signature = "S1.class",
definition = function(object) {
name_obj <- deparse(substitute(object))
if(object@data$storeData)
fac <- as.factor(object@data$fac)
else
fac <- as.factor(eval(object@data$fac, envir = sys.frame(object@data$frame)))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
## change default for some parameters
if(adegtot$p1d$horizontal & is.null(object@adeg.par$plabels$srt))
adegtot$plabels$srt <- 90
else if(!adegtot$p1d$horizontal & is.null(object@adeg.par$plabels$srt))
adegtot$plabels$srt <- 0
if(any(adegtot$plabels$cex > 0) & is.null(object@adeg.par$plegend$drawKey)) ## if labels, no legend
adegtot$plegend$drawKey <- FALSE
## setting colors
paramsToColor <- list(ppoints = list(col = object@adeg.par$ppoints$col, fill = object@adeg.par$ppoints$fill),
plabels = list(col = object@adeg.par$plabels$col, boxes = list(border = object@adeg.par$plabels$boxes$border)),
plines = list(col = object@adeg.par$plines$col))
if(!(is.null(object@g.args$col) || (is.logical(object@g.args$col) && !object@g.args$col)))
adegtot <- modifyList(adegtot, col2adepar(ccol = object@g.args$col, pparamsToColor = paramsToColor, nnlev = nlevels(fac)))
## manage limits
if(adegtot$p1d$horizontal & is.null(object@g.args$ylim))
object@g.args$ylim <- c(0, 1)
if(!adegtot$p1d$horizontal & is.null(object@g.args$xlim))
object@g.args$xlim <- c(0, 1)
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
assign(name_obj, object, envir = parent.frame())
})
## TODO: label orientation (works only for horizontal / vertical labels)
setMethod(
f= "panel",
signature = "S1.class",
definition = function(object, x, y) {
if(object@data$storeData) {
fac <- object@data$fac
score <- object@data$score
wt <- object@data$wt
at <- object@data$at
labels <- object@data$labels
} else {
fac <- eval(object@data$fac, envir = sys.frame(object@data$frame))
score <- eval(object@data$score, envir = sys.frame(object@data$frame))
wt <- eval(object@data$wt, envir = sys.frame(object@data$frame))
at <- eval(object@data$at, envir = sys.frame(object@data$frame))
labels <- eval(object@data$labels, envir = sys.frame(object@data$frame))
}
fac <- as.factor(fac)
nlev <- nlevels(fac)
object@stats$means <- meanfacwt(score, fac, wt = wt)
lims <- current.panel.limits(unit = "native")
pscore <- object@adeg.par$p1d
## repeat graphical parameters (one for each level)
ppoints <- lapply(object@adeg.par$ppoints, FUN = function(x) x <- rep(x, length.out = nlev))
plines <- lapply(object@adeg.par$plines, FUN = function(x) x <- rep(x, length.out = nlev))
plabels <- lapply(object@adeg.par$plabels, FUN = function(x) x <- rep(x, length.out = nlev))
plboxes <- lapply(object@adeg.par$plabels$boxes, FUN = function(x) x <- rep(x, length.out = nlev))
plabels$boxes <- plboxes
if(!is.null(labels)) {
## get text sizes for boxes
test <- .textsize(labels, plabels)
w <- test$w
h <- test$h
}
lead <- ifelse(pscore$reverse, -1, 1)
if(pscore$horizontal) {
## horizontal plot
xpoints <- y
## get positions for labels
if(object@g.args$poslabel == "regular") {
spacelab <- diff(lims$xlim) / (nlev + 1)
xlab <- seq(from = lims$xlim[1] + spacelab, by = spacelab, length.out = nlev)[rank(object@stats$means, ties.method = "first")]
} else
xlab <- object@stats$means
## repeat means for each individual
xlablines <- xlab[fac]
## repeat ylab for each individual
ylab <- rep(at, length.out = nlev)
ylablines <- ylab[fac]
## draw lines and labels
ypoints <- object@s.misc$rug
panel.segments(x0 = xpoints, y0 = ypoints, x1 = xlablines, y1 = ylablines, lwd = plines$lwd[fac], col = plines$col[fac], lty = plines$lty[fac])
if(any(ppoints$cex > 0))
panel.points(x = xpoints, y = ypoints, pch = ppoints$pch[fac], cex = ppoints$cex[fac], col = ppoints$col[fac], alpha = ppoints$alpha[fac], fill = ppoints$fill[fac])
if(any(plabels$cex > 0))
adeg.panel.label(x = xlab, y = ylab + lead * h / 2, labels = labels, plabels = plabels)
} else {
## vertical plot
ypoints <- y
## get positions for labels
if(object@g.args$poslabel == "regular") {
spacelab <- diff(lims$ylim) / (nlev + 1)
ylab <- seq(from = lims$ylim[1] + spacelab, by = spacelab, length.out = nlev)[rank(object@stats$means, ties.method = "first")]
} else
ylab <- object@stats$means
## repeat means for each individual
ylablines <- ylab[fac]
## repeat ylab for each individual
xlab <- rep(at, length.out = nlev)
xlablines <- xlab[fac]
## draw lines and labels
xpoints <- object@s.misc$rug
panel.segments(x0 = xpoints, y0 = ypoints, x1 = xlablines, y1 = ylablines, lwd = plines$lwd[fac], col = plines$col[fac], lty = plines$lty[fac])
if(any(ppoints$cex > 0))
panel.points(x = xpoints, y = ypoints, pch = ppoints$pch[fac], cex = ppoints$cex[fac], col = ppoints$col[fac], alpha = ppoints$alpha[fac], fill = ppoints$fill[fac])
if(any(plabels$cex > 0))
adeg.panel.label(x = xlab + lead * w / 2 , y = ylab, labels = labels, plabels = plabels)
}
})
s1d.class <- function(score, fac, wt = rep(1, NROW(fac)), labels = levels(fac), at = 0.5, poslabel = c("regular", "value"), col = NULL,
facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters
thecall <- .expand.call(match.call())
labels <- eval(thecall$labels, envir = sys.frame(sys.nframe() + pos))
fac <- eval(thecall$fac, envir = sys.frame(sys.nframe() + pos))
score <- eval(thecall$score, envir = sys.frame(sys.nframe() + pos))
if(NCOL(fac) == 1) {
fac <- as.factor(fac)
if(length(labels) != nlevels(fac))
stop("wrong number of labels")
}
if(NROW(score) != NROW(fac))
stop("score and factor must have the same number of rows")
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if(NCOL(score) == 1 & NCOL(fac) == 1)
object <- multi.facets.S1(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple scores or fac")
}
## multiple scores
else if(NCOL(score) > 1) {
if(NCOL(fac) == 1)
object <- multi.score.S1(thecall)
else
stop("Multiple scores are not allowed with multiple fac")
}
## multiple fac
else if(NCOL(fac) > 1) {
object <- multi.variables.S1(thecall, "fac")
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(poslabel = match.arg(poslabel), col = col))
if(storeData)
tmp_data <- list(score = score, wt = wt, fac = fac, labels = labels, at = at, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(score = thecall$score, wt = thecall$wt, fac = thecall$fac, labels = thecall$labels, at = thecall$at, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "S1.class", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = match.call())
## preparation
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/S2.image.R 0000644 0001762 0000144 00000015741 14354572721 014437 0 ustar ligges users ##########################################################################
## s.image ##
##########################################################################
## TODO: prendre en comptre les differents z
setClass(
Class = "S2.image",
contains = "ADEg.S2"
)
setMethod(
f = "initialize",
signature = "S2.image",
definition = function(.Object, data = list(dfxy = NULL, z = NULL, xax = 1, yax = 2, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.S2 initialize
.Object@data$z <- data$z
return(.Object)
})
setMethod(
f = "prepare",
signature = "S2.image",
definition = function(object) {
name_obj <- deparse(substitute(object))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
if(object@data$storeData) {
dfxy <- object@data$dfxy
z <- object@data$z
} else {
dfxy <- eval(object@data$dfxy, envir = sys.frame(object@data$frame))
z <- eval(object@data$z, envir = sys.frame(object@data$frame))
}
## change default for some parameters
object@g.args$gridsize <- rep(object@g.args$gridsize, length.out = 2)
if(is.null(object@adeg.par$porigin$include) & (any(names(object@g.args) %in% c("Sp", "nbobject", "outsideLimits"))))
adegtot$porigin$include <- FALSE
if(is.null(object@g.args$breaks))
object@s.misc$breaks.update <- pretty(z, object@g.args$nclass)
else
object@s.misc$breaks.update <- object@g.args$breaks
object@s.misc$breaks.update <- breakstest(object@s.misc$breaks.update, z, n = length(object@s.misc$breaks.update))
n <- length(object@s.misc$breaks.update)
## setting colors
if(!is.null(object@g.args$col)) {
if(length(object@g.args$col) < (n - 1))
stop(paste("not enough colors defined, at least ", (n - 1), " colors expected", sep = ""), call. = FALSE)
adegtot$ppoints$col <- object@g.args$col[1:(n - 1)] ## color given by the user
} else {
if(is.null(object@adeg.par$ppoints$col))
adegtot$ppoints$col <- adegtot$ppalette$quanti(n - 1)
}
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph (provide limits that are used below)
## create a sp grid
minX <- object@g.args$xlim[1]
minY <- object@g.args$ylim[1]
cgridX <- diff(object@g.args$xlim) / object@g.args$gridsize[1]
cgridY <- diff(object@g.args$ylim) / object@g.args$gridsize[2]
gridSp <- SpatialGrid(GridTopology(c(minX, minY), c(cgridX, cgridY), c(object@g.args$gridsize[1], object@g.args$gridsize[2])))
x <- dfxy[, object@data$xax]
y <- dfxy[, object@data$yax]
if(!is.null(object@g.args$outsideLimits)) {
## outside limits are provided by an sp object
whichis <- over(gridSp, object@g.args$outsideLimits)
} else {
## define the outside limits by convex hull
beplot <- cbind(x, y)[chull(cbind(x, y)), ]
extCoord <- SpatialPolygons(list(Polygons(list(Polygon(rbind(cbind(beplot[, 1], beplot[, 2]), beplot[1, ]))), ID = "extcoord")))
whichis <- over(gridSp, extCoord)
}
## NA not handled by panel.levelplot call afterward ==> we remove the points
newgrid <- coordinates(gridSp)
names(newgrid) <- c("x", "y")
lo <- loess(z ~ x + y, span = object@g.args$span) ## Local Polynomial Regression Fitting
predictval <- predict(lo, newdata = newgrid)
predictval[which(is.na(whichis))] <- NA
tokeep <- !is.na(predictval)
predictval <- predictval[tokeep]
newgrid <- newgrid[tokeep, ]
object@stats$value <- predictval
object@s.misc$newgrid <- newgrid
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "S2.image",
definition = function(object, x, y) {
zvalue <- object@stats$value
col <- object@adeg.par$ppoints$col
xx <- object@s.misc$newgrid[, 1]
yy <- object@s.misc$newgrid[, 2]
panel.levelplot(x = xx, y = yy, z = zvalue, subscripts = TRUE, col.regions = col, contour = object@g.args$contour, region = object@g.args$region, labels = object@adeg.par$plabels,
label.style = if(object@adeg.par$plabels$srt == "horizontal") "flat" else "align")
})
s.image <- function(dfxy, z, xax = 1, yax = 2, span = 0.5, gridsize = c(80L, 80L), contour = TRUE, region = TRUE, outsideLimits = NULL, breaks = NULL, nclass = 8,
col = NULL, facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
if(!is.null(outsideLimits)) {
if(!inherits(outsideLimits, "SpatialPolygons"))
stop("limits must be a SpatialPolygons")
}
## evaluation of some parameters (required for multiplot)
thecall <- .expand.call(match.call())
df <- try(as.data.frame(eval(thecall$dfxy, envir = sys.frame(sys.nframe() + pos))), silent = TRUE)
z <- eval(thecall$z, envir = sys.frame(sys.nframe() + pos))
if(inherits(df, "try-error") | is.null(thecall$dfxy)) ## non convenient dfxy argument
stop("non convenient selection for dfxy (can not be converted to dataframe)")
if(NROW(df) != NROW(z))
stop("dfxy and z should have the same number of rows")
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if((length(xax) == 1 & length(yax) == 1) & NCOL(z) == 1)
object <- multi.facets.S2(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple xax/yax or multiple z")
}
## multiple axes
else if((length(xax) > 1 | length(yax) > 1)) {
if(NCOL(z) == 1)
object <- multi.ax.S2(thecall)
else
stop("Multiple xax/yax are not allowed with multiple z")
}
## multiple z
else if(NCOL(z) > 1) {
object <- multi.variables.S2(thecall, "z")
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(breaks = breaks, nclass = nclass, span = span, gridsize = gridsize, outsideLimits = outsideLimits,
contour = contour, region = region, col = col))
if(storeData)
tmp_data <- list(dfxy = dfxy, xax = xax, yax = yax, z = z, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(dfxy = thecall$dfxy, xax = xax, yax = yax, z = thecall$z, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "S2.image", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = as.call(thecall))
## preparation of the graph
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(! add & plot)
print(object)
invisible(object)
}
adegraphics/R/utils.R 0000644 0001762 0000144 00000040121 14354572106 014215 0 ustar ligges users replaceListNull <- function(x, val) {
lapply(x, function(x) {
if (is.list(x)){
replaceListNull(x, val)
} else{
if(is.null(x)) val else(x)
}
})
}
col2adepar <- function(ccol, pparamsToColor, nnlev) {
myCol <- NULL
if(is.logical(ccol) && isTRUE(ccol))
myCol <- adegpar()$ppalette$quali(nnlev)
else
myCol <- rep(ccol, length.out = nnlev)
if(!is.null(myCol))
return(replaceListNull(pparamsToColor, myCol))
else
return()
}
repList <- function(x, times) {
if(times == 1)
l <- x
else {
l <- list()
l <- lapply(1:times, function(i) x)
names(l) <- paste("l", sapply(1:times, function(i) i), sep = "")
}
return(l)
}
.proportional_map <- function(z, maxz) {
## Proportional Symbol Mapping in R
## Susumu Tanimura, Chusi Kuroiwa, Tsutomu Mizota
## Journal of Sratistical Software January 2006
sizes <- (abs(z) / maxz) ^ 0.57
return(sizes)
}
.symbol2pch <- function(symbol){
## give the pch associated to some symbol names (used in *.value)
res <- 22 ## square by default
if(symbol == "circle"){
res <- 21
} else if(symbol == "diamond"){
res <- 23
} else if(symbol == "uptriangle"){
res <- 24
} else if(symbol == "downtriangle"){
res <- 25
}
return(res)
}
.textpos <- function(xx, yy, origin = c(0, 0), n = length(xx)) {
## justification for labels and positions used in s.arrow and s.corcircle
if(is.vector(origin) & length(origin) == 2) {
xx <- xx - origin[1]
yy <- yy - origin[2]
} else
stop("Invalid argument 'origin'")
justif <- matrix(0, nrow = 2, ncol = n)
for(i in 1:n)
## text justification
## move labels (w/2 for left/right or h/2 for bottom/top)
if(yy[i] > 0) {
if(abs(xx[i]) < yy[i])
justif[, i] <- c(0, 1)
else if(xx[i] < 0)
justif[, i] <- c(-1, 0)
else
justif[, i] <- c(1, 0)
} else { ## y<=0
if(abs(xx[i]) < abs(yy[i]))
justif[, i] <- c(0, -1)
else if(xx[i] < 0)
justif[, i] <- c(-1, 0)
else
justif[, i] <- c(1, 0)
}
return(justif)
}
.setposition <- function(position) {
## specify where to draw grid text
if(is.character(position)) {
if(position == "bottomleft") {
posi <- c(unit(0.05, "npc"), unit(0.02, "npc"))
just <- c("left", "bottom")
} else if(position == "bottomright") {
posi <- c(unit(0.95, "npc"), unit(0.02, "npc"))
just <- c("right", "bottom")
} else if(position == "topleft") {
posi <- c(unit(0.05, "npc"), unit(0.98, "npc"))
just <- c("left", "top")
} else if(position == "topright") {
posi <- c(unit(0.95, "npc"), unit(0.98, "npc"))
just <- c("right", "top")
} else
stop("Wrong position")
} else {
posi <- position
just <- c("left", "bottom")
}
return(list(posi = posi, just = just))
}
.getgrid <- function(xlim, ylim, nbgrid = 5, origin, asp) {
## specify where to draw grid lines
if(missing(origin)) {
## i.e. porigin.include = FALSE
origin <- c(pretty(xlim, n = nbgrid)[1], pretty(ylim, n = nbgrid)[1])
}
minX <- xlim[1]
minY <- ylim[1]
maxX <- xlim[2]
maxY <- ylim[2]
origin <- rep(origin, le = 2)
cgrid.y <- diff(pretty(ylim, n = nbgrid))[1]
cgrid.x <- diff(pretty(xlim, n = nbgrid))[1]
if(asp == "iso") {
if(diff(xlim) > diff(ylim))
cgrid.x <- cgrid.y
else
cgrid.y <- cgrid.x
}
if(is.na(cgrid.x) || is.na(cgrid.y))
stop("error while calculating grid")
v0 <- origin[1]
if((origin[1] + cgrid.x) <= maxX)
v0 <- c(v0, seq(origin[1] + cgrid.x, maxX, by = cgrid.x))
if((origin[1] - cgrid.x >= minX))
v0 <- c(v0, seq(origin[1] - cgrid.x, minX, by = -cgrid.x))
v0 <- sort(v0[v0 >= minX & v0 <= maxX])
h0 <- origin[2]
if((origin[2] + cgrid.y) <= maxY)
h0 <- c(h0, seq(origin[2] + cgrid.y, maxY, by = cgrid.y))
if((origin[2] - cgrid.y >= minY))
h0 <- c(h0, seq(origin[2] - cgrid.y, minY, by = -cgrid.y))
h0 <- sort(h0[h0 >= minY & h0 <= maxY])
## clean near-zero values
delta <- diff(range(v0))/nbgrid
if (any(small <- abs(v0) < 1e-14 * delta))
v0[small] <- 0
delta <- diff(range(h0))/nbgrid
if (any(small <- abs(h0) < 1e-14 * delta))
h0[small] <- 0
res <- list(x0 = c(v0, rep(NA, length.out = length(h0))), x1 = c(v0, rep(NA, length.out = length(h0)))
, y0 = c(rep(NA, length.out = length(v0)), h0), y1 = c(rep(NA, length.out = length(v0)), h0), d = signif(cgrid.x, 3))
return(res)
}
setlimits1D <- function(mini, maxi, origin, includeOr) {
## computes limits for 1D plots
if(includeOr) {
newvalu <- .includeorigin(origin, mini, maxi)
mini <- newvalu[1L]
maxi <- newvalu[2L]
}
## add 10% in both directions
if(abs(diff(c(mini, maxi))) > .Machine$double.eps ^ 2)
res <- c(mini, maxi) + c(-1, 1) * diff(c(mini, maxi)) / 10
else { ## if there is only one value
if(mini < .Machine$double.eps ^ 2)
res <- mini + 0.02 * c(-1, 1)
else
res <- mini + c(-1, 1) * abs(mini) / 10
}
return(res)
}
## if aspect.ratio == "iso", we must have identical limits range in x and y
setlimits2D <- function(minX, maxX, minY, maxY, origin = c(0, 0), aspect.ratio = "iso", includeOr) {
origin <- rep(origin, length.out = 2)
if(includeOr) { ## to include origin
newvalu <- list(.includeorigin(origin[1], minX, maxX), .includeorigin(origin[2], minY, maxY))
minX <- newvalu[[1L]][1L]
minY <- newvalu[[2L]][1L]
maxX <- newvalu[[1L]][2L]
maxY <- newvalu[[2L]][2L]
}
## interval sizes
interX <- diff(c(minX, maxX))
interY <- diff(c(minY, maxY))
if(aspect.ratio == "iso") { ## same limits (to have iso square)
biggest <- max(c(max(interX, interY)))
if(which(c(interX, interY) == biggest)[1] == 1) { ## biggest is in X
minY <- minY - (interX - interY) / 2
maxY <- maxY + (interX - interY) / 2
} else { ## biggest is in Y
minX <- minX - (interY - interX) / 2
maxX <- maxX + (interY - interX) / 2
}
}
if(interX > .Machine$double.eps ^ 2 || interY > .Machine$double.eps ^ 2) {
xvalu <- c(minX, maxX) + c(-1, 1) * diff(c(minX, maxX)) / 10
yvalu <- c(minY, maxY) + c(-1, 1) * diff(c(minY, maxY)) / 10
} else {
xvalu <- c(minX, maxX) + c(-1, 1) * abs(max(minX, minY)) / 10
yvalu <- c(minY, maxY) + c(-1, 1) * abs(max(minX, minY)) / 10
}
return(list(xlim = xvalu, ylim = yvalu))
}
.includeorigin <- function(origin, value1, value2) {
## compute limits including origin
return(range(c(origin, value1, value2)))
}
## separates a list of parameters to obtain 4 lists
## the first corresponds to 'padegraphic'
## the second to lattice parameters
## the third to graphics arguments
## the last to unused parameters
sortparamADEg <- function(...) {
if(try(is.list(...), silent = TRUE) == TRUE)
dots <- as.list(...)
else
dots <- list(...)
classtest <- try(list(...), silent = TRUE)
if(inherits(classtest, "try-error"))
stop("wrong parameters list, error in sortparamADEg")
trellis <- list()
adegpar <- list()
g.args <- list()
stats <- list()
s.misc <- list()
rest <- list()
if(length(dots)) {
## compare to trellis parameters
select <- separation(... , pattern = 1)
trellis <- select[[1L]]
rest <- select[[2L]]
## removing sp.layout items
if(length(rest)) {
indix2 <- pmatch(names(rest), "sp.layout")
if(any(!is.na(indix2))) {
whereis <- which(!is.na(indix2))
g.args <- list("sp.layout" = rest[[whereis]])
rest <- rest[-whereis]
}
}
## compare to adegpar parameters (pattern = 0 by default)
if(length(rest)) {
select <- separation(rest)
adegpar <- select[[1L]]
rest <- select[[2L]]
}
## removing g.args items
if(length(rest)) {
pattern.g.args <- c("xlim", "ylim", "main", "sub", "xlab", "ylab", "Sp", "nbobject", "samelimits", "scales", "key", "colorkey", "col")
pmatch.g.args <- pmatch(names(rest), pattern.g.args)
indix <- which(!is.na(pmatch.g.args))
pmatch.g.args <- pmatch.g.args[!is.na(pmatch.g.args)]
if(length(indix)) {
g.args <- c(g.args, rest[indix])
names(g.args)[(1 + length(g.args) - length(pmatch.g.args)):length(g.args)] <- c(pattern.g.args[pmatch.g.args])
rest <- rest[-indix]
}
}
}
return(list(adepar = adegpar, trellis = trellis, g.args = g.args, rest = rest))
}
########################################################################
### FROM CAR >= 3.1-1 (or MAPTOOLS before 2022-10-22) #######
########################################################################
.pointLabel <- function(x, y = NULL, labels, width, height, limits, xyAspect, allowSmallOverlap = FALSE, trace = FALSE) {
## xyAspect: width_in/height_inch of the current panel
## limits would have been setted before (in ADEg.S2 prepare)
## width and height de rectangle en 'npc' (fig in original code__maptools package)
## labels <- graphicsAnnot(labels)
## to do before
## TODO redo
boundary <- c(limits$xlim, limits$ylim)
toUnityCoords <- function(xy) {
return(list(x = (xy$x - boundary[1]) / (boundary[2] - boundary[1]) * xyAspect, y = (xy$y - boundary[3]) / (boundary[4] - boundary[3]) / xyAspect))
}
toUserCoords <- function(xy) {
return(list(x = boundary[1] + xy$x / xyAspect * (boundary[2] - boundary[1]), y = boundary[3] + xy$y * xyAspect * (boundary[4] - boundary[3])))
}
z <- xy.coords(x, y, recycle = TRUE)
z <- toUnityCoords(z)
x <- z$x
y <- z$y
if(allowSmallOverlap)
nudgeFactor <- 0.02
n_labels <- length(x)
gen_offset <- function(code) {
c(-1, -1, -1, 0, 0, 1, 1, 1)[code] * (width / 2) + (0 + 1i) * c(-1, 0, 1, -1, 1, -1, 0, 1)[code] * height / 2
}
rect_intersect <- function(xy1, offset1, xy2, offset2) { ##intersections calculations
w <- pmin(Re(xy1 + offset1 / 2), Re(xy2 + offset2 / 2)) - pmax(Re(xy1 - offset1 / 2), Re(xy2 - offset2 / 2))
h <- pmin(Im(xy1 + offset1 / 2), Im(xy2 + offset2 / 2)) - pmax(Im(xy1 - offset1 / 2), Im(xy2 - offset2 / 2))
w[w <= 0] <- 0
h[h <= 0] <- 0
w * h
}
nudge <- function(offset) {
doesIntersect <- rect_intersect(xy[rectidx1] + offset[rectidx1], rectv[rectidx1], xy[rectidx2] + offset[rectidx2], rectv[rectidx2]) > 0
pyth <- abs(xy[rectidx1] + offset[rectidx1] - xy[rectidx2] - offset[rectidx2]) / nudgeFactor
eps <- 1e-10
for (i in which(doesIntersect & pyth > eps)) {
idx1 <- rectidx1[i]
idx2 <- rectidx2[i]
vect <- (xy[idx1] + offset[idx1] - xy[idx2] - offset[idx2]) / pyth[idx1]
offset[idx1] <- offset[idx1] + vect
offset[idx2] <- offset[idx2] - vect
}
offset
}
objective <- function(gene) { ## score calculations
offset <- gen_offset(gene)
if(allowSmallOverlap)
offset <- nudge(offset)
if(!is.null(rectidx1))
area <- sum(rect_intersect(xy[rectidx1] + offset[rectidx1], rectv[rectidx1], xy[rectidx2] + offset[rectidx2], rectv[rectidx2]))
else
area <- 0
n_outside <- sum(Re(xy + offset - rectv / 2) < 0 | Re(xy + offset + rectv / 2) > xyAspect | Im(xy + offset - rectv / 2) < 0 | Im(xy + offset + rectv / 2) > 1 / xyAspect)
if(is.na(n_outside))
n_outside <- 0 ## TODO: to correct, n_outside sometimes NA
res <- 1000 * area + n_outside
res
}
xy <- x + (0 + 1i) * y
rectv <- width + (0 + 1i) * height
rectidx1 <- rectidx2 <- array(0, (length(x)^2 - length(x)) / 2)
k <- 0
for(i in 1:length(x)) {
for(j in seq(len = (i - 1))) {
k <- k + 1
rectidx1[k] <- i
rectidx2[k] <- j
}
}
canIntersect <- rect_intersect(xy[rectidx1], 2 * rectv[rectidx1], xy[rectidx2], 2 * rectv[rectidx2]) > 0
rectidx1 <- rectidx1[canIntersect] ## which intersect with those in rectidx2
rectidx2 <- rectidx2[canIntersect]
if(trace)
cat("possible intersects = ", length(rectidx1), "\n")
if(trace)
cat("portion covered = ", sum(rect_intersect(xy, rectv, xy, rectv)), "\n")
## simulated annealing
SANN <- function() {
## initialisation
gene <- rep(8, n_labels) ## 'rep' is best to begin at center
score <- objective(gene) ## initial score
bestgene <- gene
bestscore <- score
T <- 2.5 ## pseudo initial temperature
for (i in 1:50) {
k <- 1
for (j in 1:50) {
newgene <- gene
newgene[sample(1:n_labels, 1)] <- sample(1:8, 1)
newscore <- objective(newgene) ## score
if(newscore <= score || runif(1) < exp((score - newscore) / T)) {
## empirical law to accept differences: if 'newscore' is better or with a proba exp(Dscorce/T)
k <- k + 1
score <- newscore
gene <- newgene
}
if(score <= bestscore) {
bestscore <- score
bestgene <- gene
}
if(bestscore == 0 || k == 10)
break
}
if(bestscore == 0) ## no variation
break
if(trace)
cat("overlap area =", bestscore, "\n")
T <- 0.9 * T ## the temperature regularly decreases to become stable
}
if(trace)
cat("overlap area =", bestscore, "\n")
nx <- Re(xy + gen_offset(bestgene))
ny <- Im(xy + gen_offset(bestgene))
return(list(x = nx, y = ny))
}
xy <- SANN()
xy <- toUserCoords(xy)
return(xy)
}
## check if z is included in breaks
## no default value
breakstest <- function(breaki, zi, n) {
breaki <- sort(breaki, decreasing = TRUE)
if(max(breaki) < max(zi) | min(breaki) > min(zi)) {
zbis <- pretty(zi, n)
if(max(breaki) < max(zi)) {
warning(paste("breaks given does not include z limits, break added ", max(zbis), sep = " "), call. = FALSE)
breaki <- c((max(zbis)), breaki)
}
if(min(breaki) > min(zi)) {
warning(paste("breaks given does not include z limits, break added ", min(zbis), sep = " "), call. = FALSE)
breaki <- c(breaki, min(zbis))
}
}
return(breaki)
}
################ for axis.....
## extract from
## Lattice Graphs { Control of Panel of Panel & Strip Borders
## J H Maindonald
## http://www.maths.anu.edu.au/~johnm
axis.L <- function(side, ..., line.col) {
col <- trellis.par.get("axis.text")$col
axis.default(side, ..., line.col = col)
}
.textsize <- function(labels, plabels) {
## can be improved see s1d.barchart for non-trivial rotation
srt <- 0
if(is.numeric(plabels$srt))
srt <- plabels$srt[1]
else {
if(plabels$srt[1] == "horizontal")
srt <- 0
else if(plabels$srt[1] == "vertical")
srt <- 90
}
if(srt == 90) {
h <- (convertHeight(stringWidth(labels), unitTo = "native", valueOnly = TRUE) + convertHeight(stringWidth("h"), unitTo = "native", valueOnly = TRUE) / 2) * rep(plabels$cex, length.out = length(labels))
w <- (convertWidth(stringHeight(labels), unitTo = "native", valueOnly = TRUE) + convertWidth(stringHeight("m"), unitTo = "native", valueOnly = TRUE) / 2) * rep(plabels$cex, length.out = length(labels))
} else { ## if 0 or an other angle
w <- (convertWidth(stringWidth(labels), unitTo = "native", valueOnly = TRUE) + convertWidth(stringWidth("m"), unitTo = "native", valueOnly = TRUE) / 2) * rep(plabels$cex, length.out=length(labels))
h <- (convertHeight(stringHeight(labels), unitTo = "native", valueOnly = TRUE) + convertHeight(stringHeight("h"), unitTo = "native", valueOnly = TRUE) / 2) * rep(plabels$cex, length.out=length(labels))
}
return(list(w = w, h = h, srt = srt))
}
.expand.call <- function(thecall, eval.formals = TRUE) {
## takes a call as argument and return a "cleaned" call where argument names are filled, and unset non empty formals are added and eventually evaluated using the call as environment
## supplied args:
ans <- as.list(thecall)
## possible args:
frmls <- formals(as.character(ans[[1]]))
## remove formal args with no presets:
frmls <- frmls[!sapply(frmls, is.symbol)]
add <- which(!(names(frmls) %in% names(ans)))
frmls <- frmls[add]
if(eval.formals) {
## evaluate the call locally and recursively
frmls.new <- lapply(frmls, function(x) do.call("substitute", list(x, c(ans[-1], frmls))))
while(!isTRUE(all.equal(frmls, frmls.new))) {
frmls <- frmls.new
frmls.new <- lapply(frmls, function(x) do.call("substitute", list(x, c(ans[-1], frmls))))
}
}
return(c(ans, frmls))
}
adegraphics/R/utilstriangle.R 0000644 0001762 0000144 00000011772 13742303021 015741 0 ustar ligges users ## projection dans triangle
## de la base e1=c(1,0,0), e2=c(0,1,0), e3=c(0,0,1)
## a c(1/sqrt(3), 1/sqrt(3), 1/sqrt(3)), c(-1/sqrt(2),1/sqrt(2),0), c(-1/sqrt(6),-1/sqrt(6),2/sqrt(6))
.coordtotriangleUnity <- function(mdata3) {
x <- mdata3[, 1]
y <- mdata3[, 2]
z <- mdata3[, 3]
return(cbind(0, (y - x) / sqrt(2), (2 * z - x - y) / sqrt(6)))
}
## projection depend also on scale defined by min and max
## need to rescale coordinates to maintain distances
## in the new space
.coordtotriangleM <- function(ta, mini3, maxi3) {
data3d <- t(apply(ta, 1, FUN = function(x) {
x <- (x - mini3) / (maxi3 - mini3)
return(x / sum(x))}))
return(.coordtotriangleUnity(data3d))
}
## TODO: redo this, from ade4
.trranges <- function(df, adjust = TRUE, min3 = NULL, max3 = NULL) {
ta <- sweep(df, 1, rowSums(df), "/")
if(ncol(ta) != 3)
stop("Non convenient data")
if(min(ta) < 0)
stop("Non convenient data")
if((!is.null(min3)) & (!is.null(max3)))
adjust <- TRUE
cal <- matrix(0, 9, 3)
tb <- t(apply(ta, 1, FUN = function(x) {x / sum(x)}))
mini <- apply(tb, 2, min)
maxi <- apply(tb, 2, max)
mini <- (floor(mini / 0.1)) / 10
maxi <- (floor(maxi / 0.1) + 1) / 10
mini[mini < 0] <- 0
maxi[maxi > 1] <- 1
if(!is.null(min3))
mini <- min3
if(!is.null(max3))
maxi <- min3
ampli <- maxi - mini
amplim <- max(ampli)
if(!all(ampli == amplim)) {
for (j in 1:3) {
k <- amplim - ampli[j]
while (k > 0) {
if((k > 0) & (maxi[j] < 1)) {
maxi[j] <- maxi[j] + 0.1
k <- k - 1
}
if((k > 0) & (mini[j] > 0)) {
mini[j] <- mini[j] - 0.1
k <- k - 1
}
}
}
}
cal[1, 1] <- mini[1]
cal[1, 2] <- mini[2]
cal[1, 3] <- 1 - cal[1, 1] - cal[1, 2]
cal[2, 1] <- mini[1]
cal[2, 2] <- maxi[2]
cal[2, 3] <- 1 - cal[2, 1] - cal[2, 2]
cal[3, 1] <- maxi[1]
cal[3, 2] <- mini[2]
cal[3, 3] <- 1 - cal[3, 1] - cal[3, 2]
cal[4, 1] <- mini[1]
cal[4, 3] <- mini[3]
cal[4, 2] <- 1 - cal[4, 1] - cal[4, 3]
cal[5, 1] <- mini[1]
cal[5, 3] <- maxi[3]
cal[5, 2] <- 1 - cal[5, 1] - cal[5, 3]
cal[6, 1] <- maxi[1]
cal[6, 3] <- mini[3]
cal[6, 2] <- 1 - cal[6, 1] - cal[6, 3]
cal[7, 2] <- mini[2]
cal[7, 3] <- mini[3]
cal[7, 1] <- 1 - cal[7, 2] - cal[7, 3]
cal[8, 2] <- mini[2]
cal[8, 3] <- maxi[3]
cal[8, 1] <- 1 - cal[8, 2] - cal[8, 3]
cal[9, 2] <- maxi[2]
cal[9, 3] <- mini[3]
cal[9, 1] <- 1 - cal[9, 2] - cal[9, 3]
mini <- apply(cal, 2, min)
mini <- round(mini, digits = 4)
maxi <- apply(cal, 2, max)
maxi <- round(maxi, digits = 4)
ampli <- maxi - mini
if(!adjust) {
mini <- c(0, 0, 0)
maxi <- c(1, 1, 1)
}
return(list(mini = mini, maxi = maxi))
}
## ## calcul maximum et minimum pour triangle
## ## data as list
## .trranges <- function(data, mini, maxi, adjust){
## if(is.null(mini))mini <-c(0,0,0)
## if(is.null(maxi))maxi <-c(1,1,1)
## if(adjust){
## if(!is.null(data$frame))
## ta <- t(apply(eval(data$ta, envir = sys.frame(data$frame)), 1, function(x) x/sum(x)))
## else
## ta <- t(apply(data$ta, 1, function(x)x/sum(x)))
## tb <- t(apply(ta, 1, function(x) x/sum(x)))
## mini <- apply(tb, 2, min)
## maxi <- apply(tb, 2, max)
## mini <- (floor(mini/0.1))/10
## maxi <- (floor(maxi/0.1) + 1)/10
## mini[mini < 0] <- 0
## maxi[maxi > 1] <- 1
## }
## ampli <- maxi-mini
## amplim <- max(ampli)
## if(! all(ampli == amplim)){#on doit avoir la meme chose.
## for(i in 1:3){
## diffv <- amplim -ampli[i]/2
## mini[i] <- mini[i]-diffv
## maxi[i] <- maxi[i]+diffv
## if(mini[i]<0){
## maxi[i] <- maxi[i]-mini[i]
## mini[i] <- 0
## }
## if(maxi[i]>1){
## mini[i] <- mini[i]-(maxi[i]-1)
## maxi[i] <- 1
## }
## }
## }
## if(any(mini<0) | any(maxi>1))
## stop("wrong calculus for limits", call. = FALSE)
## ##"ici partie cal non reprise. a voir ensuite
## return(list(mini=mini, maxi=maxi))
## }
.showpos <- function(object) {
## from ade4
mini <- object@g.args$min3d
maxi <- object@g.args$max3d
w <- matrix(0, 3, 3)
w[1, 1] <- mini[1]
w[1, 2] <- mini[2]
w[1, 3] <- maxi[3]
w[2, 1] <- maxi[1]
w[2, 2] <- mini[2]
w[2, 3] <- mini[3]
w[3, 1] <- mini[1]
w[3, 2] <- maxi[2]
w[3, 3] <- mini[3]
smallT <- .coordtotriangleM(matrix(c(0, 0, 1, 1, 0, 0, 0, 1, 0), byrow = TRUE, ncol = 3), mini3 = rep(0, 3), maxi3 = rep(1, 3))[, -1]
A <- smallT[1, ]
B <- smallT[2, ]
C <- smallT[3, ]
shadowS <- .coordtotriangleM(w, c(0, 0, 0), c(1, 1, 1))[, -1]
a <- shadowS[1, ]
b <- shadowS[2, ]
c <- shadowS[3, ]
aa <- xyplot(0 ~ 0, xlim = c(-0.7, 0.7), ylim = c(-0.55, 0.9), aspect = "iso", scale = list(draw = FALSE), xlab = NULL, ylab = NULL, par.settings = list(axis.line = list(col = "transparent")),
panel = function(...) {
panel.polygon(c(A[1], B[1], C[1]), c(A[2], B[2], C[2]))
panel.polygon(c(a[1], b[1], c[1]), c(a[2], b[2], c[2]), col = grey(0.75))
})
invisible(aa)
}
adegraphics/R/T.image.R 0000644 0001762 0000144 00000016457 13742303021 014344 0 ustar ligges users setClass(
Class = "T.image",
contains = "ADEg.T"
)
setMethod(
f = "prepare",
signature = "T.image",
definition = function(object) {
name_obj <- deparse(substitute(object))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
if(object@data$storeData) {
coordsx <- object@data$coordsx
coordsy <- object@data$coordsy
z <- as.vector(as.matrix(object@data$dftab))
dftab <- object@data$dftab
labelsx <- object@data$labelsx
labelsy <- object@data$labelsy
} else {
coordsx <- eval(object@data$coordsx, envir = sys.frame(object@data$frame))
coordsy <- eval(object@data$coordsy, envir = sys.frame(object@data$frame))
z <- as.vector(as.matrix(eval(object@data$dftab, envir = sys.frame(object@data$frame))))
dftab <- eval(object@data$dftab, envir = sys.frame(object@data$frame))
labelsx <- eval(object@data$labelsx, envir = sys.frame(object@data$frame))
labelsy <- eval(object@data$labelsy, envir = sys.frame(object@data$frame))
}
if(is.null(object@g.args$breaks))
object@s.misc$breaks.update <- pretty(z, object@g.args$nclass)
else
object@s.misc$breaks.update <- object@g.args$breaks
object@s.misc$breaks.update <- breakstest(object@s.misc$breaks.update, z, n = length(object@s.misc$breaks.update))
n <- length(object@s.misc$breaks.update)
## setting colors
if(!is.null(object@g.args$col)) {
if(length(object@g.args$col) < (n - 1))
stop(paste("not enough colors defined, at least ", (n - 1), " colors expected", sep = ""), call. = FALSE)
adegtot$ppoints$col <- object@g.args$col[1:(n - 1)] ## color given by the user
} else {
if(is.null(object@adeg.par$ppoints$col))
adegtot$ppoints$col <- adegtot$ppalette$quanti(n - 1)
}
## inspired by level.colors from lattice
if(adegtot$plegend$drawColorKey)
adegtot$ptable$y$pos <- "left"
if(is.null(object@adeg.par$pgrid$col))
adegtot$pgrid$col <- "black"
if(is.null(object@adeg.par$pgrid$lwd))
adegtot$pgrid$lwd <- 0.6
if(is.null(object@adeg.par$pgrid$draw))
adegtot$pgrid$draw <- FALSE ## no cells border by default
if(is.null(labelsx))
adegtot$ptable$x$tck <- 0
if(is.null(labelsy))
adegtot$ptable$y$tck <- 0
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
## TODO: improve the code to avoid some repetition with the parent function
wx <- range(coordsx)
dx <- (diff(wx) + 1) / length(coordsx)
wy <- range(coordsy)
dy <- (diff(wy) + 1) / length(coordsy)
## add an half cell at both sides
object@g.args$xlim <- wx + c(-0.5, 0.5) * dx
object@g.args$ylim <- wy + c(-0.5, 0.5) * dy
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "T.image",
definition = function(object, x, y) {
## x is data$coordsx and y is data$coordsy
if(object@data$storeData)
dftab <- as.matrix(object@data$dftab)
else
dftab <- as.matrix(eval(object@data$dftab, envir = sys.frame(object@data$frame)))
xx <- x[!is.na(x)]
yy <- y[!is.na(y)]
zz <- as.vector(dftab)
dx <- diff(sort(xx)) / 2
dy <- diff(sort(yy)) / 2
dx <- c(dx[1], dx)
dy <- c(dy[1], dy)
## draw values
panel.levelplot.raster(x = xx[col(dftab)], y = yy[row(dftab)], z = zz, subscripts = TRUE, col.regions = object@adeg.par$ppoints$col,
at = object@s.misc$breaks.update, contour = FALSE, region = TRUE)
## draw grid (cells border)
if(object@adeg.par$pgrid$draw) {
xbis <- c(min(xx) - dx[1], xx + dx, max(xx) + dx[length(dx)])
ybis <- c(min(yy) - dy[1], yy + dy, max(yy) + dy[length(dy)])
panel.abline(h = ybis, v = xbis, col = object@adeg.par$pgrid$col, lwd = object@adeg.par$pgrid$lwd, lty = object@adeg.par$pgrid$lty)
}
})
## TODO: decider quelle classe on prend en compte
## a faire: verifier espacement correct de coordsx et coordsy
## que faire de la sous grille?
## attention, coordsx et coordsy ne serve qu'a donner l'ordre de trace, ils seront considere comme egalement espace, sinon fonction a revoir
table.image <- function(dftab, coordsx = 1:ncol(as.matrix(dftab)), coordsy = nrow(as.matrix(dftab)):1, labelsx = NULL, labelsy = NULL, nclass = 3, breaks = NULL, col = NULL, plot = TRUE,
storeData = TRUE, add = FALSE, pos = -1, ...) {
## 4 different types can be used as tab :
## distance matrix (dist), contingency table (table), data.frame or matrix
thecall <- .expand.call(match.call())
dftab <- eval(thecall$dftab, envir = sys.frame(sys.nframe() + pos))
## modify coordsx/coordsy positions (we use only the order not the values)
thecall$coordsx <- call("rank", thecall$coordsx, ties.method = "first")
thecall$coordsy <- call("rank", thecall$coordsy, ties.method = "first")
if(inherits(dftab, "dist")) {
if(missing(labelsx)){
thecall$labelsx <- labelsx <- NULL
if(!is.null(attr(dftab, "Labels")))
if(storeData)
labelsx <- attr(dftab, "Labels")
else
thecall$labelsx <- call("attr", thecall$dftab, "Labels")
}
if(missing(labelsy)){
thecall$labelsy <- labelsy <- NULL
if(!is.null(attr(dftab, "Labels")))
if(storeData)
labelsy <- attr(dftab, "Labels")
else
thecall$labelsy <- call("attr", thecall$dftab, "Labels")
}
## coordsx and coordsy should be identical for dist objects (symmetric)
thecall$coordsx <- call(":", 1, call("attr", thecall$dftab, "Size"))
thecall$coordsy <- call(":", call("attr", thecall$dftab, "Size"), 1)
} else { ## data.frame, matrix, table
if(missing(labelsy)){
thecall$labelsy <- labelsy <- NULL
if(!is.null(rownames(dftab)))
if(storeData)
labelsy <- rownames(dftab)
else
thecall$labelsy <- call("rownames", thecall$dftab)
}
if(missing(labelsx)){
thecall$labelsx <- labelsx <- NULL
if(!is.null(colnames(dftab)))
if(storeData)
labelsx <- colnames(dftab)
else
thecall$labelsx <- call("colnames", thecall$dftab)
}
}
## parameters sorted
sortparameters <- sortparamADEg(...)
## creation of the ADEg object
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
g.args <- c(sortparameters$g.args, list(breaks = breaks, nclass = nclass, col = col))
if(storeData)
tmp_data <- list(dftab = dftab, coordsx = coordsx, coordsy = coordsy, labelsx = labelsx, labelsy = labelsy, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(dftab = thecall$dftab, coordsx = thecall$coordsx, coordsy = thecall$coordsy, labelsx = thecall$labelsx, labelsy = thecall$labelsy, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "T.image", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = match.call())
## preparation of the graph
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
else
if(plot)
print(object)
invisible(object)
}
adegraphics/R/addhist.R 0000644 0001762 0000144 00000015230 13742303021 014464 0 ustar ligges users setMethod(
f = "addhist",
signature = "ADEg.S2",
definition = function(object, bandwidth, gridsize = 60, kernel = "normal", cbreaks = 2, storeData = TRUE, plot = TRUE, pos = -1, ...) {
thecall <- .expand.call(match.call())
dfcall <- thecall$object
dfxycall <- substitute(dfcall@data$dfxy)
if(!(inherits(object, "ADEg.S2")))
stop("Only implemented for 'ADEg.S2' object")
if(storeData) {
dfxy <- object@data$dfxy
xax <- object@data$xax
yax <- object@data$yax
} else {
dfxy <- eval(object@data$dfxy, envir = sys.frame(object@data$frame))
xax <- eval(object@data$xax, envir = sys.frame(object@data$frame))
yax <- eval(object@data$yax, envir = sys.frame(object@data$frame))
}
## sorting parameters
graphsnames <- c(all.names(substitute(object)), "densX", "densY", "link")
sortparameters <- sortparamADEgS(..., graphsnames = graphsnames)
params <- vector("list", 4)
names(params) <- graphsnames
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
update(object, sortparameters[[1]], plot = FALSE)
## setting positions
positions <- layout2position(matrix(c(2, 4, 1, 3), 2, 2, byrow = TRUE), c(3, 1) / 2, c(3, 1) / 2, FALSE)
## grid computation
xlimX <- object@g.args$xlim
ylimY <- object@g.args$ylim
breaks <- object@s.misc$backgrid
cgrid <- breaks$d / cbreaks
bb1 <- range(breaks$x0[!is.na(breaks$x0)])
bb2 <- range(breaks$y0[!is.na(breaks$y0)])
breaksX <- seq(from = bb1[1], to = bb1[2], by = cgrid)
breaksY <- seq(from = bb2[1], to = bb2[2], by = cgrid)
while(min(breaksX) > xlimX[1])
breaksX <- c((min(breaksX) - cgrid), breaksX)
while(max(breaksX) < xlimX[2])
breaksX <- c(breaksX, (max(breaksX) + cgrid))
while(min(breaksY) > ylimY[1])
breaksY <- c((min(breaksY) - cgrid), breaksY)
while(max(breaksY) < ylimY[2])
breaksY <- c(breaksY, (max(breaksY) + cgrid))
## limits and graduation
dfxaxcall <- call("[", dfxycall, 1:NROW(eval(dfxycall)), substitute(xax))
dfxaxcallplus <- call("~", dfxaxcall, 1)
dfyaxcall <- call("[", dfxycall, 1:NROW(eval(dfxycall)), substitute(yax))
dfyaxcallplus <- call("~", dfyaxcall, 1)
limcalX <- hist(dfxy[, xax], breaksX, plot = FALSE)
limcalXcall <- call("hist", substitute(dfxaxcall), breaksX, plot = FALSE)
limcalY <- hist(dfxy[, yax], breaksY, plot = FALSE)
limcalYcall <- call("hist", substitute(dfyaxcall), breaksY, plot = FALSE)
top <- 1.1 * max(c(limcalX$counts, limcalY$counts))
xlimY <- ylimX <- c(0, top)
drawLines <- pretty(0:top)
drawLines <- drawLines[-c(1, length(drawLines))]
if(!missing(bandwidth)) {
densiX <- bkde(dfxy[, xax], kernel = kernel, bandwidth = bandwidth, gridsize = gridsize)
densiXcall <- call("bkde", substitute(dfxaxcall), kernel = kernel, bandwidth = bandwidth, gridsize = gridsize)
densiY <- bkde(dfxy[, yax], kernel = kernel, bandwidth = bandwidth, gridsize = gridsize)
densiYcall <- call("bkde", substitute(dfyaxcall), kernel = kernel, bandwidth = bandwidth, gridsize = gridsize)
} else {
densiX <- bkde(dfxy[, xax], kernel = kernel, gridsize = gridsize)
densiXcall <- call("bkde", substitute(dfxaxcall), kernel = kernel, gridsize = gridsize)
densiY <- bkde(dfxy[, yax], kernel = kernel, gridsize = gridsize)
densiYcall <- call("bkde", substitute(dfyaxcall), kernel = kernel, gridsize = gridsize)
}
## trellis creation
g2 <- xyplot(dfxy[, xax] ~ 1, xlim = xlimX, ylim = ylimX, horizontal = TRUE, scales = list(draw = FALSE), xlab = NULL, ylab = NULL, histValues = limcalX,
drawLines = drawLines, densi = densiX, params = sortparameters[[2]],
panel = function(histValues, horizontal, drawLines, densi, params) adeg.panel.hist(histValues = histValues, horizontal = horizontal,
drawLines = drawLines, densi = densi, params = params))
g2$call <- call("xyplot", dfxaxcallplus, xlim = substitute(xlimX), ylim = substitute(ylimX), horizontal = TRUE, scales = list(draw = FALSE), xlab = NULL, ylab = NULL,
histValues = limcalXcall, drawLines = substitute(drawLines), densi = substitute(densiXcall), params = sortparameters[[2]],
panel = function(histValues, horizontal, drawLines, densi, params) adeg.panel.hist(histValues = histValues, horizontal = horizontal,
drawLines = drawLines, densi = densi, params = params))
g3 <- xyplot(dfxy[, yax] ~ 1, xlim = xlimY, ylim = ylimY, horizontal = FALSE, scales = list(draw = FALSE), xlab = NULL, ylab = NULL, histValues = limcalY,
drawLines = drawLines, densi = densiY, params = sortparameters[[3]],
panel = function(histValues, horizontal, drawLines, densi, params) adeg.panel.hist(histValues = histValues, horizontal = horizontal,
drawLines = drawLines, densi = densi, params = params))
g3$call <- call("xyplot", dfyaxcallplus, xlim = substitute(xlimY), ylim = substitute(ylimY), horizontal = FALSE, scales = list(draw = FALSE), xlab = NULL, ylab = NULL,
histValues = limcalYcall, drawLines = substitute(drawLines), densi = substitute(densiYcall), params = sortparameters[[3]],
panel = function(histValues, horizontal, drawLines, densi, params) adeg.panel.hist(histValues = histValues, horizontal = horizontal,
drawLines = drawLines, densi = densi, params = params))
g4 <- xyplot(1 ~ 1, xlim = xlimY, ylim = ylimX, scales = list(draw = FALSE), xlab = NULL, ylab = NULL, drawLines = drawLines, params = sortparameters[[4]],
panel = function(drawLines, params) adeg.panel.join(drawLines = drawLines, params = params))
g4$call <- call("xyplot", 1 ~ 1, xlim = substitute(xlimY), ylim = substitute(ylimX), scales = list(draw = FALSE), xlab = NULL, ylab = NULL, drawLines = substitute(drawLines),
params = sortparameters[[4]], panel = function(drawLines, params) adeg.panel.join(drawLines = drawLines, params = params))
## ADEgS creation and display
obj <- new(Class = "ADEgS", ADEglist = list(object, g2, g3, g4), positions = positions, add = matrix(0, ncol = 4, nrow = 4), Call = match.call())
names(obj) <- graphsnames
if(plot)
print(obj)
invisible(obj)
}) adegraphics/R/Tr.match.R 0000644 0001762 0000144 00000012202 14354572102 014530 0 ustar ligges users setClass(
Class = "Tr.match",
contains = "ADEg.Tr",
)
setMethod(
f = "initialize",
signature = "Tr.match",
definition = function(.Object, data = list(dfxyz = NULL, labels = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.Tr initialize
.Object@data$labels <- data$labels
return(.Object)
})
setMethod(
f = "prepare",
signature = "Tr.match",
definition = function(object) {
name_obj <- deparse(substitute(object))
if(object@data$storeData) {
df <- object@data$dfxyz
} else {
df <- eval(object@data$dfxyz, envir = sys.frame(object@data$frame))
}
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
## calculate 2D coordinates
df <- sweep(df, 1, rowSums(df), "/")
n <- NROW(df) / 2
df1 <- df[1:n,]
df2 <- df[(1 + n):(2 * n), ]
object@stats$coords2d1 <- .coordtotriangleM(df1, mini3 = object@g.args$min3d, maxi3 = object@g.args$max3d)[, 2:3]
object@stats$coords2d2 <- .coordtotriangleM(df2, mini3 = object@g.args$min3d, maxi3 = object@g.args$max3d)[, 2:3]
## never optimized labels for triangle.match
object@adeg.par$plabels$optim <- FALSE
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "Tr.match",
definition = function(object, x, y) {
if(object@data$storeData) {
labels <- object@data$labels
df <- object@data$dfxyz
} else {
labels <- eval(object@data$labels, envir = sys.frame(object@data$frame))
df <- eval(object@data$dfxyz, envir = sys.frame(object@data$frame))
}
if(NROW(df) %% 2)
stop("error in panel method : unable to split the two datasets")
## draw points
if(any(object@adeg.par$ppoints$cex > 0))
do.call("panel.points", c(list(x = object@stats$coords2d1[, 1], y = object@stats$coords2d1[, 2]), object@adeg.par$ppoints))
## draw arrows
panel.arrows(x0 = object@stats$coords2d1[, 1], y0 = object@stats$coords2d1[, 2] , y1 = object@stats$coords2d2[, 2], x1 = object@stats$coords2d2[, 1],
angle = object@adeg.par$parrows$angle, length = object@adeg.par$parrows$length,
ends = object@adeg.par$parrows$end, lwd = object@adeg.par$plines$lwd, col = object@adeg.par$plines$col,
lty = object@adeg.par$plines$lty)
if(any(object@adeg.par$plabels$cex > 0)) {
xlab <- (object@stats$coords2d1[, 1] + object@stats$coords2d2[, 1]) / 2
ylab <- (object@stats$coords2d1[, 2] + object@stats$coords2d2[, 2]) / 2
adeg.panel.label(xlab, ylab, labels = labels, object@adeg.par$plabels)
}
})
triangle.match <- function(dfxyz1, dfxyz2, labels = row.names(as.data.frame(dfxyz1)), min3d = NULL, max3d = NULL, adjust = TRUE,
showposition = TRUE, facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters
thecall <- .expand.call(match.call())
data1 <- try(as.data.frame(eval(thecall$dfxyz1, envir = sys.frame(sys.nframe() + pos))), silent = TRUE)
data2 <- try(as.data.frame(eval(thecall$dfxyz2, envir = sys.frame(sys.nframe() + pos))), silent = TRUE)
if(inherits(data1, "try-error") || inherits(data2, "try-error") || is.null(thecall$dfxyz1) || is.null(thecall$dfxyz2)) ## wrong conversion
stop("non convenient selection for dfxyz1 or dfxyz2 (can not be converted to dataframe)")
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
object <- multi.facets.Tr(thecall, samelimits = sortparameters$g.args$samelimits)
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(adjust = adjust, min3d = min3d, max3d = max3d))
if(storeData)
tmp_data <- list(dfxyz = rbind(dfxyz1, dfxyz2), labels = labels, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(dfxyz = call("rbind", thecall$dfxyz1, thecall$dfxyz2), labels = thecall$labels, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "Tr.match", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = match.call())
## preparation
prepare(object)
setlatticecall(object)
if(showposition & add) {
print("cannot show position and add") ## can be done, but modifies the meaning of the superposition
showposition <- FALSE
}
if(showposition)
object <- new(Class = "ADEgS", ADEglist = list("triangle" = object, "positions" = .showpos(object)), positions = rbind(c(0, 0, 1, 1), c(0, 0.7, 0.3, 1)), add = matrix(0, ncol = 2, nrow = 2), Call = match.call())
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/C1.dotplot.R 0000644 0001762 0000144 00000010321 13742303021 014767 0 ustar ligges users setClass(
Class = "C1.dotplot",
contains = "ADEg.C1"
)
setMethod(
f = "initialize",
signature = "C1.dotplot",
definition = function(.Object, data = list(score = NULL, at = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.C1 initialize
.Object@data$at <- data$at
validObject(.Object)
return(.Object)
})
setMethod(
f = "prepare",
signature = "C1.dotplot",
definition = function(object) {
nameobj <- deparse(substitute(object))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
if(object@data$storeData) {
score <- object@data$score
at <- object@data$at
} else {
score <- eval(object@data$score, envir = sys.frame(object@data$frame))
at <- eval(object@data$at, envir = sys.frame(object@data$frame))
}
score <- as.matrix(score)[, 1] ## to manage 'score' when it is a data.frame with only one column
## change some defaults
adegtot$p1d$rug$draw <- FALSE
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
if(object@adeg.par$p1d$horizontal && is.null(object@g.args$ylim))
object@g.args$ylim <- setlimits1D(min(at), max(at), 0, FALSE)
if(!object@adeg.par$p1d$horizontal && is.null(object@g.args$xlim))
object@g.args$xlim <- setlimits1D(min(at), max(at), 0, FALSE)
assign(nameobj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "C1.dotplot",
definition = function(object, x, y) {
## Drawing dotchart
## x is the index
## y is the score
## get some parameters
pscore <- object@adeg.par$p1d
ppoints <- lapply(object@adeg.par$ppoints, FUN = function(x) {rep(x, length.out = length(x))})
plines <- lapply(object@adeg.par$plines, FUN = function(x) {rep(x, length.out = length(x))})
## reorder the values
y <- y[order(x)]
x <- sort(x)
## Starts the display
## depends on the parametres horizontal
## rug.draw and reverse are always considered as FALSE
if(pscore$horizontal) {
x.tmp <- y
y.tmp <- x
panel.segments(object@adeg.par$porigin$origin[1], y.tmp, x.tmp, y.tmp, lwd = plines$lwd, lty = plines$lty, col = plines$col)
} else {
x.tmp <- x
y.tmp <- y
panel.segments(x.tmp, object@adeg.par$porigin$origin[1], x.tmp, y.tmp, lwd = plines$lwd, lty = plines$lty, col = plines$col)
}
panel.dotplot(x = x.tmp, y = y.tmp, horizontal = pscore$horizontal, pch = ppoints$pch, cex = ppoints$cex, col = ppoints$col, alpha = ppoints$alpha, col.line = "transparent")
})
s1d.dotplot <- function(score, at = 1:NROW(score), facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters
thecall <- .expand.call(match.call())
score <- eval(thecall$score, envir = sys.frame(sys.nframe() + pos))
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if(NCOL(score) == 1)
object <- multi.facets.C1(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple scores")
}
## multiple scores
else if(NCOL(score) > 1) {
object <- multi.score.C1(thecall)
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
if(storeData)
tmp_data <- list(score = score, at = at, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(score = thecall$score, at = thecall$at, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "C1.dotplot", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = sortparameters$g.args, Call = match.call())
## preparation
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/S2.value.R 0000644 0001762 0000144 00000015466 14354572717 014502 0 ustar ligges users #########################################################
### s.value ##
#########################################################
## TO DO: calcul place legend, taille des points
## Remarque ==> pour size, si couleur selon <0 ou >0 il faut s'assurer que 0 ne sera donc pas dans un intervalle? (inclus ex [-1, 1])
setClass(
Class = "S2.value",
contains = "ADEg.S2"
)
setMethod(
f = "initialize",
signature = "S2.value",
definition = function(.Object, data = list(dfxy = NULL, z = NULL, xax = 1, yax = 2, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.S2 initialize
.Object@data$z <- data$z
return(.Object)
})
setMethod(
f = "prepare",
signature = "S2.value",
definition = function(object) {
name_obj <- deparse(substitute(object))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
if(object@data$storeData)
z <- object@data$z
else
z <- eval(object@data$z, envir = sys.frame(object@data$frame))
if(is.null(object@adeg.par$ppoints$alpha))
adegtot$ppoints$alpha <- 0.9
if(is.null(object@adeg.par$ppoints$cex))
adegtot$ppoints$cex <- 1
if(is.null(object@adeg.par$porigin$include) & (any(names(object@g.args) %in% c("Sp", "nbobject"))))
adegtot$porigin$include <- FALSE
if(is.null(object@g.args$breaks))
object@s.misc$breaks.update <- pretty(z, object@g.args$nclass)
else
object@s.misc$breaks.update <- object@g.args$breaks
object@s.misc$breaks.update <- breakstest(object@s.misc$breaks.update, z, n = length(object@s.misc$breaks.update))
n <- length(object@s.misc$breaks.update)
## symbols for z = center
if(!is.null(object@g.args$centerpar)) {
default <- list(pch = 4, cex = 1, col = "black")
if(is.list(object@g.args$centerpar))
object@g.args$centerpar <- modifyList(default, object@g.args$centerpar, keep.null = TRUE)
else
object@g.args$centerpar <- default
}
if(is.null(object@adeg.par$psub$position))
adegtot$psub$position <- "topleft"
## setting colors
if(!is.null(object@g.args$col)) {
switch(object@g.args$method,
size = {
if(length(object@g.args$col) != 2)
stop("if method size choosen, col vector should be size 2", call. = FALSE)
adegtot$ppoints$col <- object@g.args$col ## color given by the user
},
color = {
if(length(object@g.args$col) < (n - 1))
stop(paste("not enough colors defined for method color, at least ", (n - 1), " colors expected", sep = ""), call. = FALSE)
adegtot$ppoints$fill <- object@g.args$col[1:(n - 1)] ## color given by the user
})
} else {
if(object@g.args$method == "color")
adegtot$ppoints$fill <- adegtot$ppalette$quanti(n - 1)
else
adegtot$ppoints$col <- adegtot$ppalette$quanti(2)
}
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
## never optimized labels for s.value
object@adeg.par$plabels$optim <- FALSE
assign(name_obj, object, envir = parent.frame())
})
## Draw symbols according to the different methods
setMethod(
f = "panel",
signature = "S2.value",
definition = function(object, x, y) {
if(object@data$storeData)
zorig <- object@data$z
else
zorig <- eval(object@data$z, envir = sys.frame(object@data$frame))
adeg.panel.values(x = x, y = y, z = zorig, method = object@g.args$method, symbol = object@g.args$symbol, ppoints = object@adeg.par$ppoints,
breaks = object@s.misc$breaks.update, centerpar = object@g.args$centerpar, center = object@g.args$center)
})
s.value <- function(dfxy, z, breaks = NULL, xax = 1, yax = 2, method = c("size", "color"), symbol = c("square", "circle", "diamond", "uptriangle", "downtriangle"),
col = NULL, nclass = 4, center = 0, centerpar = NULL, facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters
thecall <- .expand.call(match.call())
thecall$method <- match.arg(method)
if(thecall$method == "color") {
if(center != 0 | !is.null(centerpar))
warning("'center' and 'centerpar' are not used with 'color' method", call. = FALSE)
center <- 0
centerpar <- NULL
}
thecall$center <- center
thecall$centerpar <- centerpar
thecall$symbol <- match.arg(symbol)
df <- try(as.data.frame(eval(thecall$dfxy, envir = sys.frame(sys.nframe() + pos))), silent = TRUE)
z <- eval(thecall$z, envir = sys.frame(sys.nframe() + pos))
if(inherits(df, "try-error") | is.null(thecall$dfxy)) ## non convenient dfxy argument
stop("non convenient selection for dfxy (can not be converted to dataframe)", call. = FALSE)
if(NROW(df) != NROW(z))
stop("dfxy and z should have the same number of rows", call. = FALSE)
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if((length(xax) == 1 & length(yax) == 1) & NCOL(z) == 1)
object <- multi.facets.S2(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple xax/yax or multiple z", call. = FALSE)
}
## multiple axes
else if((length(xax) > 1 | length(yax) > 1)) {
if(NCOL(z) == 1)
object <- multi.ax.S2(thecall)
else
stop("Multiple xax/yax are not allowed with multiple z", call. = FALSE)
}
## multiple z
else if(NCOL(z) > 1) {
object <- multi.variables.S2(thecall, "z")
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(method = thecall$method, symbol = thecall$symbol, center = center, breaks = breaks, col = col,
nclass = nclass, centerpar = centerpar))
if(storeData)
tmp_data <- list(dfxy = dfxy, xax = xax, yax = yax, z = z, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(dfxy = thecall$dfxy, xax = xax, yax = yax, z = thecall$z, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "S2.value", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = as.call(thecall))
## preparation of the graph
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(! add & plot)
print(object)
invisible(object)
}
adegraphics/R/ADEg.T.R 0000644 0001762 0000144 00000022263 13742303021 014012 0 ustar ligges users ####################################################
## Table/matrix/dist plot ##
####################################################
setClass(
Class = "ADEg.T",
contains = c("ADEg", "VIRTUAL"),
slots = c(data = "list")
)
setMethod(
f = "initialize",
signature = "ADEg.T",
definition = function(.Object, data = list(dftab = NULL, coordsx = NULL, coordsy = NULL, labelsx = NULL, labelsy = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, ...) ## ADEg initialize
.Object@data <- data
return(.Object)
})
setMethod(
f = "prepare",
signature = "ADEg.T",
definition = function(object) {
name_obj <- deparse(substitute(object))
if(object@data$storeData){
coordsx <- object@data$coordsx
coordsy <- object@data$coordsy
} else {
coordsx <- eval(object@data$coordsx, envir = sys.frame(object@data$frame))
coordsy <- eval(object@data$coordsy, envir = sys.frame(object@data$frame))
}
## cell size
object@s.misc$axes$dx <- ifelse(length(coordsx) == 1, 1, diff(range(coordsx)) / length(coordsx))
object@s.misc$axes$dy <- ifelse(length(coordsy) == 1, 1, diff(range(coordsy)) / length(coordsy))
## default margins
if(object@adeg.par$ptable$x$pos == "top" & object@adeg.par$ptable$margin$top <= 5)
object@adeg.par$ptable$margin$top <- 12
if(object@adeg.par$ptable$x$pos == "bottom" & object@adeg.par$ptable$margin$bottom <= 5)
object@adeg.par$ptable$margin$bottom <- 12
if(object@adeg.par$ptable$y$pos == "right" & object@adeg.par$ptable$margin$right <= 5)
object@adeg.par$ptable$margin$right <- 12
if(object@adeg.par$ptable$y$pos == "left" & object@adeg.par$ptable$margin$left <= 5)
object@adeg.par$ptable$margin$left <- 12
object@g.args$xlim <- range(coordsx) + c(-1, 1) * object@s.misc$axes$dx
object@g.args$ylim <- range(coordsy) + c(-1, 1) * object@s.misc$axes$dy
object@trellis.par <- c(object@trellis.par, list(clip = list(panel = "off"),
layout.heights = list(top.padding = object@adeg.par$ptable$margin$top, bottom.padding = object@adeg.par$ptable$margin$bottom),
layout.widths = list(left.padding = object@adeg.par$ptable$margin$left, right.padding = object@adeg.par$ptable$margin$right)))
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panelbase",
signature = "ADEg.T",
definition = function(object, x, y) {
callNextMethod()
## draw the box and the segments
grid <- object@adeg.par$pgrid
## draw grid
if(object@data$storeData) {
xpos <- object@data$coordsx
ypos <- object@data$coordsy
labelsx <- object@data$labelsx
labelsy <- object@data$labelsy
} else {
xpos <- eval(object@data$coordsx, envir = sys.frame(object@data$frame))
ypos <- eval(object@data$coordsy, envir = sys.frame(object@data$frame))
labelsx <- eval(object@data$labelsx, envir = sys.frame(object@data$frame))
labelsy <- eval(object@data$labelsy, envir = sys.frame(object@data$frame))
}
nx <- length(xpos)
ny <- length(ypos)
## draw grid (except for T.image)
if(grid$draw & !inherits(object, "T.image"))
panel.segments(
x0 = c(xpos, rep(min(xpos)- object@s.misc$axes$dx, length.out = ny)),
x1 = c(xpos, rep(max(xpos) + object@s.misc$axes$dx, length.out = ny)),
y0 = c(rep(min(ypos) - object@s.misc$axes$dy, length.out = nx), ypos),
y1 = c(rep(max(ypos) + object@s.misc$axes$dy, length.out = nx), ypos),
col = grid$col, lwd = grid$lwd, lty = grid$lty)
## draw ticks
limis <- current.panel.limits()
## if in ptable$x (or y) $tck; number without unit, considered as 'mm', otherwise used with the unit defined by user
dxticks <- convertHeight(if(is.unit(object@adeg.par$ptable$x$tck)) object@adeg.par$ptable$x$tck else unit(object@adeg.par$ptable$x$tck, "mm"), unitTo = "native", valueOnly = TRUE)
dyticks <- convertWidth(if(is.unit(object@adeg.par$ptable$y$tck)) object@adeg.par$ptable$y$tck else unit(object@adeg.par$ptable$y$tck, "mm"), unitTo = "native", valueOnly = TRUE)
## get parameters
linespar <- modifyList(as.list(object@trellis.par$axis.line), trellis.par.get()$axis.line, keep.null = TRUE)
textspar <- modifyList(as.list(object@trellis.par$axis.text), trellis.par.get()$axis.text, keep.null = TRUE)
if(textspar$cex > 0 & dyticks > 0) {
## draw ticks for y
y0axes <- ypos
## regular positions
y1axes <- seq(from = min(ypos), to = max(ypos), length.out = ny)[rank(ypos, ties.method = "first")]
yylab <- y1axes
drawing <- FALSE
if(any(object@adeg.par$ptable$y$pos == "right")) {
if(any(is.na(object@adeg.par$ptable$y$adj)))
adj <- c(0, 0.5)
else
adj <- object@adeg.par$ptable$y$adj
x0axes <- limis$xlim[2]
x1axes <- limis$xlim[2] + dyticks
if(textspar$cex)
xxlab <- limis$xlim[2] + 1.1 * dyticks
drawing <- TRUE
}
if(any(object@adeg.par$ptable$y$pos == "left")) {
if(any(is.na(object@adeg.par$ptable$y$adj)))
adj <- c(1, 0.5)
else
adj <- object@adeg.par$ptable$y$adj
x0axes <- limis$xlim[1]
x1axes <- limis$xlim[1] - dyticks
if(textspar$cex)
xxlab <- limis$xlim[1] - 1.1 * dyticks
drawing <- TRUE
}
if(drawing) {
panel.segments(x0 = x0axes, y0 = y0axes, x1 = x1axes, y1 = y1axes,
lwd = linespar$lwd, lty = linespar$lty, alpha = linespar$alpha, col = linespar$col)
if(textspar$cex)
panel.text(labels = labelsy, x = xxlab, y = yylab, cex = textspar$cex, col = textspar$col, font = textspar$font,
lineheight = textspar$lineheight, alpha = textspar$alpha, adj = adj, srt = object@adeg.par$ptable$x$srt)
}
}
if(textspar$cex > 0 & dxticks > 0) {
## draw ticks for x
x0axes <- xpos
## regular positions
x1axes <- seq(from = min(xpos), to = max(xpos), length.out = nx)[rank(xpos, ties.method = "first")]
xxlab <- x1axes
drawing <- FALSE
if(any(object@adeg.par$ptable$x$pos == "top")) {
if(any(is.na(object@adeg.par$ptable$x$adj)))
adj <- c(0, 0.5)
else
adj <- object@adeg.par$ptable$x$adj
y0axes <- limis$ylim[2]
y1axes <- limis$ylim[2] + dxticks
if(textspar$cex > 0)
yylab <- limis$ylim[2] + 1.1 * dxticks
drawing <- TRUE
}
if(any(object@adeg.par$ptable$x$pos == "bottom")) {
if(any(is.na(object@adeg.par$ptable$x$adj)))
adj <- c(1, 0.5)
else
adj <- object@adeg.par$ptable$x$adj
y0axes <- limis$ylim[1]
y1axes <- limis$ylim[1] - dxticks
if(textspar$cex > 0)
yylab <- limis$ylim[1] - 1.1 * dxticks
drawing <- TRUE
}
if(drawing) {
panel.segments(x0 = x0axes, y0 = y0axes, x1 = x1axes, y1 = y1axes,
lwd = linespar$lwd, lty = linespar$lty, alpha = linespar$alpha, col = linespar$col)
if(textspar$cex)
panel.text(labels = labelsx, x = xxlab, y = yylab, cex = textspar$cex, col = textspar$col, font = textspar$font,
lineheight = textspar$lineheight, alpha = textspar$alpha, adj = adj, srt = object@adeg.par$ptable$y$srt)
}
}
})
setMethod(
f = "setlatticecall",
signature = "ADEg.T",
definition = function(object) {
name_obj <- deparse(substitute(object))
## background and box
object@trellis.par$panel.background$col <- object@adeg.par$pbackground$col
if(!object@adeg.par$pbackground$box)
object@trellis.par$axis.line$col <- "transparent"
else
object@trellis.par$axis.line$col <- "black"
arguments <- list(
par.settings = object@trellis.par,
key = createkey(object),
legend = createcolorkey(object),
scales = list(draw = FALSE),
panel = function(...) {
panelbase(object, ...)
panel(object, ...)
})
object@lattice.call$arguments <- arguments
object@lattice.call$graphictype <- "xyplot"
## get lattice arguments (set unspecified to NULL)
argnames <- c("main", "sub", "xlab", "ylab")
largs <- object@g.args[argnames]
names(largs) <- argnames
## add xlim and ylim if not NULL
if("xlim" %in% names(object@g.args))
largs["xlim"] <- object@g.args["xlim"]
if("ylim" %in% names(object@g.args))
largs["ylim"] <- object@g.args["ylim"]
object@lattice.call$arguments <- c(object@lattice.call$arguments, largs, list(strip = FALSE))
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "gettrellis",
signature = "ADEg.T",
definition = function(object) {
if(object@data$storeData) {
xdata <- object@data$coordsx
ydata <- object@data$coordsy
} else {
xdata <- eval(object@data$coordsx, envir = sys.frame(object@data$frame))
ydata <- eval(object@data$coordsy, envir = sys.frame(object@data$frame))
}
tmptrellis <- do.call(what = object@lattice.call$graphictype, args = c(formula(ydata ~ xdata), object@lattice.call$arguments, environment()))
return(tmptrellis)
})
adegraphics/R/ADEg.C1.R 0000644 0001762 0000144 00000024362 14354571670 014075 0 ustar ligges users ####################################################
## Curves Plot ##
## 1d score represents in 2D plot ##
####################################################
setClass(
Class = "ADEg.C1",
contains = c("ADEg", "VIRTUAL"),
slots = c(data = "list")
)
setMethod(
f = "initialize",
signature = "ADEg.C1",
definition = function(.Object, data = list(score = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, ...) ## ADEg initialize
.Object@data <- data
return(.Object)
})
setMethod(
f = "prepare",
signature = "ADEg.C1",
definition = function(object) {
## prepare: grid calculations
## reset limits and sets axis information for lattice
name_obj <- deparse(substitute(object))
if(object@data$storeData)
score <- object@data$score
else
score <- eval(object@data$score, envir = sys.frame(object@data$frame))
if(inherits(object, "C1.barchart") | inherits(object, "C1.curve") | inherits(object, "C1.dotplot") | inherits(object, "C1.interval")) {
if(object@data$storeData)
at <- object@data$at
else
at <- eval(object@data$at, envir = sys.frame(object@data$frame))
}
if(inherits(object, "C1.curves"))
score <- as.matrix(score)
else
score <- as.matrix(score)[, 1] ## to manage 'score' when it is a data.frame with only one column
if(inherits(object, "C1.interval")) ## to manage only the first score in c(score1, score2)
score <- score[1:(length(score) / 2)]
## limits and scale
if(!is.null(object@s.misc$hori.update))
if(object@s.misc$hori.update != object@adeg.par$p1d$horizontal) {
aux <- object@g.args$xlim
object@g.args$xlim <- object@g.args$ylim
object@g.args$ylim <- aux
}
object@s.misc$hori.update <- object@adeg.par$p1d$horizontal
minX <- min(score)
maxX <- max(score)
if(object@adeg.par$p1d$horizontal & !is.null(object@g.args$xlim)) {
minX <- object@g.args$xlim[1]
maxX <- object@g.args$xlim[2]
}
if(!object@adeg.par$p1d$horizontal & !is.null(object@g.args$ylim)) {
minX <- object@g.args$ylim[1]
maxX <- object@g.args$ylim[2]
}
origin <- object@adeg.par$porigin
lim <- setlimits1D(minX, maxX, origin = origin$origin[1], includeOr = origin$include)
## compute grid size
tmp <- pretty(lim, n = object@adeg.par$pgrid$nint)
if(!origin$include)
origin$origin[1] <- tmp[1]
cgrid <- diff(tmp)[1]
if(is.na(cgrid))
stop("error while calculating grid")
## compute grid location
v0 <- origin$origin[1]
if((origin$origin[1] + cgrid) <= lim[2])
v0 <- c(v0, seq(origin$origin[1] + cgrid, lim[2], by = cgrid))
if((origin$origin[1] - cgrid >= lim[1]))
v0 <- c(v0, seq(origin$origin[1] - cgrid, lim[1], by = -cgrid))
v0 <- sort(v0[v0 >= lim[1] & v0 <= lim[2]])
## clean near-zero values
delta <- diff(range(v0))/object@adeg.par$pgrid$nint
if (any(small <- abs(v0) < 1e-14 * delta))
v0[small] <- 0
object@s.misc$backgrid <- list(x = v0, d = cgrid)
## object@adeg.par$paxes has priority over object@g.args$scales
object@adeg.par$paxes$aspectratio <- "fill"
scalesandlab <- modifyList(as.list(object@g.args$scales), object@adeg.par$paxes, keep.null = TRUE)
if(!scalesandlab$draw) {
scalesandlab$x$draw <- FALSE
scalesandlab$y$draw <- FALSE
}
lead <- ifelse(object@adeg.par$p1d$reverse, 1 , -1)
if(object@adeg.par$p1d$horizontal) {
## draw axes for horizontal plot
if(is.null(scalesandlab$x$at))
scalesandlab$x$at <- object@s.misc$backgrid$x
if(is.null(object@g.args$xlim))
object@g.args$xlim <- lim
} else {
## draw axes for vertical plot
if(is.null(scalesandlab$y$at))
scalesandlab$y$at <- object@s.misc$backgrid$x
if(is.null(object@g.args$ylim))
object@g.args$ylim <- lim
}
object@g.args$scales <- scalesandlab
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panelbase",
signature = "ADEg.C1",
definition = function(object, x, y) {
## Formula defined in gettrellis
## if horizontal, x is score and y is a vector with repetitions of origin
## if vertical, this is the inverse
grid <- object@adeg.par$pgrid
porigin <- object@adeg.par$porigin
pscore <- object@adeg.par$p1d
lims <- current.panel.limits(unit = "native")
## for rugs
if(pscore$rug$draw & (pscore$rug$tck != 0)) {
plines <- object@adeg.par$plines
if(!is.null(object@data$fac)) {
## C1.density or C1.gauss (different colors for rugs)
if(object@data$storeData)
fac <- as.factor(object@data$fac)
else
fac <- as.factor(eval(object@data$fac, envir = sys.frame(object@data$frame)))
plines <- lapply(plines, FUN = function(x) {return(rep(x, length.out = nlevels(fac))[fac])})
}
}
lead <- ifelse(pscore$reverse, -1, 1)
if(pscore$horizontal) {
## horizontal plot
## draw grid
if(grid$draw)
panel.segments(x0 = object@s.misc$backgrid$x , x1 = object@s.misc$backgrid$x, y0 = lims$ylim[1], y1 = lims$ylim[2], col = grid$col, lty = grid$lty, lwd = grid$lwd)
## draw origin
panel.abline(
v = if(porigin$draw) porigin$origin else NULL,
h = if(pscore$rug$draw & pscore$rug$line) object@s.misc$rug else NULL,
col = porigin$col, lwd = porigin$lwd, lty = porigin$lty, alpha = porigin$alpha)
## draw rug
if(pscore$rug$draw & (pscore$rug$tck != 0)) {
ref <- ifelse(pscore$reverse, lims$ylim[2], lims$ylim[1])
## tick end and starting points
start <- object@s.misc$rug
end <- start - pscore$rug$tck * lead * abs(start - ref)
start <- convertUnit(unit(start, "native"), unitTo = "npc", axisFrom = "y", valueOnly = TRUE)
end <- convertUnit(unit(end, "native"), unitTo = "npc", axisFrom = "y", valueOnly = TRUE)
do.call("panel.rug", c(list(x = y, start = start, end = end), plines))
}
} else {
## vertical plot
## draw grid
if(grid$draw)
panel.segments(y0 = object@s.misc$backgrid$x , y1 = object@s.misc$backgrid$x, x0 = lims$xlim[1], x1 = lims$xlim[2], col = grid$col, lty = grid$lty, lwd = grid$lwd)
## draw origin
panel.abline(
h = if(porigin$draw) porigin$origin else NULL,
v = if(pscore$rug$draw & pscore$rug$line) object@s.misc$rug else NULL,
col = porigin$col, lwd = porigin$lwd, lty = porigin$lty, alpha = porigin$alpha)
## draw rug
if(pscore$rug$draw && pscore$rug$tck != 0) {
ref <- ifelse(pscore$reverse, lims$xlim[2], lims$xlim[1])
## tick end and starting points
start <- object@s.misc$rug
end <- start - pscore$rug$tck * lead * abs(start - ref)
start <- convertUnit(unit(start, "native"), unitTo = "npc", axisFrom = "x", valueOnly = TRUE)
end <- convertUnit(unit(end, "native"), unitTo = "npc", axisFrom = "x", valueOnly = TRUE)
do.call("panel.rug", c(list(y = y, start = start, end = end), plines))
}
}
## indicate grid size (d = **)
if(grid$draw & (grid$text$cex > 0)) {
text.pos <- .setposition(grid$text$pos)
textgrid <- textGrob(label = paste("d =", object@s.misc$backgrid$d), x = text.pos$posi[1], y = text.pos$posi[2], gp = gpar(cex = grid$text$cex, col = grid$text$col), name = "gridtext")
grid.rect(x = text.pos$posi[1], y = text.pos$posi[2], width = grobWidth(textgrid), height = grobHeight(textgrid), gp = gpar(fill = object@adeg.par$pbackground$col, alpha = 0.8, col = "transparent"))
grid.draw(textgrid)
}
callNextMethod()
})
setMethod(
f = "setlatticecall",
signature = "ADEg.C1",
definition = function(object) {
## arguments recurrents de la liste, pas les limites car elles seront definis ensuite
name_obj <- deparse(substitute(object))
## grid background and box
object@trellis.par$panel.background$col <- object@adeg.par$pbackground$col
if(!object@adeg.par$pbackground$box)
object@trellis.par$axis.line$col <- "transparent"
else
object@trellis.par$axis.line$col <- "black"
arguments <- list(
par.settings = object@trellis.par,
scales = object@g.args$scales,
aspect = object@adeg.par$paxes$aspectratio,
key = createkey(object),
axis = axis.L, ## see utils.R
panel = function(...) {
panelbase(object, ...) ## grid,
panel(object, ...) ## call to C1.panel function, for slabel and ADEg.C1 class of graphs
})
object@lattice.call$arguments <- arguments
object@lattice.call$graphictype <- "xyplot"
## get lattice arguments (set unspecified to NULL)
argnames <- c("main", "sub", "xlab", "ylab")
largs <- object@g.args[argnames]
names(largs) <- argnames
## add xlim and ylim if not NULL
if("xlim" %in% names(object@g.args))
largs["xlim"] <- object@g.args["xlim"]
if("ylim" %in% names(object@g.args))
largs["ylim"] <- object@g.args["ylim"]
object@lattice.call$arguments <- c(object@lattice.call$arguments, largs, list(strip = FALSE))
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "gettrellis",
signature = "ADEg.C1",
definition = function(object) {
if(object@data$storeData)
score <- object@data$score
else
score <- eval(object@data$score, envir = sys.frame(object@data$frame))
if(inherits(object, "C1.curves"))
score <- as.matrix(score)
else
score <- as.matrix(score)[, 1] ## to manage 'score' when it is a data.frame with only one column
xdata <- rep(1, length(score))
if(inherits(object, "C1.barchart") | inherits(object, "C1.curve") | inherits(object, "C1.dotplot") | inherits(object, "C1.interval")) {
if(object@data$storeData)
xdata <- object@data$at
else
xdata <- eval(object@data$at, envir = sys.frame(object@data$frame))
}
fml <- as.formula(score ~ xdata)
tmptrellis <- do.call(what = object@lattice.call$graphictype, args = c(fml, object@lattice.call$arguments, environment()))
return(tmptrellis)
})
adegraphics/R/Tr.label.R 0000644 0001762 0000144 00000017416 13742303021 014517 0 ustar ligges users ###############################################
## triangle.label ##
###############################################
setClass(
Class = "Tr.label",
contains = "ADEg.Tr"
)
setMethod(
f = "initialize",
signature = "Tr.label",
definition = function(.Object, data = list(dfxyz = NULL, labels = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.Tr initialize
.Object@data$labels <- data$labels
return(.Object)
})
setMethod(
f = "prepare",
signature = "Tr.label",
definition = function(object) {
name_obj <- deparse(substitute(object))
if(object@data$storeData) {
labels <- object@data$labels
df <- object@data$dfxyz
} else {
labels <- eval(object@data$labels, envir = sys.frame(object@data$frame))
df <- eval(object@data$dfxyz, envir = sys.frame(object@data$frame))
}
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
## change default for some parameters
if((is.null(object@adeg.par$plabels$boxes$draw) & adegtot$plabels$optim) || (is.null(object@adeg.par$plabels$boxes$draw) & length(labels) > 1000))
adegtot$plabels$boxes$draw <- FALSE
if(object@g.args$addmean) {
default <- list(pch = 20, col = "black", cex = 2)
if(is.list(object@g.args$meanpar))
object@g.args$meanpar <- modifyList(default, object@g.args$meanpar, keep.null = TRUE)
else {
if(!is.null(object@g.args$meanpar))
stop("meanpar must be a list of graphical parameters (pch, col, cex)", call. = FALSE)
else
object@g.args$meanpar <- default
}
}
if(object@g.args$addaxes | object@g.args$addmean) {
## lines (axes or mean)
default <- list(col = "black", lwd = 1, lty = 1)
if(is.list(object@g.args$axespar))
object@g.args$axespar <- modifyList(default, object@g.args$axespar, keep.null = TRUE)
else {
if(!is.null(object@g.args$axespar))
stop("axespar must be a list of graphical parameters (lwd, col, lty)", call. = FALSE)
else
object@g.args$axespar <- default
}
## point (axes or mean)
default <- list(pch = 20, col = "black", cex = 2)
if(is.list(object@g.args$meanpar))
object@g.args$meanpar <- modifyList(default, object@g.args$meanpar, keep.null = TRUE)
else {
if(!is.null(object@g.args$meanpar))
stop("meanpar must be a list of graphical parameters (pch, col, cex)", call. = FALSE)
else
object@g.args$meanpar <- default
}
}
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
## calculate 2D coordinates
df <- sweep(df, 1, rowSums(df), "/")
object@stats$coords2d <- .coordtotriangleM(df, mini3 = object@g.args$min3d, maxi3 = object@g.args$max3d)[, 2:3]
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "Tr.label",
definition = function(object, x, y) {
if(object@data$storeData) {
labels <- object@data$labels
df <- object@data$dfxyz
} else {
labels <- eval(object@data$labels, envir = sys.frame(object@data$frame))
df <- eval(object@data$dfxyz, envir = sys.frame(object@data$frame))
}
## draw points and labels
if(any(object@adeg.par$ppoints$cex > 0))
panel.points(object@stats$coords2d[, 1], object@stats$coords2d[, 2], pch = object@adeg.par$ppoints$pch, cex = object@adeg.par$ppoints$cex, col = object@adeg.par$ppoints$col, alpha = object@adeg.par$ppoints$alpha, fill = object@adeg.par$ppoints$fill)
if(any(object@adeg.par$plabels$cex > 0))
adeg.panel.label(object@stats$coords2d[, 1], object@stats$coords2d[, 2], labels, object@adeg.par$plabels)
## addmean or addaxes
if(object@g.args$addmean | object@g.args$addaxes) {
df <- sweep(df, 1, rowSums(df), "/")
mini3 <- object@g.args$min3d
maxi3 <- object@g.args$max3d
m3 <- colMeans(df)
mxy <- .coordtotriangleM(t(as.matrix(m3)), mini3 = mini3, maxi3 = maxi3)[-1]
if(object@g.args$addmean) {
## axis points: putting means on the axis A
axp3 <- rbind(c(m3[1], mini3[2], 1 - m3[1] - mini3[2]),
c(1 - m3[2] -mini3[3], m3[2], mini3[3]),
c(mini3[1], 1 - m3[3] - mini3[1], m3[3]))
axpxyz <- .coordtotriangleM(axp3, mini3 = mini3, maxi3 = maxi3)
## drawing lines for means
apply(axpxyz, 1, FUN = function(x) {
do.call("panel.lines", c(list(x = c(x[2], mxy[1]), y = c(x[3], mxy[2])), object@g.args$axespar))
})
do.call("panel.points", c(list(x = c(mxy[1], axpxyz[, 2]), y = c(mxy[2], axpxyz[, 3])), object@g.args$meanpar))
panel.text(x = axpxyz[, 2], y = axpxyz[, 3], labels = as.character(round(m3, digits = 4)), pos = c(2, 1, 4))
}
if(object@g.args$addaxes) {
axx <- dudi.pca(df, scale = FALSE, scannf = FALSE)$c1
cornerp <- object@s.misc$cornerp
a1 <- axx[, 1]
x1 <- a1[1] * cornerp$A + a1[2] * cornerp$B + a1[3] * cornerp$C
do.call("panel.segments", c(list(x0 = mxy[1] - x1[1], x1 = mxy[1] + x1[1], y0 = mxy[2] - x1[2], y1 = mxy[2] + x1[2]), object@g.args$axespar))
a2 <- axx[, 2]
x1 <- a2[1] * cornerp$A + a2[2] * cornerp$B + a2[3] * cornerp$C
do.call("panel.segments", c(list(x0 = mxy[1] - x1[1], x1 = mxy[1] + x1[1], y0 = mxy[2] - x1[2], y1 = mxy[2] + x1[2]), object@g.args$axespar))
do.call("panel.points", c(list(x = mxy[1], y = mxy[2]), object@g.args$meanpar))
}
}
})
triangle.label <- function(dfxyz, labels = rownames(dfxyz), adjust = TRUE, min3d = NULL, max3d = NULL, addaxes = FALSE, addmean = FALSE, meanpar = NULL, axespar = NULL,
showposition = TRUE, facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## dfxyz: matrix/data.frame with 3 columns
## min3d, max3d: limits by default: c(0,0,0), c(1,1,1)
## addaxes: should we draw pca axes
## addmean: should we draw mean
thecall <- .expand.call(match.call())
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
object <- multi.facets.Tr(thecall, samelimits = sortparameters$g.args$samelimits)
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(adjust = adjust, min3d = min3d, max3d = max3d, addaxes = addaxes, addmean = addmean, meanpar = meanpar, axespar = axespar))
if(storeData)
tmp_data <- list(dfxyz = dfxyz, labels = labels, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(dfxyz = thecall$dfxyz, labels = thecall$labels, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "Tr.label", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = match.call())
## preparation
prepare(object)
setlatticecall(object)
if(showposition & add) {
warning("cannot show position and add") ## can be done, but modifies the meaning of the superposition
showposition <- FALSE
}
if(showposition)
object <- new(Class = "ADEgS", ADEglist = list("triangle" = object, "positions" = .showpos(object)), positions = rbind(c(0, 0, 1, 1), c(0, 0.7, 0.3, 1)), add = matrix(0, ncol = 2, nrow = 2), Call = match.call())
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/addsegment.R 0000644 0001762 0000144 00000005677 13742303021 015175 0 ustar ligges users setMethod(
f = "addsegment",
signature = "ADEg",
definition = function(object, x0 = NULL, y0 = NULL, x1, y1, plot = TRUE, ...) {
# collect limits
xlim <- object@g.args$xlim
ylim <- object@g.args$ylim
aspect <- object@adeg.par$paxes$aspectratio
## sorting parameters
sortparameters <- sortparamADEg(...)$adepar
params <- adegpar()
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
params <- sortparameters$plines
segmentadded <- xyplot(0 ~ 0, xlim = xlim, ylim = ylim, main = NULL, xlab = NULL, ylab = NULL, aspect = aspect,
myx0 = x0, myy0 = y0, myx1 = x1, myy1 = y1,
panel = function(x, y, ...) panel.segments(x0 = x0, y0 = y0, x1 = x1, y1 = y1, lwd = params$lwd, lty = params$lty, col = params$col), plot = FALSE)
segmentadded$call <- call("xyplot", 0 ~ 0, xlim = substitute(xlim), ylim = substitute(ylim), xlab = NULL, ylab = NULL,
aspect = substitute(aspect), lwd = params$lwd, lty = params$lty, col = params$col,
x0 = substitute(x0), y0 = substitute(y0), x1 = substitute(x1), y1 = substitute(y1),
panel = function(x, y, ...) panel.segments(x0 = x0, y0 = y0, x1 = x1, y1 = y1))
# superposition
obj <- superpose(object, segmentadded, plot = FALSE)
nn <- all.names(substitute(object))
names(obj) <- c(ifelse(is.na(nn[2]), nn[1], nn[2]), "segmentadded")
if(plot)
print(obj)
invisible(obj)
})
setMethod(
f = "addsegment",
signature = "ADEgS",
definition = function(object, x0 = NULL, y0 = NULL, x1, y1, plot = TRUE, which = 1:length(object), ...) {
ngraph <- length(object)
if(max(which) > ngraph)
stop("Values in 'which' should be lower than the length of object")
if(length(which) == 1) {
object[[which]] <- addsegment(object[[which]], x0 = x0, y0 = y0, x1 = x1, y1 = y1, ..., plot = FALSE)
} else {
if(sum(object@add) != 0)
stop("The 'addsegment' function is not available for superposed objects.", call. = FALSE)
## sorting parameters
sortparameters <- sortparamADEg(...)$adepar
params <- adegpar()
sortparameters <- modifyList(params, sortparameters, keep.null = TRUE)
params <- sortparameters$plines
params <- rapply(params, function(X) rep(X, length.out = length(which)), how = "list")
if(!is.null(x0)) x0 <- rep_len(x0, length.out = length(which))
if(!is.null(y0)) y0 <- rep_len(y0, length.out = length(which))
x1 <- rep_len(x1, length.out = length(which))
y1 <- rep_len(y1, length.out = length(which))
for (i in which)
object[[i]] <- addsegment(object[[i]], x0 = x0[i], y0 = y0[i], x1 = x1[i], y1 = y1[i], which = 1, plot = FALSE, plines = lapply(params, function(X) X[i]))
}
obj <- object
if(plot)
print(obj)
invisible(obj)
}) adegraphics/R/ADEg.S2.R 0000644 0001762 0000144 00000033734 14354572444 014121 0 ustar ligges users setClass(
Class = "ADEg.S2",
contains = c("ADEg", "VIRTUAL"),
slots = c(data = "list")
)
setMethod(
f = "initialize",
signature = "ADEg.S2",
definition = function(.Object, data = list(dfxy = NULL, xax = 1, yax = 2, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, ...) ## ADEg initialize
.Object@data <- data
return(.Object)
})
setMethod(
f = "prepare",
signature = "ADEg.S2",
definition = function(object) {
## TODO: factorise les if
name_obj <- deparse(substitute(object))
if(object@data$storeData)
dfxy <- object@data$dfxy
else
dfxy <- eval(object@data$dfxy, envir = sys.frame(object@data$frame))
## axes limits
if(inherits(object, "S2.corcircle")) {
object@trellis.par$panel.background$col <- "transparent"
if(object@g.args$fullcircle) {
if(is.null(object@g.args$xlim) || !identical(object@s.misc$xfullcircle.update, object@g.args$fullcircle)) {
minX <- -1
maxX <- 1
} else {
minX <- object@g.args$xlim[1]
maxX <- object@g.args$xlim[2]
}
if(is.null(object@g.args$ylim) || !identical(object@s.misc$yfullcircle.update, object@g.args$fullcircle)) {
minY <- -1
maxY <- 1
} else {
minY <- object@g.args$ylim[1]
maxY <- object@g.args$ylim[2]
}
} else {
if(is.null(object@g.args$xlim) || !identical(object@s.misc$xfullcircle.update, object@g.args$fullcircle)) {
minX <- min(dfxy[, object@data$xax])
maxX <- max(dfxy[, object@data$xax])
} else {
minX <- object@g.args$xlim[1]
maxX <- object@g.args$xlim[2]
}
if(is.null(object@g.args$ylim) || !identical(object@s.misc$yfullcircle.update, object@g.args$fullcircle)) {
minY <- min(dfxy[, object@data$yax])
maxY <- max(dfxy[, object@data$yax])
} else {
minY <- object@g.args$ylim[1]
maxY <- object@g.args$ylim[2]
}
}
} else {
if(is.null(object@g.args$xlim)) {
minX <- min(dfxy[, object@data$xax])
maxX <- max(dfxy[, object@data$xax])
} else {
minX <- object@g.args$xlim[1]
maxX <- object@g.args$xlim[2]
}
if(is.null(object@g.args$ylim)) {
minY <- min(dfxy[, object@data$yax])
maxY <- max(dfxy[, object@data$yax])
} else {
minY <- object@g.args$ylim[1]
maxY <- object@g.args$ylim[2]
}
}
limits <- setlimits2D(minX = minX, maxX = maxX, minY = minY, maxY = maxY, origin = rep(object@adeg.par$porigin$origin, le = 2),
aspect.ratio = object@adeg.par$paxes$aspectratio, includeOr = object@adeg.par$porigin$include)
if(is.null(object@g.args$xlim) || !identical(object@s.misc$xfullcircle.update, object@g.args$fullcircle))
object@g.args$xlim <- limits$xlim
if(is.null(object@g.args$ylim) || !identical(object@s.misc$yfullcircle.update, object@g.args$fullcircle))
object@g.args$ylim <- limits$ylim
if(inherits(object, "S2.corcircle")) {
object@s.misc$xfullcircle.update <- object@g.args$fullcircle
object@s.misc$yfullcircle.update <- object@g.args$fullcircle
}
## grid locations and axes
if(object@adeg.par$pgrid$draw || object@adeg.par$paxes$draw) {
## axes division
if(!inherits(object, "S2.corcircle")) {
if(object@adeg.par$porigin$include)
object@s.misc$backgrid <- .getgrid(xlim = object@g.args$xlim, ylim = object@g.args$ylim, object@adeg.par$pgrid$nint, rep(object@adeg.par$porigin$origin, le = 2), asp = object@adeg.par$paxes$aspectratio)
else
object@s.misc$backgrid <- .getgrid(xlim = object@g.args$xlim, ylim = object@g.args$ylim, object@adeg.par$pgrid$nint, asp = object@adeg.par$paxes$aspectratio)
}
if(object@adeg.par$paxes$draw) {
## parameters to plot axes
scalesandlab <- modifyList(as.list(object@g.args$scales), object@adeg.par$paxes, keep.null = TRUE)
if(is.null(scalesandlab$y$at)) {
scalesandlab$y$at <- object@s.misc$backgrid[[3L]][!is.na(object@s.misc$backgrid[[3L]])]
if(inherits(object, "S2.corcircle"))
scalesandlab$y$at <- scalesandlab$y$at[(length(scalesandlab$y$at) / 2 + 1):length(scalesandlab$y$at)]
}
if(is.null(scalesandlab$x$at)) {
scalesandlab$x$at <- object@s.misc$backgrid[[1L]][!is.na(object@s.misc$backgrid[[1L]])]
if(inherits(object, "S2.corcircle"))
scalesandlab$x$at <- scalesandlab$x$at[1:(length(scalesandlab$x$at) / 2)]
}
} else
scalesandlab <- list(draw = FALSE) ## no axes
}
else
scalesandlab <- list(draw = FALSE) ## no axes
if(object@adeg.par$paxes$aspectratio != "iso")
object@adeg.par$pgrid$text$cex <- 0 ## grid cell size has no meaning
if(!is.null(object@g.args$Sp))
object@adeg.par$paxes$aspectratio <- ifelse(is.na(proj4string(object@g.args$Sp)) || is.projected(object@g.args$Sp), 1, 1/cos((mean(object@g.args$ylim) * pi)/180))
## if grid and axes are drawn, no text indication
if(object@adeg.par$pgrid$draw && object@adeg.par$paxes$draw)
object@adeg.par$pgrid$text$cex <- 0
object@g.args$scales <- scalesandlab
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panelbase",
signature = "ADEg.S2",
definition = function(object, x, y) {
## draw grid
lims <- current.panel.limits(unit = "native")
porigin <- object@adeg.par$porigin
porigin$origin <- rep(porigin$origin, length.out = 2)
if(inherits(object, "S2.corcircle"))
grid.circle(x = 0, y = 0, r = 1, default.units = "native", gp = gpar(col = "black", fill = object@adeg.par$pbackground$col), draw = TRUE, name = "circleGrid")
if(object@adeg.par$pgrid$draw) { ## if grid to draw
grid <- object@adeg.par$pgrid
locations <- object@s.misc$backgrid ## coordinates for the grid
panel.segments(
x0 = c(locations$x0[!is.na(locations$x0)], rep(lims$xlim[1], sum(is.na(locations$x0)))),
x1 = c(locations$x1[!is.na(locations$x1)], rep(lims$xlim[2], sum(is.na(locations$x1)))),
y0 = c(rep(lims$ylim[1], sum(is.na(locations$y0))), locations$y0[!is.na(locations$y0)]),
y1 = c(rep(lims$ylim[2], sum(is.na(locations$y1))), locations$y1[!is.na(locations$y1)]),
col = grid$col, lty = grid$lty, lwd = grid$lwd)
if(grid$text$cex > 0) {
text.pos <- .setposition(grid$text$pos)
textgrid <- textGrob(label = paste("d =", locations$d), x = text.pos$posi[1], y = text.pos$posi[2], just = text.pos$just, gp = gpar(cex = grid$text$cex, col = grid$text$col), name = "gridtext")
grid.rect(x = text.pos$posi[1], y = text.pos$posi[2], width = grobWidth(textgrid), height = grobHeight(textgrid),
just = text.pos$just, gp = gpar(fill = ifelse(inherits(object, "S2.corcircle"), "transparent", object@adeg.par$pbackground$col), alpha = 1, col = "transparent"))
grid.draw(textgrid)
}
}
if(porigin$draw && porigin$include & inherits(object, "S2.corcircle")) {
panel.segments(x0 = c(-1, porigin$origin[1]), x1 = c(1, porigin$origin[1]), y0 = c(porigin$origin[2], -1), y1 = c(porigin$origin[2], 1), col = porigin$col, lwd = porigin$lwd, lty = porigin$lty, alpha = porigin$alpha)
## TODO: check last parameters valididy
}
if(porigin$draw && porigin$include & !inherits(object, "S2.corcircle")) {
panel.abline(h = porigin$origin[2], v = porigin$origin[1], col = porigin$col, lwd = porigin$lwd, lty = porigin$lty, alpha = porigin$alpha)
## TODO: check last parameters valididy
}
## spatial object management
if(any(names(object@g.args) == "Sp")) {
do.call("adeg.panel.Spatial", args = c(list(SpObject = object@g.args$Sp, sp.layout = object@g.args$sp.layout), object@adeg.par$pSp))
}
else ## no Sp but sp.layout
if(any(names(object@g.args) == "sp.layout"))
sppanel(obj = object@g.args$sp.layout)
## neighbouring object management
if(any(names(object@g.args) == "nbobject")) {
nbobj <- object@g.args$nbobject
if(!inherits(nbobj, "nb") & !inherits(nbobj, "listw"))
stop("wrong class for the nb object")
pnb <- object@adeg.par$pnb
do.call("adeg.panel.nb", args = list(nbobject = nbobj, coords = cbind(x, y), col.edge = pnb$edge$col, lwd = pnb$edge$lwd, lty = pnb$edge$lty, pch = pnb$node$pch, cex = pnb$node$cex, col.node = pnb$node$col, alpha = pnb$node$alpha))
}
callNextMethod()
})
setMethod(
f = "setlatticecall",
signature = "ADEg.S2",
definition = function(object) {
## arguments recurrents de la liste, pas les limites car elles seront definis ensuite
name_obj <- deparse(substitute(object))
## background and box
if(!inherits(object, "S2.corcircle"))
object@trellis.par$panel.background$col <- object@adeg.par$pbackground$col
if(!object@adeg.par$pbackground$box)
object@trellis.par$axis.line$col <- "transparent"
else
object@trellis.par$axis.line$col <- "black"
arguments <- list(
par.settings = object@trellis.par,
scales = object@g.args$scales,
aspect = object@adeg.par$paxes$aspectratio,
key = createkey(object),
legend = createcolorkey(object),
axis = axis.L, ## see utils.R
panel = function(...) {
panelbase(object,...) ## grid,
panel(object,...) ## call to S2.panel function, for slabel and ADEg.S2 class of graphs
})
object@lattice.call$arguments <- arguments
object@lattice.call$graphictype <- "xyplot"
## get lattice arguments (set unspecified to NULL)
argnames <- c("main", "sub", "xlab", "ylab")
largs <- object@g.args[argnames]
names(largs) <- argnames
## add xlim and ylim if not NULL
if("xlim" %in% names(object@g.args))
largs["xlim"] <- object@g.args["xlim"]
if("ylim" %in% names(object@g.args))
largs["ylim"] <- object@g.args["ylim"]
object@lattice.call$arguments <- c(object@lattice.call$arguments, largs, list(strip = FALSE))
assign(name_obj, object, envir = parent.frame())
})
## zoom without center
setMethod(
f = "zoom",
signature = c("ADEg.S2", "numeric", "missing"),
definition = function(object, zoom, center) {
oldxlim <- object@g.args$xlim
oldylim <- object@g.args$ylim
if(length(zoom) != 1)
stop("zoom factor should be length 1")
diffx <- diff(oldxlim)
diffy <- diff(oldylim)
center <- c(oldxlim[1] + diffx / 2, oldylim[1] + diffy / 2)
diffx <- diffx / zoom
diffy <- diffy / zoom
object@g.args$xlim <- c(center[1] - diffx / 2, center[1] + diffx / 2)
object@g.args$ylim <- c(center[2] - diffy / 2, center[2] + diffy / 2)
if(object@adeg.par$pgrid$draw || object@adeg.par$paxes$draw)
object@s.misc$backgrid <- .getgrid(xlim = object@g.args$xlim, ylim = object@g.args$ylim, object@adeg.par$pgrid$nint, object@adeg.par$porigin$origin, asp = object@adeg.par$paxes$aspectratio)
prepare(object)
setlatticecall(object)
print(object)
invisible(object)
})
## zoom with center
setMethod(
f = "zoom",
signature = c("ADEg.S2", "numeric", "numeric"),
definition = function(object, zoom, center) {
if(length(center) != 2)
stop("error, center should be length 2")
if(length(zoom) != 1)
stop("zoom factor should be length 1")
diffx <- diff(object@g.args$xlim) / zoom
diffy <- diff(object@g.args$ylim) / zoom
object@g.args$xlim <- c(center[1] - diffx / 2, center[1] + diffx / 2)
object@g.args$ylim <- c(center[2] - diffy / 2, center[2] + diffy / 2)
if(object@adeg.par$pgrid$draw || object@adeg.par$paxes$draw)
object@s.misc$backgrid <- .getgrid(xlim = object@g.args$xlim, ylim = object@g.args$ylim, object@adeg.par$pgrid$nint, object@adeg.par$porigin$origin, asp = object@adeg.par$paxes$aspectratio)
prepare(object)
setlatticecall(object)
print(object)
invisible(object)
})
setMethod(
f = "gettrellis",
signature = "ADEg.S2",
definition = function(object) {
if(object@data$storeData) {
dfxy <- as.matrix(object@data$dfxy)
xax <- object@data$xax
yax <- object@data$yax
} else {
dfxy <- as.matrix(eval(object@data$dfxy, envir = sys.frame(object@data$frame)))
yax <- eval(object@data$yax, envir = sys.frame(object@data$frame))
xax <- eval(object@data$xax, envir = sys.frame(object@data$frame))
}
tmptrellis <- do.call(what = object@lattice.call$graphictype, args = c(formula(dfxy[, yax] ~ dfxy[, xax]), object@lattice.call$arguments, environment()))
return(tmptrellis)
})
adegraphics/R/utilskey.R 0000644 0001762 0000144 00000016021 13742303021 014714 0 ustar ligges users setMethod(
f = "addkey",
signature = "ADEg",
definition = function(object) {
object@adeg.par$plegend$drawKey <- TRUE
object@g.args$key <- createkey(object)
return(object)
})
setMethod(
f = "createkey",
signature = "ADEg",
definition = function(object) {
if(object@adeg.par$plegend$drawKey){
res <- object@g.args$key
}
else
res <- NULL
return(res)
})
setMethod(
f = "createkey",
signature = "S2.value",
definition = function(object) {
return(.createkeyvalue(object, type = "S2"))
})
setMethod(
f = "createkey",
signature = "T.value",
definition = function(object) {
return(.createkeyvalue(object, type = "T"))
})
setMethod(
f = "createkey",
signature = "S2.class",
definition = function(object) {
return(.createkeyclass(object, type = "S2"))
})
setMethod(
f = "createkey",
signature = "S1.class",
definition = function(object) {
return(.createkeyclass(object, type = "S1"))
})
setMethod(
f = "createkey",
signature = "Tr.class",
definition = function(object) {
return(.createkeyclass(object, type = "Tr"))
})
setMethod(
f = "createcolorkey",
signature = "ADEg",
definition = function(object) {
if(object@adeg.par$plegend$drawColorKey){
res <- object@g.args$legend
}
else
res <- NULL
return(res)
})
setMethod(
f = "createcolorkey",
signature = "T.image",
definition = function(object) {
## add a small space before the colorkey
trellis.par.set(layout.widths = list(axis.key.padding = 1))
return(.createcolorkeyimage(object, type = "T"))
})
setMethod(
f = "createcolorkey",
signature = "S2.image",
definition = function(object) {
## add a small space before the colorkey
trellis.par.set(layout.widths = list(axis.key.padding = 1))
return(.createcolorkeyimage(object, type = "S2"))
})
.createkeyvalue <- function(object, type = c("T", "S2")) {
type <- match.arg(type)
res <- NULL
if(object@adeg.par$plegend$drawKey){
res <- list()
res$points$pch <- .symbol2pch(object@g.args$symbol)
cstnormal <- 5 ## same value in adeg.panel.value
if(object@g.args$method == "size"){
center <- object@g.args$center
breaks <- unique(c(object@s.misc$breaks.update, signif(center, 5)))
maxsize <- max(abs(breaks))
breaks <- breaks[order(breaks, decreasing = FALSE)]
l0 <- length(breaks)
breaks <- (breaks[1:(l0 - 1)] + breaks[2:l0]) / 2
res$text$lab <- as.character(breaks)
size <- breaks - center
res$points$cex <- .proportional_map(size, maxsize) * object@adeg.par$ppoints$cex[1] * cstnormal
res$points$fill <- object@adeg.par$ppoints$col[ifelse(breaks < center, 1, 2)]
res$points$col <- object@adeg.par$ppoints$col[ifelse(breaks < center, 2, 1)]
} else if(object@g.args$method == "color"){
breaks <- object@s.misc$breaks.update
l0 <- length(breaks)
res$points$cex <- object@adeg.par$ppoints$cex[1] * cstnormal / 2 * object@adeg.par$plegend$size
res$text$lab <- paste("[", breaks[l0], ";", breaks[l0 - 1], "]", sep = "")
for(i in (l0 - 1):2)
res$text$lab <- c(res$text$lab, paste("]", breaks[i], ";", breaks[i - 1], "]", sep = ""))
res$points$fill <- object@adeg.par$ppoints$fill[1:length(res$text$lab)]
res$points$col <- object@adeg.par$ppoints$col
}
res$columns <- length(res$text$lab)
res$border <- TRUE
res$between <- 0.1 * object@adeg.par$plegend$size
res$between.columns <- 0 * object@adeg.par$plegend$size
res$padding.text <- 1.2 * max(res$points$cex)
res$text$cex <- object@adeg.par$plegend$size
if(is.null(object@g.args$key$space)){
if(type == "T"){
res$x <- 0
res$y <- 0
} else {
res$corner <- c(0,0)
res$x <- 0.01
res$y <- 0.01
}
}
res$background <- object@adeg.par$pbackground$col
res <- modifyList(res, as.list(object@g.args$key), keep.null = TRUE)
}
return(res)
}
.createkeyclass <- function(object, type = c("S1", "S2", "Tr")) {
type <- match.arg(type)
res <- NULL
if(object@adeg.par$plegend$drawKey){
res <- list()
if(object@data$storeData)
fac <- as.factor(object@data$fac)
else
fac <- as.factor(eval(object@data$fac, envir = sys.frame(object@data$frame)))
res$text$lab <- levels(fac)
res$text$col <- object@adeg.par$plabels$col
if(object@adeg.par$ppoints$cex > 0){
res$points$pch <- object@adeg.par$ppoints$pch
res$points$col <- object@adeg.par$ppoints$col
res$points$fill <- object@adeg.par$ppoints$fill
} else if(!is.null(object@g.args$chullSize)){
if(object@g.args$chullSize > 0){
res$rectangles$border <- object@adeg.par$ppolygons$border
res$rectangles$col <- object@adeg.par$ppolygons$col
res$rectangles$alpha <- object@adeg.par$ppolygons$alpha
}
} else if(object@g.args$ellipseSize > 0){
res$rectangles$border <- object@adeg.par$pellipses$border
res$rectangles$col <- object@adeg.par$pellipses$col
res$rectangles$alpha <- object@adeg.par$pellipses$alpha
} else if(object@g.args$starSize > 0){
res$lines$col <- object@adeg.par$plines$col
res$lines$lty <- object@adeg.par$plines$lty
res$lines$lwd <- object@adeg.par$plines$lwd
}
res$between <- 0.1 * object@adeg.par$plegend$size
res$between.columns <- 0 * object@adeg.par$plegend$size
res$text$cex <- object@adeg.par$plegend$size
if(is.null(object@g.args$key$space)){
if(type == "S2"){
res$corner <- c(0,0)
res$x <- 0.01
res$y <- 0.01
}
if(type == "S1"){
res$corner <- c(0,1)
res$x <- 0.01
res$y <- 0.99
}
if(type == "Tr"){
res$corner <- c(1,1)
res$x <- 0.99
res$y <- 0.99
}
}
res$background <- object@adeg.par$pbackground$col
res <- modifyList(res, as.list(object@g.args$key), keep.null = TRUE)
}
return(res)
}
.createcolorkeyimage <- function(object, type = c("T", "S2")) {
type <- match.arg(type)
res <- NULL
if(object@adeg.par$plegend$drawColorKey){
res <- list(right = list(fun = draw.colorkey, args = list(key = list(col = object@adeg.par$ppoints$col, at = object@s.misc$breaks.update))))
}
return(res)
}
adegraphics/R/parameter.R 0000644 0001762 0000144 00000022054 13747033173 015043 0 ustar ligges users changelatticetheme <- function(...) {
## lattice.options(default.theme = adegspecial)
## change lattice theme
## if a device is open, it would apply only to new devices
if(try(is.list(...), silent = TRUE) == TRUE)
changes <- as.list(...)
else
changes <- list(...)
newtheme <- get("lattice.theme", envir = getFromNamespace(".LatticeEnv", ns = "lattice"))
adegspecial <- get("adegtheme", envir = .ADEgEnv)
if(length(changes))
newtheme <- modifyList(newtheme, changes, keep.null = TRUE)
else
## come back at the starting point
newtheme <- modifyList(newtheme, adegspecial, keep.null = TRUE)
## for all new devices
lattice.options(default.theme = switch(EXPR = .Device, newtheme))
if(dev.cur() != 1) ## if a device is open
trellis.par.set(newtheme)
invisible(newtheme)
}
.mergingList <- function(tomerge) {
## merge elements of the list by name recursively
lnames <- names(tomerge)
counter <- 0 ## safety counter
while(length(lnames) != length(unique(lnames))) {
## be sure that there are duplicated values
indix <- match(lnames, lnames)
remove <- c()
for(i in 1:length(indix)) {
if(i != indix[i]) {
tomerge[[indix[i]]] <- c(tomerge[[indix[i]]], tomerge[[i]])
remove <- c(remove, i)
}
}
if(length(remove))
tomerge[remove] <- NULL
tomerge <- lapply(tomerge, FUN = function(x) {if(is.list(x) & (length(x) > 1)) .mergingList(x) else x})
counter <- counter + 1
if(counter == 50)
stop("error in .mergingList", call. = FALSE)
lnames <- names(tomerge)
}
return(tomerge)
}
.replaceList <- function(x, val) {
## replaceList: inspired by modifyList but
## replace only previous existing elements and with partial names matching
## x: list to modify, val: modications to pass
## x structure can not be changed
## To be more specific if an element is a list, it cannot be change with a single value
rest <- list()
returned <- list()
xnames <- names(x)
for (v in names(val)) {
indix <- pmatch(v, xnames, nomatch = 0)
if(indix > 0) {
## if there is a match
if(is.list(x[[indix]]) && (!is.list(val[[v]])))
stop(paste("cannot replace a list: ", xnames[indix], " by a single value element", sep = ""), call. = FALSE)
else {
if(is.list(x[[indix]])) {
## recursivity
replace <- .replaceList(x[[indix]], val[[v]])
returned <- c(returned, list(replace$select))
rest <- c(rest, replace$rest)
}
else
returned[[(length(returned) + 1)]] <- val[[v]] ## else replace values
names(returned)[length(returned)] <- xnames[indix]
}
}
else rest <- c(rest, val[v])
}
return(list(select = returned, rest = rest))
}
.getlist <- function(keys, values) {
## assembles keys and values as list of list
## keys: list of characters vectors, the keys splitted, values: the original list
result <- list()
for(i in 1:length(keys)) {
l <- list(values[[i]])
names(l) <- keys[[i]][length(keys[[i]])]
if(length(keys[[i]]) > 1)
for(j in (length(keys[[i]]) - 1):1) {
l <- list(l)
names(l)[1] <- keys[[i]][j]
}
result[[i]] <- l
}
return(result)
}
separation <- function(... , pattern = 0, split = TRUE) {
## separate between the list passed to the function and the one already known
## if pattern is 1, compare to trellis parameters
## if pattern is 0, compare to 'padegraphic' parameters
## gets dots
if(try(is.list(...), silent = TRUE) == TRUE)
tmp_list <- as.list(...)
else
tmp_list <- list(...)
if(is.null(names(tmp_list)))
names(tmp_list) <- tmp_list
if(!length(tmp_list))
return(list(select = list(), rest = list()))
## get pattern
if(is.list(pattern))
listpat <- pattern
else {
if(pattern > 1)
stop("pattern must be 0 or 1 in 'separation' function", call. = FALSE)
else {
if(pattern == 1)
listpat <- trellis.par.get()
else{
listpat <- get("padegraphic", envir = .ADEgEnv)
}
}
}
## splitting list keys
if(!is.list(pattern)) {
if(pattern != 1 && split) {
## adegpar, collates keys
sep <- strsplit(names(tmp_list), split = ".", fixed = TRUE)
values <- tmp_list
val <- .getlist(keys = sep, values = values) ## assemblies keys with values, as list of list...
val <- sapply(val, FUN = function(x) return(x))
val <- .mergingList(val)
} else
val <- tmp_list
} else
val <- tmp_list
res <- .replaceList(x = listpat, val)
res[[1]] <- .mergingList(res[[1]])
return(res)
}
adegpar <- function(...) {
## case 0: nothing in parenthesis
## case 0 bis: only one key (no indication sublist, "paxes")
## case 1: ...= "axes.draw", "sub", "sub.size" # one level, only names
## case 2: ...= "axes" = list("draw") # two levels, only names
## case 3: ...= "axes.draw" = FALSE, "sub.size" = 12 # one level, key names and matching values
## case 4: ...= axes=list(draw=TRUE), sub=list(size=55) # two levels, key names and matching values
## case 5 : ... is a complete list
## if ... is a list
## does not assign, only find corresponding element in list patti
recursfinder <- function(x, patti) {
result <- list()
okfu <- function(x, patti) {
## okfu: retrieve good values and keys (patti)
if(length(x) > 1)
stop("x has length > 1") ## to remove
idx <- pmatch(names(x), names(patti))
if(!is.na(idx))
return( patti[idx])
else
return(NA)
}
if(!is.list(x[[1]]))
result <- c(result, okfu(x, patti))
else {
idx <- pmatch(names(x), names(patti))
if(!is.na(idx)) {
result <- c(result, list(recursfinder(x[[1]], patti[[idx]])))
names(result) <- names(patti[idx])
}
else
print("no matching found in adegpar")
}
return(result)
} ## end recurs finder
nonames <- function(userlist, pattili) {
## return the right values list
sep <- sapply(userlist, strsplit, split = ".", fixed = TRUE) ## a list
values <- userlist
val <- .getlist(keys = sep, values = values)
return(sapply(val, FUN = recursfinder, patti = pattili)) ## get result
}
value <- list()
assignement <- FALSE
if(try(is.list(...), silent = TRUE) == TRUE)
argu <- as.list(...) ## ... is still a list
else
argu <- list(...) ## tranforms in list
## choose option
padegr <- get("padegraphic", envir = .ADEgEnv)
## switching case: recursive
switchingcase <- function(userlist, patternlist) {
if(!length(userlist)) ## empty case 0
return(list(result = patternlist, assigni = list()))
else {
lnames <- names(userlist)
if(is.null(lnames)) { ## no values, case 0 bis or 1
res <- nonames(userlist, patternlist)
return(list(result = res, assigni = list()))
} else {
result <- list()
assigni <- list() ## initialization
for(i in 1:length(lnames)) {
if(identical(lnames[i], "")) {
## no names, meaning value is the key cas 2/1
result <- c(result,nonames(userlist[i], patternlist))
} else {
## we have names so value to assign, or sublist
sep <- sapply(lnames[i], strsplit, split = ".", fixed = TRUE) ## a list
## get a list of list with right keys (splitting *.* keys)
val <- .getlist(keys = sep, values = userlist[i])[[1L]]
idx <- pmatch(names(val), names(patternlist))
if(!is.na(idx)) {
## match with patternlist
if(is.list(val[[1]])) {
## sublist val from user list
ok <- switchingcase(val[[1]], patternlist = patternlist[[idx]])
if(length(ok$result)) {
result <- c(result, list(ok$result))
## level behind
names(result)[length(result)] <- names(patternlist[idx])
}
if(length(ok$assigni)) {
assigni <- c(assigni, list(ok$assigni))
names(assigni)[length(assigni)] <- names(patternlist[idx])
}
} else {
## if not a list, then a value to assign
if(is.list(patternlist[[idx]]))
stop(paste("be careful, intent to replace in adegraphics parameters: ", names(patternlist[idx]), " by a single value element", sep = ""), call. = FALSE)
assigni <- c(assigni, list(userlist[[i]]))
names(assigni)[length(assigni)] <- names(patternlist[idx])
}
}
}
}
}
}
return(list(result = result, assigni = assigni))
} ## end switching case
if(!length(argu)) ## ... empty
return(padegr) ## case 0
else {
## adegpar called with arguments
switchi <- switchingcase(argu, padegr)
}
if(length(switchi$assign)) {
padegr <- modifyList(padegr, switchi$assign, keep.null = TRUE)
assign("padegraphic", padegr, envir = .ADEgEnv)
return(invisible(padegr)) ## must be improve : avoid two calls to padegraphic
}
return(switchi$result)
}
adegraphics/R/S2.logo.R 0000644 0001762 0000144 00000007026 14354572673 014320 0 ustar ligges users #########################################################
## s.logo ##
#########################################################
setClass(
Class = "S2.logo",
contains = "ADEg.S2"
)
setMethod(
f = "initialize",
signature = "S2.logo",
definition = function(.Object, data = list(dfxy = NULL, logos = NULL, xax = 1, yax = 2, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.S2 initialize
.Object@data$logos <- data$logos
return(.Object)
})
setMethod(
f = "prepare",
signature = "S2.logo",
definition = function(object) {
name_obj <- deparse(substitute(object))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
if(is.null(object@adeg.par$porigin$include) & (any(names(object@g.args) %in% c("Sp", "nbobject"))))
adegtot$porigin$include <- FALSE
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "S2.logo",
definition = function(object, x, y) {
## list of bitmap objects:logos
if(object@data$storeData)
logos <- object@data$logos
else
logos <- eval(object@data$logos, envir = sys.frame(object@data$frame))
for(i in 1:length(logos)) {
grid.draw(rasterGrob(logos[[i]], x = x[i], y = y[i], height = unit(0.1, "npc") * object@adeg.par$ppoints$cex, default.units = "native"))
}
})
s.logo <- function(dfxy, logos, xax = 1, yax = 2, facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters
thecall <- .expand.call(match.call())
df <- try(as.data.frame(eval(thecall$dfxy, envir = sys.frame(sys.nframe() + pos))), silent = TRUE)
if(inherits(df, "try-error") | is.null(thecall$dfxy)) ## non convenient dfxy argument
stop("non convenient selection for dfxy (can not be converted to dataframe)")
logos <- eval(thecall$logos, envir = sys.frame(sys.nframe() + pos))
if(!is.list(logos))
stop("The argument 'logos' should be a list")
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if((length(xax) == 1 & length(yax) == 1))
object <- multi.facets.S2(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple xax/yax")
}
## multiple axes
else if((length(xax) > 1 | length(yax) > 1)) {
object <- multi.ax.S2(thecall)
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
if(storeData)
tmp_data <- list(dfxy = dfxy, xax = xax, yax = yax, logos = logos, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(dfxy = thecall$dfxy, xax = xax, yax = yax, logos = thecall$logos, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "S2.logo", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = sortparameters$g.args, Call = as.call(thecall))
## preparation
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/C1.curve.R 0000644 0001762 0000144 00000007625 13742303021 014443 0 ustar ligges users setClass(
Class = "C1.curve",
contains = "ADEg.C1"
)
setMethod(
f = "initialize",
signature = "C1.curve",
definition = function(.Object, data = list(score = NULL, at = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.C1 initialize
.Object@data$at <- data$at
validObject(.Object)
return(.Object)
})
setMethod(
f = "prepare",
signature = "C1.curve",
definition = function(object) {
nameobj <- deparse(substitute(object))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
if(object@data$storeData) {
score <- object@data$score
at <- object@data$at
} else {
score <- eval(object@data$score, envir = sys.frame(object@data$frame))
at <- eval(object@data$at, envir = sys.frame(object@data$frame))
}
score <- as.matrix(score)[, 1] ## to manage 'score' when it is a data.frame with only one column
## change some defaults
adegtot$p1d$rug$draw <- FALSE
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
if(object@adeg.par$p1d$horizontal && is.null(object@g.args$ylim))
object@g.args$ylim <- setlimits1D(min(at), max(at), 0, FALSE)
if(!object@adeg.par$p1d$horizontal && is.null(object@g.args$xlim))
object@g.args$xlim <- setlimits1D(min(at), max(at), 0, FALSE)
assign(nameobj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "C1.curve",
definition = function(object, x, y) {
## Drawing dotchart
## x is the index
## y is the score
## get some parameters
pscore <- object@adeg.par$p1d
ppoints <- lapply(object@adeg.par$ppoints, FUN = function(x) {rep(x, length.out = length(x))})
plines <- lapply(object@adeg.par$plines, FUN = function(x) {rep(x, length.out = length(x))})
## reorder the values
y <- y[order(x)]
x <- sort(x)
## Starts the display
## depends on the parametres horizontal
## rug.draw and reverse are always considered as FALSE
if(pscore$horizontal) {
x.tmp <- y
y.tmp <- x
} else {
x.tmp <- x
y.tmp <- y
}
panel.lines(x = x.tmp, y = y.tmp, lwd = plines$lwd, lty = plines$lty, col = plines$col)
panel.points(x = x.tmp, y = y.tmp, pch = ppoints$pch, cex = ppoints$cex, col = ppoints$col, alpha = ppoints$alpha)
})
s1d.curve <- function(score, at = 1:NROW(score), facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters
thecall <- .expand.call(match.call())
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if(NCOL(score) == 1)
object <- multi.facets.C1(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple scores")
}
## multiple scores
else if(NCOL(score) > 1) {
object <- multi.score.C1(thecall)
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
if(storeData)
tmp_data <- list(score = score, at = at, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(score = thecall$score, at = thecall$at, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "C1.curve", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = sortparameters$g.args, Call = match.call())
## preparation
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/C1.density.R 0000644 0001762 0000144 00000025502 14550522102 014771 0 ustar ligges users #####################################################################
## S1.density to compare with S1.gauss afterwards ##
## TODO: reverse/vertical mettre a l'echelle distribution calculee ##
## Dans l'idée S1.density plutot si pas de factor... ##
#####################################################################
setClass(
Class = "C1.density",
contains = "ADEg.C1"
)
setMethod(
f = "initialize",
signature = "C1.density",
definition = function(.Object, data = list(score = NULL, fac = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.C1 initialize
.Object@data$fac <- data$fac
return(.Object)
})
### densities calculations according to user parameters and score/factor
setMethod(
f = "prepare",
signature = "C1.density",
definition = function(object) {
nameobj <- deparse(substitute(object))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
if(object@data$storeData) {
score <- object@data$score
fac <- object@data$fac
} else {
score <- eval(object@data$score, envir = sys.frame(object@data$frame))
fac <- eval(object@data$fac, envir = sys.frame(object@data$frame))
}
score <- as.matrix(score)[, 1] ## to manage 'score' when it is a data.frame with only one column
nlev <- nlevels(as.factor(fac))
## If axes are plotted, put a label for axis
if(adegtot$paxes$draw) {
if(is.null(object@g.args$xlab) & !adegtot$p1d$horizontal)
object@g.args$xlab <- "density"
if(is.null(object@g.args$ylab) & adegtot$p1d$horizontal)
object@g.args$ylab <- "density"
}
## setting colors
paramsToColor <- list(plabels = list(col = object@adeg.par$plabels$col, boxes = list(col = object@adeg.par$plabels$boxes$col)),
plines = list(col = object@adeg.par$plines$col),
ppolygons = list(border = object@adeg.par$ppolygons$border, col = object@adeg.par$ppolygons$col))
if(!(is.null(object@g.args$col) || (is.logical(object@g.args$col) && !object@g.args$col)))
adegtot <- modifyList(adegtot, col2adepar(ccol = object@g.args$col, pparamsToColor = paramsToColor, nnlev = nlev))
## if fill is FALSE, polygons density curves are transparent
if(!object@g.args$fill)
adegtot$ppolygons$col <- "transparent"
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
scores <- split(score, fac)
densit <- vector(mode = "list", length = length(scores))
names(densit) <- names(scores)
## estimate density for each level of the factor
for(i in 1:length(scores)) {
if(length(scores[[i]]) == 0) {
## no data in the given level
densit[[i]] <- list(x = NA, y = NA)
} else {
if(!is.null(object@g.args$bandwidth))
densit[[i]] <- bkde(scores[[i]], kernel = object@g.args$kernel, bandwidth = object@g.args$bandwidth, gridsize = object@g.args$gridsize)
else
densit[[i]] <- bkde(scores[[i]], kernel = object@g.args$kernel, gridsize = object@g.args$gridsize)
}
}
lead <- ifelse(object@adeg.par$p1d$reverse, 1 , -1)
if(object@adeg.par$p1d$horizontal) {
Ylim <- object@g.args$ylim
if(is.null(object@s.misc$p1dReverse.update) || object@adeg.par$p1d$reverse != object@s.misc$p1dReverse.update ||
is.null(object@s.misc$Ylim.update) || any(Ylim != object@s.misc$Ylim.update)) {
if(is.null(object@g.args$ylim))
Ylim <- c(0, max(sapply(densit, FUN = function(x) {ifelse(is.na(x$y[1]), 0, max(x$y))}) / 0.85))
if(object@adeg.par$p1d$rug$draw) {
ref <- ifelse(object@adeg.par$p1d$reverse, 2, 1)
margin <- Ylim[ref]
if(object@adeg.par$p1d$rug$draw)
margin <- object@adeg.par$p1d$rug$margin * abs(diff(Ylim))
object@s.misc$rug <- Ylim[ref]
Ylim[ref] <- Ylim[ref] + lead * margin
}
object@s.misc$Ylim.update <- Ylim
object@s.misc$p1dReverse.update <- object@adeg.par$p1d$reverse
}
object@g.args$ylim <- Ylim
} else {
Xlim <- object@g.args$xlim
if(is.null(object@s.misc$p1dReverse.update) || object@adeg.par$p1d$reverse != object@s.misc$p1dReverse.update ||
is.null(object@s.misc$Xlim.update) || any(Xlim != object@s.misc$Xlim.update)) {
if(is.null(object@g.args$xlim))
Xlim <- c(0, max(sapply(densit, FUN = function(x) {ifelse(is.na(x$y[1]), 0, max(x$y))}) / 0.85))
if(object@adeg.par$p1d$rug$draw) {
ref <- ifelse(object@adeg.par$p1d$reverse, 2, 1)
margin <- Xlim[ref]
if(object@adeg.par$p1d$rug$draw)
margin <- object@adeg.par$p1d$rug$margin * abs(diff(Xlim))
object@s.misc$rug <- Xlim[ref]
Xlim[ref] <- Xlim[ref] + lead * margin
}
object@s.misc$Xlim.update <- Xlim
object@s.misc$p1dReverse.update <- object@adeg.par$p1d$reverse
}
object@g.args$xlim <- Xlim
}
object@stats$densit <- densit
assign(nameobj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "C1.density",
definition = function(object, x, y) {
## Drawing densities as polygons (filled or not)
## one polygon per level
## y is the score
## get some parameters
pscore <- object@adeg.par$p1d
curvess <- object@stats$densit
labels <- names(curvess)
lims <- current.panel.limits(unit = "native")
if(object@data$storeData)
fac <- object@data$fac
else
fac <- eval(object@data$fac, envir = sys.frame(object@data$frame))
nlev <- nlevels(as.factor(fac))
ppoly <- lapply(object@adeg.par$ppolygons, FUN = function(x) rep(x, length.out = nlev))
plabels <- lapply(object@adeg.par$plabels, FUN = function(x) rep(x, length.out = nlev))
y <- split(y, fac)
## manage string rotation
srt <- 0
if(is.numeric(plabels$srt[1]))
srt <- plabels$srt[1]
else{
if(plabels$srt[1] == "horizontal")
srt <- 0
else if(plabels$srt[1] == "vertical")
srt <- 90
}
## Starts the display
## depends on the parametres horizontal and reverse
lead <- ifelse(pscore$reverse, -1, 1)
if(pscore$horizontal) {
## horizontal drawing
margin <- ifelse(pscore$reverse, lims$ylim[2], lims$ylim[1])
if(pscore$rug$draw)
margin <- if(is.unit(object@s.misc$rug)) convertUnit(object@s.misc$rug, typeFrom = "dimension", unitTo = "native", axisFrom = "y", valueOnly = TRUE) else object@s.misc$rug
# margin <- ifelse(pscore$reverse, lims$ylim[2], lims$ylim[1]) + lead * margin
for(i in 1:nlev) {
if(!is.na(curvess[[i]]$y[1])) {
y <- margin + lead * curvess[[i]]$y
panel.polygon(x = c(min(curvess[[i]]$x), curvess[[i]]$x, max(curvess[[i]]$x)), y = c(margin, y, margin), border = ppoly$border[i],
col = ppoly$col[i], lty = ppoly$lty[i], lwd = ppoly$lwd[i], alpha = ppoly$alpha[i])
if(nlev > 1) {
## indicate levels names for each curve
ymaxindex <- which.max(curvess[[i]]$y) ## places at the maximum
panel.text(x = curvess[[i]]$x[ymaxindex], y = y[ymaxindex], labels = names(curvess)[i], pos = ifelse(pscore$reverse, 1, 3), col = plabels$col[i],
cex = plabels$cex[i], alpha = plabels$alpha[i], srt = srt)
}
}
}
} else {
## vertical drawing
margin <- ifelse(pscore$reverse, lims$xlim[2], lims$xlim[1])
if(pscore$rug$draw)
margin <- if(is.unit(object@s.misc$rug)) convertUnit(object@s.misc$rug, typeFrom = "dimension", unitTo = "native", axisFrom = "x", valueOnly = TRUE) else object@s.misc$rug
# margin <- ifelse(pscore$reverse, lims$xlim[2], lims$xlim[1]) + lead * margin
for(i in 1:nlev) {
if(!is.na(curvess[[i]]$y[1])) {
x <- margin + lead * curvess[[i]]$y
panel.polygon(x = c(margin, x, margin), y = c(min(curvess[[i]]$x), curvess[[i]]$x, max(curvess[[i]]$x)), border = ppoly$border[i],
col = ppoly$col[i], lty = ppoly$lty[i], lwd = ppoly$lwd[i], alpha = ppoly$alpha[i])
if(nlev > 1) {
## indicate levels names for each curve
xmaxindex <- which.max(curvess[[i]]$y)
panel.text(x = x[xmaxindex], y = curvess[[i]]$x[xmaxindex], labels = names(curvess)[i], pos = ifelse(pscore$reverse, 2, 4), col = plabels$col[i], cex = plabels$cex[i], alpha = plabels$alpha[i], srt = srt)
}
}
}
}
})
## s1d.density: user function
## kernel, bandwidth and gridsize directly passed to the bkde function (for density calculation)
## if fill is FALSE, polygons density curves are transparent
s1d.density <- function(score, fac = gl(1, NROW(score)), kernel = c("normal", "box", "epanech", "biweight", "triweight"), bandwidth = NULL, gridsize = 450, col = NULL, fill = TRUE, facets = NULL,
plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
thecall <- .expand.call(match.call())
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if(NCOL(score) == 1 & NCOL(fac) == 1)
object <- multi.facets.C1(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple scores and/or multiple fac")
}
## multiple scores
else if(NCOL(score) > 1) {
if(NCOL(fac) == 1)
object <- multi.score.C1(thecall)
else
stop("Multiple scores are not allowed with multiple fac")
}
## multiple fac
else if(NCOL(fac) > 1) {
object <- multi.variables.C1(thecall, "fac")
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(kernel = match.arg(kernel), bandwidth = bandwidth, gridsize = gridsize, fill = fill, col = col))
if(storeData)
tmp_data <- list(score = score, fac = fac, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(score = thecall$score, fac = thecall$fac, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "C1.density", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = match.call())
## preparation
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/C1.gauss.R 0000644 0001762 0000144 00000025070 14550522117 014442 0 ustar ligges users #########################################################
## C1.gauss: here assumption: gaussian distribution ###
#########################################################
setClass(
Class = "C1.gauss",
contains = "ADEg.C1"
)
setMethod(
f = "initialize",
signature = "C1.gauss",
definition = function(.Object, data = list(score = NULL, fac = NULL, wt = NULL, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.C1 initialize
.Object@data$fac <- data$fac
.Object@data$wt <- data$wt
return(.Object)
})
setMethod(
f = "prepare",
signature = "C1.gauss",
definition = function(object) {
nameobj <- deparse(substitute(object))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
if(object@data$storeData) {
score <- object@data$score
fac <- object@data$fac
wt <- object@data$wt
} else {
score <- eval(object@data$score, envir = sys.frame(object@data$frame))
fac <- eval(object@data$fac, envir = sys.frame(object@data$frame))
wt <- eval(object@data$wt, envir = sys.frame(object@data$frame))
}
score <- as.matrix(score)[, 1] ## to manage 'score' when it is a data.frame with only one column
nlev <- nlevels(as.factor(fac))
## If axes are plotted, put a label for axis
if(adegtot$paxes$draw) {
if(is.null(object@g.args$xlab) & !adegtot$p1d$horizontal)
object@g.args$xlab <- "density"
if(is.null(object@g.args$ylab) & adegtot$p1d$horizontal)
object@g.args$ylab <- "density"
}
## setting colors
paramsToColor <- list(plabels = list(col = object@adeg.par$plabels$col, boxes = list(col = object@adeg.par$plabels$boxes$col)),
plines = list(col = object@adeg.par$plines$col),
ppolygons = list(border = object@adeg.par$ppolygons$border, col = object@adeg.par$ppolygons$col))
if(!(is.null(object@g.args$col) || (is.logical(object@g.args$col) && !object@g.args$col)))
adegtot <- modifyList(adegtot, col2adepar(ccol = object@g.args$col, pparamsToColor = paramsToColor, nnlev = nlev))
## if fill is FALSE, polygons density curves are transparent
if(!object@g.args$fill)
adegtot$ppolygons$col <- "transparent"
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
## statistics calculus
object@stats$means <- meanfacwt(score, fac, wt)
object@stats$var <- varfacwt(score, fac)
## here steps fixed, could be a argument of s1d.gauss
steps <- object@g.args$steps
nind <- table(fac)
gausscurv <- list()
if(object@adeg.par$p1d$horizontal)
xx <- seq(from = object@g.args$xlim[1], to = object@g.args$xlim[2], length.out = steps)
else
xx <- seq(from = object@g.args$ylim[1], to = object@g.args$ylim[2], length.out = steps)
for(i in 1:nlev) {
if(nind[i] == 0)
gausscurv[[i]] <- NA
else
gausscurv[[i]] <- dnorm(xx, mean = object@stats$means[i], sd = sqrt(object@stats$var[i]))
}
names(gausscurv) <- levels(fac)
lead <- ifelse(object@adeg.par$p1d$reverse, 1 , -1)
if(object@adeg.par$p1d$horizontal) {
Ylim <- object@g.args$ylim
if(is.null(object@s.misc$p1dReverse.update) || object@adeg.par$p1d$reverse != object@s.misc$p1dReverse.update ||
is.null(object@s.misc$Ylim.update) || any(Ylim != object@s.misc$Ylim.update)) {
if(is.null(object@g.args$ylim))
Ylim <- c(0, max(sapply(gausscurv, FUN = function(x) {ifelse(is.na(x[1]), 0, max(x)) / 0.85})))
if(object@adeg.par$p1d$rug$draw) {
ref <- ifelse(object@adeg.par$p1d$reverse, 2, 1)
margin <- Ylim[ref]
if(object@adeg.par$p1d$rug$draw)
margin <- object@adeg.par$p1d$rug$margin * abs(diff(Ylim))
object@s.misc$rug <- Ylim[ref]
Ylim[ref] <- Ylim[ref] + lead * margin
}
object@s.misc$Ylim.update <- Ylim
}
object@g.args$ylim <- Ylim
object@s.misc$p1dReverse.update <- object@adeg.par$p1d$reverse
} else {
Xlim <- object@g.args$xlim
if(is.null(object@s.misc$p1dReverse.update) || object@adeg.par$p1d$reverse != object@s.misc$p1dReverse.update ||
is.null(object@s.misc$Xlim.update) || any(Xlim != object@s.misc$Xlim.update)) {
if(is.null(object@g.args$xlim))
Xlim <- c(0, max(sapply(gausscurv, FUN = function(x) {ifelse(is.na(x[1]), 0, max(x)) / 0.85})))
if(object@adeg.par$p1d$rug$draw) {
ref <- ifelse(object@adeg.par$p1d$reverse, 2, 1)
margin <- Xlim[ref]
if(object@adeg.par$p1d$rug$draw)
margin <- object@adeg.par$p1d$rug$margin * abs(diff(Xlim))
object@s.misc$rug <- Xlim[ref]
Xlim[ref] <- Xlim[ref] + lead * margin
}
object@s.misc$Xlim.update <- Xlim
object@s.misc$p1dReverse.update <- object@adeg.par$p1d$reverse
}
object@g.args$xlim <- Xlim
}
object@stats$gausscurves <- gausscurv
assign(nameobj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "C1.gauss",
definition = function(object, x, y) {
## Drawing gauss curves as polygons (filled or not)
## one polygon per level
## y is the score
## get some parameters
pscore <- object@adeg.par$p1d
curvess <- object@stats$gausscurves
labels <- names(curvess)
lims <- current.panel.limits(unit = "native")
if(object@data$storeData)
fac <- object@data$fac
else
fac <- eval(object@data$fac, envir = sys.frame(object@data$frame))
nlev <- nlevels(as.factor(fac))
ppoly <- lapply(object@adeg.par$ppolygons, FUN = function(x) rep(x, length.out = nlev))
plabels <- lapply(object@adeg.par$plabels, FUN = function(x) rep(x, length.out = nlev))
## manage string rotation
srt <- 0
if(is.numeric(plabels$srt[1]))
srt <- plabels$srt[1]
else {
if(plabels$srt[1] == "horizontal")
srt <- 0
else if(plabels$srt[1] == "vertical")
srt <- 90
}
## Starts the display
## depends on the parametres horizontal and reverse
lead <- ifelse(pscore$reverse, -1, 1)
if(pscore$horizontal) {
## horizontal drawing
margin <- ifelse(pscore$reverse, lims$ylim[2], lims$ylim[1])
xx <- seq(from = lims$xlim[1], to = lims$xlim[2], length.out = object@g.args$steps)
if(pscore$rug$draw)
margin <- if(is.unit(object@s.misc$rug)) convertUnit(object@s.misc$rug, typeFrom = "dimension", unitTo = "native", axisFrom = "y", valueOnly = TRUE) else object@s.misc$rug
# margin <- ifelse(pscore$reverse, lims$ylim[2], lims$ylim[1]) + lead * margin
for(i in 1:nlev) {
if(!is.na(curvess[[i]][1])) {
y <- margin + lead * curvess[[i]]
panel.polygon(x = c(lims$xlim[1], xx, lims$xlim[2]), y = c(margin, y, margin) , border = ppoly$border[i],
col = ppoly$col[i], lty = ppoly$lty[i], lwd = ppoly$lwd[i], alpha = ppoly$alpha[i])
if(nlev > 1) {
## indicate levels names for each curve
ymaxindex <- which.max(curvess[[i]]) ## places at the maximum
panel.text(x = xx[ymaxindex], y = y[ymaxindex], labels = names(curvess)[i], pos = ifelse(pscore$reverse, 1, 3), col = plabels$col[i],
cex = plabels$cex[i], alpha = plabels$alpha[i], srt = srt)
}
}
}
} else {
## vertical drawing
margin <- ifelse(pscore$reverse, lims$xlim[2], lims$xlim[1])
yy <- seq(from = lims$ylim[1], to = lims$ylim[2], length.out = object@g.args$steps)
if(pscore$rug$draw)
margin <- if(is.unit(object@s.misc$rug)) convertUnit(object@s.misc$rug, typeFrom = "dimension", unitTo = "native", axisFrom = "x", valueOnly = TRUE) else object@s.misc$rug
# margin <- ifelse(pscore$reverse, lims$xlim[2], lims$xlim[1]) + lead * margin
for(i in 1:nlev) {
if(!is.na(curvess[[i]][1])) {
x <- margin + lead * curvess[[i]]
panel.polygon(x = c(margin, x, margin), y = c(lims$ylim[1], yy, lims$ylim[2]), border = ppoly$border[i],
col = ppoly$col[i], lty = ppoly$lty[i], lwd = ppoly$lwd[i], alpha = ppoly$alpha[i])
if(nlev > 1) {
xmaxindex <- which.max(curvess[[i]])
panel.text(x = x[xmaxindex], y = yy[xmaxindex], labels = names(curvess)[i], col = plabels$col[i], pos = ifelse(pscore$reverse, 2, 4),
cex = plabels$cex[i], alpha = plabels$alpha[i], srt = srt)
}
}
}
}
})
s1d.gauss <- function(score, fac = gl(1, NROW(score)), wt = rep(1, NROW(score)), steps = 200, col = NULL, fill = TRUE, facets = NULL,
plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
thecall <- .expand.call(match.call())
## parameters management
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if(NCOL(score) == 1 & NCOL(fac) == 1)
object <- multi.facets.C1(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple scores and/or multiple fac")
}
## multiple scores
else if(NCOL(score) > 1) {
if(NCOL(fac) == 1)
object <- multi.score.C1(thecall)
else
stop("Multiple scores are not allowed with multiple fac")
}
## multiple fac
else if(NCOL(fac) > 1) {
object <- multi.variables.C1(thecall, "fac")
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(steps = steps, fill = fill, col = col))
if(storeData)
tmp_data <- list(score = score, fac = fac, wt = wt, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(score = thecall$score, fac = thecall$fac, wt = thecall$wt, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "C1.gauss", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = match.call())
## preparation
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(!add & plot)
print(object)
invisible(object)
}
adegraphics/R/S2.traject.R 0000644 0001762 0000144 00000016735 14354572704 015016 0 ustar ligges users #########################################################
### s.traject ##
#########################################################
setClass(
Class= "S2.traject",
contains = "ADEg.S2"
)
setMethod(
f = "initialize",
signature = "S2.traject",
definition = function(.Object, data = list(dfxy = NULL, fac = NULL, labels = NULL, xax = 1, yax = 2, frame = 0, storeData = TRUE), ...) {
.Object <- callNextMethod(.Object, data = data, ...) ## ADEg.S2 initialize
.Object@data$labels <- data$labels
.Object@data$fac <- data$fac
return(.Object)
})
setMethod(
f = "prepare",
signature = "S2.traject",
definition = function(object) {
name_obj <- deparse(substitute(object))
if(object@data$storeData)
fac <- as.factor(object@data$fac)
else
fac <- as.factor(eval(object@data$fac, envir = sys.frame(object@data$frame)))
## pre-management of graphics parameters
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(object@adeg.par)
## change default for some parameters
if(is.null(object@adeg.par$porigin$include) & (any(names(object@g.args) %in% c("Sp", "nbobject"))))
adegtot$porigin$include <- FALSE
## setting colors
paramsToColor <- list(ppoints = list(col = object@adeg.par$ppoints$col, fill = object@adeg.par$ppoints$fill),
plabels = list(col = object@adeg.par$plabels$col, boxes = list(border = object@adeg.par$plabels$boxes$border)),
plines = list(col = object@adeg.par$plines$col))
if(!(is.null(object@g.args$col) || (is.logical(object@g.args$col) && !object@g.args$col)))
adegtot <- modifyList(adegtot, col2adepar(ccol = object@g.args$col, pparamsToColor = paramsToColor, nnlev = nlevels(fac)))
## object modification before calling inherited method
object@adeg.par <- adegtot
callNextMethod() ## prepare graph
## never optimized labels for s.traject
object@adeg.par$plabels$optim <- FALSE
assign(name_obj, object, envir = parent.frame())
})
setMethod(
f = "panel",
signature = "S2.traject",
definition = function(object, x, y) {
if(object@data$storeData) {
fact <- object@data$fac
labels <- object@data$labels
} else {
fact <- eval(object@data$fac, envir = sys.frame(object@data$frame))
labels <- eval(object@data$labels, envir = sys.frame(object@data$frame))
}
todrawX <- split(x, fact)
todrawY <- split(y, fact)
sizelevels <- sapply(todrawX, length)
if(!is.null(object@g.args$order))
orderdraw <- split(order, fact)
else
orderdraw <- lapply(sizelevels, FUN = function(x) if(x > 0) 1:x else NULL)
## ordrerdraw is a list used to recycle graphical parameters
setparam <- function(params, nblevel, sizelevels) {
## for param begin and end or repetition
if(length(params) == nblevel)
return(mapply(params, FUN = function(x, y) rep(x, length.out = y), sizelevels, SIMPLIFY = FALSE))
else
return(mapply(sizelevels, FUN = function(x, y) rep(params, length.out = x), SIMPLIFY = FALSE))
}
parrows <- lapply(object@adeg.par$parrows, setparam, nblevel = length(todrawX), sizelevels = sizelevels)
plines <- lapply(object@adeg.par$plines, setparam, nblevel = length(todrawX), sizelevels = sizelevels)
ppoints <- lapply(object@adeg.par$ppoints, setparam, nblevel = length(todrawX), sizelevels = sizelevels)
for(i in 1:length(todrawX)) {
if(length(todrawX[[i]]) > 0)
panel.points(x = todrawX[[i]], y = todrawY[[i]], col = ppoints$col[[i]], cex = ppoints$cex[[i]], pch = ppoints$pch[[i]], fill = ppoints$fill[[i]])
}
for(i in 1:length(todrawX)) {
if(length(todrawX[[i]]) > 1) {
suborder <- orderdraw[[i]]
for(j in 1:(length(todrawX[[i]]) - 1)) {
panel.arrows(x0 = todrawX[[i]][suborder[j]], y0 = todrawY[[i]][suborder[j]],
x1 = todrawX[[i]][suborder[j + 1]], y1 = todrawY[[i]][suborder[j + 1]],
angle = parrows$angle[[i]][suborder[j + 1]], length = parrows$length[[i]][suborder[j + 1]],
ends = parrows$end[[i]][suborder[j + 1]], lwd = plines$lwd[[i]][suborder[j + 1]],
col = plines$col[[i]][suborder[j + 1]], lty = plines$lty[[i]][suborder[j + 1]])
}
}
}
if(any(object@adeg.par$plabels$cex > 0)) {
## draws labels in the middle part of the trajectory
middl <- sapply(orderdraw, FUN = function(x) floor(length(x) / 2))
x <- y <- rep(NA, length(middl))
for(i in 1:length(middl)) {
if(length(todrawX[[i]]) > 1) {
x[i] <- (todrawX[[i]][suborder[middl[i]]] + todrawX[[i]][suborder[middl[i]+1]]) / 2
y[i] <- (todrawY[[i]][suborder[middl[i]]] + todrawY[[i]][suborder[middl[i]+1]]) / 2
}
}
adeg.panel.label(x, y, labels = labels, plabels = object@adeg.par$plabels)
}
})
s.traject <- function(dfxy, fac = gl(1, nrow(dfxy)), order, labels = levels(fac), xax = 1, yax = 2, col = NULL, facets = NULL, plot = TRUE, storeData = TRUE, add = FALSE, pos = -1, ...) {
## evaluation of some parameters (required for multiplot)
thecall <- .expand.call(match.call())
labels <- eval(thecall$labels, envir = sys.frame(sys.nframe() + pos))
fac <- eval(thecall$fac, envir = sys.frame(sys.nframe() + pos))
df <- try(as.data.frame(eval(thecall$dfxy, envir = sys.frame(sys.nframe() + pos))), silent = TRUE)
if(inherits(df, "try-error") | is.null(thecall$dfxy)) ## non convenient dfxy argument
stop("non convenient selection for dfxy (can not be converted to dataframe)")
if(missing(fac))
stop("no factor specified")
if(NCOL(fac) == 1) {
fac <- as.factor(fac)
if(length(labels) != nlevels(fac))
stop("wrong number of labels")
}
## parameters sorted
sortparameters <- sortparamADEg(...)
## facets
if(!is.null(facets)) {
if((length(xax) == 1 & length(yax) == 1) & NCOL(fac) == 1)
object <- multi.facets.S2(thecall, sortparameters$adepar, samelimits = sortparameters$g.args$samelimits)
else
stop("Facets are not allowed with multiple xax/yax or multiple fac")
}
## multiple axes
else if((length(xax) > 1 | length(yax) > 1)) {
if(NCOL(fac) == 1)
object <- multi.ax.S2(thecall)
else
stop("Multiple xax/yax are not allowed with multiple fac")
}
## multiple fac
else if(NCOL(fac) > 1) {
object <- multi.variables.S2(thecall, "fac")
}
## simple ADEg graphic
else {
if(length(sortparameters$rest))
warning(c("Unused parameters: ", paste(unique(names(sortparameters$rest)), " ", sep = "")), call. = FALSE)
## creation of the ADEg object
g.args <- c(sortparameters$g.args, list(order = thecall$order, col = col))
if(storeData)
tmp_data <- list(dfxy = dfxy, xax = xax, yax = yax, labels = labels, fac = fac, frame = sys.nframe() + pos, storeData = storeData)
else
tmp_data <- list(dfxy = thecall$dfxy, xax = xax, yax = yax, labels = thecall$labels, fac = thecall$fac, frame = sys.nframe() + pos, storeData = storeData)
object <- new(Class = "S2.traject", data = tmp_data, adeg.par = sortparameters$adepar, trellis.par = sortparameters$trellis, g.args = g.args, Call = as.call(thecall))
## preparation
prepare(object)
setlatticecall(object)
if(add)
object <- add.ADEg(object)
}
if(! add & plot)
print(object)
invisible(object)
}
adegraphics/R/multiplot.R 0000644 0001762 0000144 00000060461 13742303021 015103 0 ustar ligges users #######################################################################
## S2. Class ##
#######################################################################
multi.ax.S2 <- function(thecall) {
## function to plot ADEgS when an s.* function is called and 'xax/yax' arguments are vectors of length > 1
listGraph <- list()
thenewcall <- thecall
## update some arguments
thenewcall$pos <- eval(thenewcall$pos) - 3
thenewcall$plot <- FALSE
if(thenewcall[[1]] == "s.value") {
if(is.null(thenewcall$psub.position))
thenewcall$psub.position <- "topleft"
}
## evaluate some arguments in the correct frame
xax <- eval(thecall$xax, envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
yax <- eval(thecall$yax, envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
## create ADEg plots
for(i in yax) {
for(j in xax) {
thenewcall$xax <- j
thenewcall$yax <- i
thenewcall$psub.text <- paste("xax=", j, ", yax=", i, collapse = "", sep = "")
listGraph <- c(listGraph, do.call(as.character(thenewcall[[1]]), thenewcall[-1]))
}
}
## create the multiplot ADEgS
names(listGraph) <- paste("x", apply(expand.grid(xax, yax), 1, paste, collapse = "y"), sep = "")
posmatrix <- layout2position(c(length(yax), length(xax)), ng = length(listGraph), square = FALSE)
object <- new(Class = "ADEgS", ADEglist = listGraph, positions = posmatrix, add = matrix(0, ncol = length(listGraph), nrow = length(listGraph)), Call = as.call(thecall))
return(object)
}
##
##
##
multi.facets.S2 <- function(thecall, adepar, samelimits = TRUE) {
## function to plot ADEgS when the 'facets' argument is used
listGraph <- list()
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(adepar)
## update some arguments in the newcall
thenewcall <- thecall
thenewcall$plot <- FALSE
thenewcall$pos <- eval(thenewcall$pos) - 3
thenewcall$facets <- NULL
## evaluate some arguments in the correct frame
if(thecall[[1]] != "s.match")
dfxy <- eval(thecall$dfxy, envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
else
dfxy <- do.call("rbind", list(thecall$dfxy1, thecall$dfxy2), envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
facets <- factor(eval(thecall$facets, envir = sys.frame(sys.nframe() + thenewcall$pos + 2)))
## same limits for all sub-graphics
if((isTRUE(samelimits) | is.null(samelimits)) & (thecall[[1]] != "s.corcircle")) {
xax <- eval(thecall$xax, envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
yax <- eval(thecall$yax, envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
if(is.null(thenewcall$Sp))
lim.global <- setlimits2D(minX = min(dfxy[, xax]), maxX = max(dfxy[, xax]), minY = min(dfxy[, yax]), maxY = max(dfxy[, yax]),
origin = adegtot$porigin$origin, aspect.ratio = adegtot$paxes$aspectratio, includeOr = adegtot$porigin$include)
else { ## Sp: ex map, alors par defaut on prend la bbox
limsSp <- bbox(eval(thenewcall$Sp))
lim.global <- setlimits2D(minX = limsSp[1, 1], maxX = limsSp[1, 2], minY = limsSp[2, 1], maxY = limsSp[2, 2], origin = rep(adegtot$porigin$origin, le = 2), aspect.ratio = adegtot$paxes$aspectratio, includeOr = adegtot$porigin$include)
}
if(is.null(thecall$xlim))
thenewcall$xlim <- lim.global$xlim
if(is.null(thecall$ylim))
thenewcall$ylim <- lim.global$ylim
}
## creation of the plots (ADEg objects)
for(i in 1:nlevels(facets)) {
thenewcall$psub.text <- levels(facets)[i]
## specific arguments for the different functions
if(thecall[[1]] == "s.match") {
thenewcall$dfxy1 <- call("[[", call("split", call("as.data.frame", thecall$dfxy1), thecall$facets), i)
thenewcall$dfxy2 <- call("[[", call("split", call("as.data.frame", thecall$dfxy2), thecall$facets), i)
thenewcall$labels <- call("[[", call("split", thecall$labels, thecall$facets), i)
} else {
thenewcall$dfxy <- call("[[", call("split", call("as.data.frame", thecall$dfxy), thecall$facets), i)
}
if(thecall[[1]] == "s.class") {
thenewcall$fac <- call("[[", call("split", thecall$fac, thecall$facets), i)
thenewcall$wt <- call("[[", call("split", thecall$wt, thecall$facets), i)
}
if(thecall[[1]] == "s.distri")
thenewcall$dfdistri <- call("[[", call("split", thecall$dfdistri, thecall$facets), i)
if(thecall[[1]] == "s.image")
thenewcall$z <- call("[[", call("split", thecall$z, thecall$facets), i)
if(thecall[[1]] == "s.label" || thecall[[1]] == "s.corcircle"|| thecall[[1]] == "s.arrow")
thenewcall$labels <- call("[[", call("split", thecall$labels, thecall$facets), i)
if(thecall[[1]] == "s.logo")
thenewcall$logos <- call("[[", call("split", thecall$logos, thecall$facets), i)
if(thecall[[1]] == "s.traject") {
thenewcall$fac <- call("[[", call("split", thecall$fac, thecall$facets), i)
if(!is.null(thecall$order))
thenewcall$order <- call("[[", call("split", thecall$order, thecall$facets), i)
}
if(thecall[[1]] == "s.value") {
thenewcall$z <- call("[[", call("split", thecall$z, thecall$facets), i)
if(is.null(thenewcall$breaks)) {
## same breaks for all groups
z <- eval(thecall$z, envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
breaks <- pretty(z, thenewcall$n)
thenewcall$breaks <- breakstest(breaks, z, n = length(breaks))
}
if(is.null(thenewcall$psub.position))
thenewcall$psub.position <- "topleft"
}
listGraph <- c(listGraph, do.call(as.character(thenewcall[[1]]), thenewcall[-1]))
}
## creation of the multi-plot (ADEgS object)
names(listGraph) <- levels(facets)
posmatrix <- layout2position(.n2mfrow(nlevels(facets)), ng = nlevels(facets), square = FALSE)
object <- new(Class = "ADEgS", ADEglist = listGraph, positions = posmatrix, add = matrix(0, ncol = nlevels(facets), nrow = nlevels(facets)), Call = as.call(thecall))
## change pos et frame a posteriori ??
return(object)
}
##
##
##
multi.variables.S2 <- function(thecall, arg.vary) {
## function to plot ADEgS when an s.* function is called and an argument is multivariable (e.g., z in s.value, fac in s.class, etc)
## the name of the varying argument is in name.vary
listGraph <- list()
thenewcall <- thecall
## update some arguments
thenewcall$pos <- eval(thecall$pos) - 3
thenewcall$plot <- FALSE
## evaluate some arguments in the correct frame
name.vary <- thenewcall[[arg.vary]]
dfvary <- eval(name.vary, envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
## create ADEg plots
for(j in 1:ncol(dfvary)) {
thenewcall[[arg.vary]] <- call("[", name.vary, substitute(1:nrow(name.vary)), j)
thenewcall$psub.text <- colnames(dfvary)[j]
if(thenewcall[[1]] == "s.class" || thenewcall[[1]] == "s.traject") {
thenewcall$labels <- call("levels", call("as.factor", thenewcall[[arg.vary]]))
}
if(thenewcall[[1]] == "s.value") {
if(is.null(thenewcall$psub.position))
thenewcall$psub.position <- "topleft"
}
listGraph <- c(listGraph, do.call(as.character(thenewcall[[1]]), thenewcall[-1]))
}
## create the multiplot ADEgS
names(listGraph) <- colnames(dfvary)
posmatrix <- layout2position(.n2mfrow(ncol(dfvary)), ng = ncol(dfvary), square = FALSE)
object <- new(Class = "ADEgS", ADEglist = listGraph, positions = posmatrix, add = matrix(0, ncol = ncol(dfvary), nrow = ncol(dfvary)), Call = as.call(thecall))
return(object)
}
#######################################################################
## C1. Class ##
#######################################################################
multi.score.C1 <- function(thecall) {
## function to plot ADEgS when an s1d.* function is called and score is a data.frame with multiple columns
listGraph <- list()
thenewcall <- thecall
## update some arguments
thenewcall$pos <- eval(thenewcall$pos) - 3
thenewcall$plot <- FALSE
## evaluate some arguments in the correct frame
if(thenewcall[[1]] != "s1d.interval") {
score <- eval(thecall$score, envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
name.score <- thecall$score
} else {
score <- eval(thecall$score1, envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
name.score <- thecall$score1
}
nc <- ncol(score)
## create ADEg plots
for(i in 1:nc) {
thenewcall$psub.text <- colnames(score)[i]
## specific arguments for the different functions
if(thenewcall[[1]] != "s1d.interval") {
thenewcall$score <- call("[", thecall$score, substitute(1:nrow(name.score)), i)
} else {
thenewcall$score1 <- call("[", thecall$score1, substitute(1:nrow(name.score)), i)
thenewcall$score2 <- call("[", thecall$score2, substitute(1:nrow(name.score)), i)
}
if(thenewcall[[1]] == "s1d.barchart") {
if(is.null(thenewcall$labels))
thenewcall$labels <- call("rownames", thecall$score)
}
listGraph <- c(listGraph, do.call(as.character(thenewcall[[1]]), thenewcall[-1]))
}
## create the multiplot ADEgS
names(listGraph) <- colnames(score)
posmatrix <- layout2position(.n2mfrow(nc), ng = nc)
object <- new(Class = "ADEgS", ADEglist = listGraph, positions = posmatrix, add = matrix(0, ncol = length(listGraph), nrow = length(listGraph)), Call = as.call(thecall))
return(object)
}
##
##
##
multi.facets.C1 <- function(thecall, adepar, samelimits = TRUE) {
## function to plot ADEgS when the 'facets' argument is used
listGraph <- list()
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(adepar)
## update some arguments in the newcall
thenewcall <- thecall
thenewcall$plot <- FALSE
thenewcall$pos <- eval(thenewcall$pos) - 3
thenewcall$facets <- NULL
## evaluate some arguments in the correct frame
if(thenewcall[[1]] != "s1d.interval") {
score <- eval(thecall$score, envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
} else {
score1 <- eval(thecall$score1, envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
score2 <- eval(thecall$score2, envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
score <- c(score1, score2)
}
facets <- factor(eval(thecall$facets, envir = sys.frame(sys.nframe() + thenewcall$pos + 2)))
## same limits for all graphics
if(isTRUE(samelimits) | is.null(samelimits)) {
lim.axe1 <- setlimits1D(min(score), max(score), origin = adegtot$porigin$origin[1], includeOr = adegtot$porigin$include)
if(adegtot$p1d$horizontal & is.null(thecall$xlim)) {
thenewcall$xlim <- lim.axe1
}
if(!adegtot$p1d$horizontal & is.null(thecall$ylim)) {
thenewcall$ylim <- lim.axe1
}
}
## creation of the plots (ADEg objects)
for(i in 1:nlevels(facets)) {
thenewcall$psub.text <- levels(facets)[i]
if(thecall[[1]] == "s1d.interval") {
thenewcall$score1 <- call("[[", call("split", thecall$score1, thecall$facets), i)
thenewcall$score2 <- call("[[", call("split", thecall$score2, thecall$facets), i)
} else {
thenewcall$score <- call("[[", call("split", thecall$score, thecall$facets), i)
}
if(thecall[[1]] == "s1d.barchart" & !is.null(thecall$labels))
thenewcall$labels <- call("[[", call("split", thecall$labels, thecall$facets), i)
if(thecall[[1]] == "s1d.barchart" | thecall[[1]] == "s1d.dotplot" | thecall[[1]] == "s1d.curve" | thecall[[1]] == "s1d.interval")
thenewcall$at <- call("[[", call("split", thecall$at, thecall$facets), i)
if(thecall[[1]] == "s1d.density" | thecall[[1]] == "s1d.gauss")
thenewcall$fac <- call("[[", call("split", thecall$fac, thecall$facets), i)
if(thecall[[1]] == "s1d.gauss")
thenewcall$wt <- call("[[", call("split", thecall$wt, thecall$facets), i)
listGraph <- c(listGraph, do.call(as.character(thenewcall[[1]]), thenewcall[-1]))
}
## creation of the multi-plot (ADEgS object)
names(listGraph) <- levels(facets)
posmatrix <- layout2position(.n2mfrow(nlevels(facets)), ng = nlevels(facets))
object <- new(Class = "ADEgS", ADEglist = listGraph, positions = posmatrix, add = matrix(0, ncol = nlevels(facets), nrow = nlevels(facets)), Call = as.call(thecall))
## same limits for all graphics when the second axis is done by intern calculations
if(inherits(object[[1]], "C1.density") | inherits(object[[1]], "C1.gauss") | inherits(object[[1]], "C1.hist")) {
if(isTRUE(samelimits) | is.null(samelimits)) {
cc <- object@Call
if(adegtot$p1d$horizontal & is.null(thecall$ylim)) {
Ylim <- range(sapply(object@ADEglist, function(x) x@g.args$ylim))
update(object, ylim = Ylim)
object@Call <- cc # this call does not include the ylim update
}
if(!adegtot$p1d$horizontal & is.null(thecall$xlim)) {
Xlim <- range(sapply(listGraph, function(x) x@g.args$xlim))
update(object, xlim = Xlim)
object@Call <- paste(substr(cc, 1, nchar(cc) - 1), ", xlim = c(", Xlim[1], ",", Xlim[2], ")", sep = "")
object@Call <- cc # this call does not include the xlim update
}
}
}
## change pos et frame a posteriori ??
return(object)
}
##
##
##
multi.variables.C1 <- function(thecall, arg.vary) {
## function to plot ADEgS when an s1d.* function is called and an argument is multivariable (e.g., fac in s1d.density)
## the name of the varying argument is in name.vary
listGraph <- list()
thenewcall <- thecall
## update some arguments
thenewcall$pos <- eval(thecall$pos) - 3
thenewcall$plot <- FALSE
## evaluate some arguments in the correct frame
name.vary <- thenewcall[[arg.vary]]
dfvary <- eval(name.vary, envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
## create ADEg plots
for(j in 1:ncol(dfvary)) {
thenewcall[[arg.vary]] <- call("[", name.vary, substitute(1:nrow(name.vary)), j)
thenewcall$psub.text <- colnames(dfvary)[j]
listGraph <- c(listGraph, do.call(as.character(thenewcall[[1]]), thenewcall[-1]))
}
## create the multiplot ADEgS
names(listGraph) <- colnames(dfvary)
posmatrix <- layout2position(.n2mfrow(ncol(dfvary)), ng = ncol(dfvary))
object <- new(Class = "ADEgS", ADEglist = listGraph, positions = posmatrix, add = matrix(0, ncol = ncol(dfvary), nrow = ncol(dfvary)), Call = as.call(thecall))
return(object)
}
#######################################################################
## S1. Class ##
#######################################################################
multi.score.S1 <- function(thecall) {
## function to plot ADEgS when an s1d.* function is called and score is a data.frame with multiple columns
listGraph <- list()
thenewcall <- thecall
## update some arguments
thenewcall$pos <- eval(thenewcall$pos) - 3
thenewcall$plot <- FALSE
## evaluate some arguments in the correct frame
if(thenewcall[[1]] != "s1d.match") {
score <- eval(thecall$score, envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
name.score <- thecall$score
} else {
score <- eval(thecall$score1, envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
name.score <- thecall$score1
}
## create ADEg plots
nc <- ncol(score)
for(i in 1:nc) {
## specific arguments for the different functions
if(thenewcall[[1]] != "s1d.match") {
thenewcall$score <- call("[", thecall$score, substitute(1:nrow(name.score)), i)
} else {
thenewcall$score1 <- call("[", thecall$score1, substitute(1:nrow(name.score)), i)
thenewcall$score2 <- call("[", thecall$score2, substitute(1:nrow(name.score)), i)
}
thenewcall$psub.text <- colnames(score)[i]
listGraph <- c(listGraph, do.call(as.character(thenewcall[[1]]), thenewcall[-1]))
}
## create the multiplot ADEgS
names(listGraph) <- colnames(score)
posmatrix <- layout2position(.n2mfrow(nc), ng = nc)
object <- new(Class = "ADEgS", ADEglist = listGraph, positions = posmatrix, add = matrix(0, ncol = length(listGraph), nrow = length(listGraph)), Call = as.call(thecall))
return(object)
}
##
##
##
multi.facets.S1 <- function(thecall, adepar, samelimits = TRUE) {
## function to plot ADEgS when the 'facets' argument is used
listGraph <- list()
oldparamadeg <- adegpar()
on.exit(adegpar(oldparamadeg))
adegtot <- adegpar(adepar)
## update some arguments in the newcall
thenewcall <- thecall
thenewcall$plot <- FALSE
thenewcall$pos <- eval(thenewcall$pos) - 3
thenewcall$facets <- NULL
## evaluate some arguments in the correct frame
if(thenewcall[[1]] != "s1d.match") {
score <- eval(thecall$score, envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
} else {
score1 <- eval(thecall$score1, envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
score2 <- eval(thecall$score2, envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
score <- c(score1, score2)
}
facets <- factor(eval(thecall$facets, envir = sys.frame(sys.nframe() + thenewcall$pos + 2)))
## same limits for all graphics
if(isTRUE(samelimits) | is.null(samelimits)) {
lim.global <- setlimits1D(min(score), max(score), origin = adegtot$porigin$origin[1], includeOr = adegtot$porigin$include)
if(adegtot$p1d$horizontal & is.null(thecall$xlim))
thenewcall$xlim <- lim.global
if(!adegtot$p1d$horizontal & is.null(thecall$ylim))
thenewcall$ylim <- lim.global
}
## creation of the plots (ADEg objects)
for(i in 1:nlevels(facets)) {
thenewcall$psub.text <- levels(facets)[i]
if(thecall[[1]] == "s1d.match") {
thenewcall$score1 <- call("[[", call("split", thecall$score1, thecall$facets), i)
thenewcall$score2 <- call("[[", call("split", thecall$score2, thecall$facets), i)
thenewcall$labels <- call("[[", call("split", thecall$labels, thecall$facets), i)
} else {
thenewcall$score <- call("[[", call("split", thecall$score, thecall$facets), i)
}
if(thecall[[1]] == "s1d.label" & !is.null(thecall$labels))
thenewcall$labels <- call("[[", call("split", thecall$labels, thecall$facets), i)
if(thecall[[1]] == "s1d.class") {
thenewcall$fac <- call("[[", call("split", thecall$fac, thecall$facets), i)
thenewcall$wt <- call("[[", call("split", thecall$wt, thecall$facets), i)
}
if(thecall[[1]] == "s1d.distri")
thenewcall$dfdistri <- call("[[", call("split", thecall$dfdistri, thecall$facets), i)
if(thecall[[1]] == "s1d.boxplot")
thenewcall$fac <- call("[[", call("split", thecall$fac, thecall$facets), i)
listGraph <- c(listGraph, do.call(as.character(thenewcall[[1]]), thenewcall[-1]))
}
## creation of the multi-plot (ADEgS object)
names(listGraph) <- levels(facets)
posmatrix <- layout2position(.n2mfrow(nlevels(facets)), ng = nlevels(facets))
object <- new(Class = "ADEgS", ADEglist = listGraph, positions = posmatrix, add = matrix(0, ncol = nlevels(facets), nrow = nlevels(facets)), Call = as.call(thecall))
## change pos et frame a posteriori ??
return(object)
}
##
##
##
multi.variables.S1 <- function(thecall, arg.vary) {
## function to plot ADEgS when an s1d.* function is called and an argument is multivariable (e.g., z in fac in s1d.class)
## the name of the varying argument is in name.vary
listGraph <- list()
thenewcall <- thecall
## update some arguments
thenewcall$pos <- eval(thecall$pos) - 3
thenewcall$plot <- FALSE
## evaluate some arguments in the correct frame
name.vary <- thenewcall[[arg.vary]]
dfvary <- eval(name.vary, envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
## create ADEg plots
for(j in 1:ncol(dfvary)) {
thenewcall[[arg.vary]] <- call("[", name.vary, substitute(1:nrow(name.vary)), j)
thenewcall$psub.text <- colnames(dfvary)[j]
if(thenewcall[[1]] == "s1d.class")
thenewcall$labels <- call("levels", call("as.factor", thenewcall[[arg.vary]]))
if(thenewcall[[1]] == "s1d.boxplot" || thenewcall[[1]] == "s1d.distri")
thenewcall$at <- call("seq", 1, call("nlevels", call("as.factor", thenewcall[[arg.vary]])))
listGraph <- c(listGraph, do.call(as.character(thenewcall[[1]]), thenewcall[-1]))
}
## create the multiplot ADEgS
names(listGraph) <- colnames(dfvary)
posmatrix <- layout2position(.n2mfrow(ncol(dfvary)), ng = ncol(dfvary), square = FALSE)
object <- new(Class = "ADEgS", ADEglist = listGraph, positions = posmatrix, add = matrix(0, ncol = ncol(dfvary), nrow = ncol(dfvary)), Call = as.call(thecall))
return(object)
}
#######################################################################
## Tr. Class ##
#######################################################################
multi.facets.Tr <- function(thecall, samelimits = TRUE) {
## function to plot ADEgS when the 'facets' argument is used
listGraph <- list()
## update some arguments in the newcall
thenewcall <- thecall
thenewcall$plot <- FALSE
thenewcall$pos <- eval(thenewcall$pos) - 3
thenewcall$facets <- NULL
## evaluate some arguments in the correct frame
if(thecall[[1]] != "triangle.match")
dfxyz <- eval(thecall$dfxyz, envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
else
dfxyz <- do.call("rbind", list(thecall$dfxyz1, thecall$dfxyz2), envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
facets <- factor(eval(thecall$facets, envir = sys.frame(sys.nframe() + thenewcall$pos + 2)))
## same limits for all graphics
if(isTRUE(samelimits) | is.null(samelimits)) {
#lim.global <- .trranges(df = dfxyz, scale = thecall$scale, min3 = NULL, max3 = NULL)
lim.global <- .trranges(df = dfxyz, adjust = TRUE, min3 = NULL, max3 = NULL)
if(is.null(thecall$min3d))
thenewcall$min3d <- lim.global$mini
if(is.null(thecall$max3d))
thenewcall$max3d <- lim.global$maxi
}
## creation of the plots (ADEg objects)
for(i in 1:nlevels(facets)) {
thenewcall$psub.text <- levels(facets)[i]
## specific arguments for the different functions
if(thecall[[1]] == "triangle.match") {
thenewcall$dfxyz1 <- call("[[", call("split", call("as.data.frame", thecall$dfxyz1), thecall$facets), i)
thenewcall$dfxyz2 <- call("[[", call("split", call("as.data.frame", thecall$dfxyz2), thecall$facets), i)
thenewcall$labels <- call("[[", call("split", thecall$labels, thecall$facets), i)
} else {
thenewcall$dfxyz <- call("[[", call("split", call("as.data.frame", thecall$dfxyz), thecall$facets), i)
}
if(thecall[[1]] == "triangle.class") {
thenewcall$fac <- call("[[", call("split", thecall$fac, thecall$facets), i)
thenewcall$wt <- call("[[", call("split", thecall$wt, thecall$facets), i)
}
if(thecall[[1]] == "triangle.label")
thenewcall$labels <- call("[[", call("split", thecall$labels, thecall$facets), i)
listGraph <- c(listGraph, do.call(as.character(thenewcall[[1]]), thenewcall[-1]))
}
## creation of the multi-plot (ADEgS object)
names(listGraph) <- levels(facets)
posmatrix <- layout2position(.n2mfrow(nlevels(facets)), ng = nlevels(facets))
object <- new(Class = "ADEgS", ADEglist = listGraph, positions = posmatrix, add = matrix(0, ncol = nlevels(facets), nrow = nlevels(facets)), Call = as.call(thecall))
## change pos et frame a posteriori ??
return(object)
}
##
##
##
multi.variables.Tr <- function(thecall, arg.vary) {
## function to plot ADEgS when an triangle.* function is called and an argument is multivariable (e.g., fac in triangle.class, etc)
## the name of the varying argument is in name.vary
listGraph <- list()
thenewcall <- thecall
## update some arguments
thenewcall$pos <- eval(thecall$pos) - 3
thenewcall$plot <- FALSE
## evaluate some arguments in the correct frame
name.vary <- thenewcall[[arg.vary]]
dfvary <- eval(name.vary, envir = sys.frame(sys.nframe() + thenewcall$pos + 2))
## create ADEg plots
for(j in 1:ncol(dfvary)) {
thenewcall[[arg.vary]] <- call("[", name.vary, substitute(1:nrow(name.vary)), j)
thenewcall$psub.text <- colnames(dfvary)[j]
if(thenewcall[[1]] == "triangle.class") {
thenewcall$labels <- call("levels", call("as.factor", thenewcall[[arg.vary]]))
}
listGraph <- c(listGraph, do.call(as.character(thenewcall[[1]]), thenewcall[-1]))
}
## create the multiplot ADEgS
names(listGraph) <- colnames(dfvary)
posmatrix <- layout2position(.n2mfrow(ncol(dfvary)), ng = ncol(dfvary))
object <- new(Class = "ADEgS", ADEglist = listGraph, positions = posmatrix, add = matrix(0, ncol = ncol(dfvary), nrow = ncol(dfvary)), Call = as.call(thecall))
return(object)
}
adegraphics/vignettes/ 0000755 0001762 0000144 00000000000 14774707431 014552 5 ustar ligges users adegraphics/vignettes/adegraphics.bib 0000644 0001762 0000144 00000002645 14115624042 017472 0 ustar ligges users @article{Siberchicot2017,
author = {Aurélie Siberchicot and Alice Julien-Laferrière and Anne-Béatrice Dufour and Jean Thioulouse and Stéphane Dray},
title = {{adegraphics: An S4 Lattice-Based Package for the
Representation of Multivariate Data}},
year = {2017},
journal = {{The R Journal}},
url = {https://journal.r-project.org/archive/2017/RJ-2017-042/index.html},
pages = {198--212},
volume = {9},
number = {2}
}
@article{DrayJombart2011,
title = {Revisiting Guerry's data: introducing spatial constraints in multivariate analysis},
author = {Stéphane Dray and Thibaut Jombart},
journal = {{The Annals of Applied Statistics}},
year = {2011},
volume = {5},
pages = {2278-2299}
}
@book{Sarkar2008,
title={Lattice: multivariate data visualization with R},
author={Deepayan Sarkar},
year={2008},
publisher={Springer},
url = {https://doi.org/10.1007/978-0-387-75969-2}
}
@book{Murrell2005,
title={R graphics},
author={Paul Murrell},
year={2005},
publisher={Chapman \& Hall/CRC Press},
url = {https://www.e-reading.club/bookreader.php/137370/C486x_APPb.pdf}
}
@article{Dray2007,
author = {Stéphane Dray and Anne-Béatrice Dufour},
journal = {Journal of Statistical Software},
number = {4},
pages = {1--20},
title = {{The ade4 Package: Implementing the Duality Diagram for Ecologists}},
volume = {22},
year = {2007},
url = {https://doi.org/10.18637/jss.v022.i04}
}
adegraphics/vignettes/FAQ.Rmd 0000644 0001762 0000144 00000004021 14647411121 015605 0 ustar ligges users ---
title: "Frequently Asked Questions"
author: "Aurélie Siberchicot, Stéphane Dray, Jean Thioulouse"
date: '`r Sys.Date()`'
output:
html_vignette:
number_sections: yes
toc: yes
vignette: >
%\VignetteEngine{knitr::rmarkdown}
%\VignetteIndexEntry{Frequently Asked Questions}
%!\VignetteEncoding{UTF-8}
\usepackage[utf8]{inputenc}
---
```{r}
set.seed(2564)
library(ade4)
library(adegraphics)
```
# How to personalize plots
## How to update title axes?
```{r}
df <- data.frame(x = rep(1:10,1),
y = rep(1:10, each = 10),
ms_li = runif(100, min = -5, max = 4))
s.value(df[, 1:2], df$ms_li,
paxes.draw = TRUE)
```
### Size titles on axes
`xlab.cex` and `ylab.cex` manage the size titles on the `x` and `y` axes.
```{r}
s.value(df[, 1:2], df$ms_li,
paxes.draw = TRUE,
xlab = "Longitude", xlab.cex = 0.5,
ylab = "Latitude", ylab.cex = 0.5
)
```
### Size labels on axes
`scales.x.cex` and `scales.y.cex` manage the sizes labels on the `x` and `y` axes.
```{r}
s.value(df[, 1:2], df$ms_li,
paxes.draw = TRUE,
scales.x.cex = 0.5,
scales.y.cex = 0.5
)
```
### Margin of axis
`layout.heights = list(bottom.padding = 1)` manages the margin of the bottom axis.
This enlarges the space for a larger title axis.
```{r}
s.value(df[, 1:2], df$ms_li,
paxes.draw = TRUE,
xlab = "Longitude", xlab.cex = 2,
ylab = "Latitude", ylab.cex = 2,
layout.heights = list(bottom.padding = 2)
)
```
## How to update label's boxes ?
```{r}
x0 <- runif(50, -2, 2)
y0 <- runif(50, -2, 2)
s.label(data.frame(x0, y0))
```
### Remove boxes around labels
```{r}
s.label(data.frame(x0, y0), plabels.boxes.border = 0)
s.label(data.frame(x0, y0), plabels.boxes.draw = FALSE, ppoints.cex = 0)
```
### Color of label's boxes
```{r}
s.label(data.frame(x0, y0), plabels.boxes.col = "orange")
```
### Border of label's boxes
```{r}
s.label(data.frame(x0, y0), plabels.boxes.border = "blue", plabels.boxes.lwd = 2)
```
adegraphics/vignettes/gargsVSclass.csv 0000644 0001762 0000144 00000003761 13747764071 017702 0 ustar ligges users ,s1d.barchart,s1d.curve,s1d.curves,s1d.density,s1d.dotplot,s1d.gauss,s1d.hist,s1d.interval,s1d.boxplot,s1d.class,s1d.distri,s1d.label,s1d.match,s.arrow,s.class,s.corcircle,s.density,s.distri,s.image,s.label,s.logo,s.match,s.traject,s.value,table.value (T.cont),table.image,table.value (T.value),triangle.class,triangle.label,triangle.match,triangle.traject
ablineX,,,,,,,,,,,,,,,,,,,,,,,,,1,,,,,,
ablineY,,,,,,,,,,,,,,,,,,,,,,,,,1,,,,,,
addaxes,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,,
addmean,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,,
adjust,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,1,1,1
arrows,,,,,,,,,,,,,,,,,,,,,,1,,,,,,,,,
axespar,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,,
bandwidth,,,,1,,,,,,,,,,,,,1,,,,,,,,,,,,,,
breaks,,,,,,,1,,,,,,,,,,,,1,,,,,1,1,1,1,,,,
center,,,,,,,,,,,,,,,,,,,,,,,,1,1,,1,,,,
centerpar,,,,,,,,,,,,,,,,,,,,,,,,1,1,,1,,,,
chullSize,,,,,,,,,,,,,,,1,,,,,,,,,,,,,1,,,
col,,,,1,,1,,,1,1,,,,,1,,1,1,,,,,1,1,1,1,1,1,,,1
contour,,,,,,,,,,,,,,,,,1,,1,,,,,,,,,,,,
ellipseSize,,,,,,,,,,,,,,,1,,,1,,,,,,,,,,1,,,
fill,,,,1,,1,,,,,,,,,,,,,,,,,,,,,,,,,
fullcircle,,,,,,,,,,,,,,,,1,,,,,,,,,,,,,,,
gridsize,,,,1,,,,,,,,,,,,,1,,1,,,,,,,,,,,,
kernel,,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,
max3d,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,1,1,1
meanpar,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,,
meanX,,,,,,,,,,,,,,,,,,,,,,,,,1,,,,,,
meanY,,,,,,,,,,,,,,,,,,,,,,,,,1,,,,,,
method,,,,,,,,1,,,,,,,,,,,,,,,,1,1,,1,,,,
min3d,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,1,1,1
nclass,,,,,,,1,,,,,,,,,,1,,1,,,,,1,1,1,1,,,,
nrpoints,,,,,,,,,,,,,,,,,1,,,,,,,,,,,,,,
order,,,,,,,,,,,,,,,,,,,,,,,1,,,,,,,,1
outsideLimits,,,,,,,,,,,,,,,,,,,1,,,,,,,,,,,,
poslab,,,,,,,,,,1,,1,,,,,,,,,,,,,,,,,,,
rect,,,,,,,,,,,,,,,,,,,,,1,,,,,,,,,,
region,,,,,,,,,,,,,,,,,1,,1,,,,,,,,,,,,
right,,,,,,1,,,,,,,,,,,,,,,,,,,,,,,,,
sdSize,,,,,,,,,,,1,,,,,,,,,,,,,,,,,,,,
span,,,,,,,,,,,,,,,,,,,1,,,,,,,,,,,,
starSize,,,,,,,,,,,,,,,1,,,1,,,,,,,,,,1,,,
steps,,,,,,1,,,,,,,,,,,,,,,,,,,,,,,,,
symbol,,,,,,,,,,,,,,,,,,,,,,,,1,1,,1,,,,
threshold,,,,,,,,,,,,,,,,,1,,,,,,,,,,,,,,
type,,,,,,,1,,,,,,,,,,,,,,,,,,,,,,,,
yrank,,,,,,,,,,,1,,,,,,,,,,,,,,,,,,,,
adegraphics/vignettes/gargsVSclass.R 0000644 0001762 0000144 00000000707 13742303021 017260 0 ustar ligges users library(grid)
t <- read.csv("gargsVSclass.csv", sep = ",", header = TRUE, check.names = FALSE)
row.names(t) <- t[, 1]
t <- t[, -1]
t[is.na(t)] <- 0
table.value(t, plegend.drawKey = FALSE, ppoints.cex = 0.2, symbol = "circle", axis.text = list(cex = 0.7), pgrid.draw = TRUE,
ptable.margin = list(bottom = 5, left = 15, top = 15, right = 5),
ptable.x = list(tck = 5), ptable.y = list(tck = 5, srt = 45, pos = "left"))
adegraphics/vignettes/adegraphics.Rmd 0000644 0001762 0000144 00000156430 14572055321 017467 0 ustar ligges users ---
title: "The `adegraphics` package"
author: "Alice Julien-Laferrière, Aurélie Siberchicot and Stéphane Dray"
date: '`r Sys.Date()`'
output:
html_vignette:
number_sections: yes
toc: yes
bibliography: adegraphics.bib
vignette: >
%\VignetteIndexEntry{The `adegraphics` package}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
\usepackage[utf8]{inputenc}
---