Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
2701 views
1
foobar <- function(...) {}
2
rm(list=ls())
3
4
##--------> consequence of the above experiments:
5
## the 2nd form is numerically "uniformly better" than the first
6
##--------> 2011-05-27: Change Frank's psiInv() to
7
## psiInv = function(t,theta)
8
## -log1p(exp(-theta)*expm1((1-t)*theta)/expm1(-theta))
9
10
##--- In the following block, in the first line, C-c C-c did *NOT* behave
11
12
th <- 48 # now do ls() and see what happened ... the horror !!!
13
d <- 3
14
cpF <- list("Frank", list(th, 1:d))
15
cop <- acF <- cpF$copula
16
17
18
### Here, the bug (12.09-2, e.g.) has been that
19
### the function beginning is not found reliably:
20
### C-M-q -> should go to end; then C-M-a should go back to beginning (here)
21
mplot4 <- function(x, vList, xvar, cvar, rvar, log = "",
22
verbose=FALSE, show.layout=verbose)
23
{
24
dn <- dimnames(x)
25
## the variable displayed in one plot (with different colors):
26
v <- setdiff(names(dn), c(xvar, cvar, rvar))
27
stopifnot(length(v) == 1, 1 <= (nv <- length(dn[[v]])), nv <= length(pcol),
28
length(pspc) == 2, length(spc) == 2, length(axlabspc) == 2,
29
length(labspc) == 2, length(auxcol) == 4)
30
v.col <- colorRampPalette(pcol, space="Lab")(nv) # colors for v
31
## permute to know the component indices:
32
x <- aperm(x, perm=c(rvar, cvar, v, xvar))
33
34
if(is.null(xlab)) # default: the expression from varlist
35
xlab <- vList[[xvar]]$expr
36
z <- as.numeric(vList[[xvar]]$value) # pick out different x values
37
zrange <- range(z) # for forcing the same x axis limits per row
38
39
## set up the grid layout
40
nx <- length(dn[[cvar]]) # number of plot columns
41
nx. <- nx+1+(nx-1)+1 # +1: for y axis label; +(nx-1): for gaps; +1: for row labels
42
ny <- length(dn[[rvar]]) # number of plot rows
43
ny. <- ny+1+(ny-1)+1 # +1: for column labels; +(ny-1): for gaps; +1: for x axis label
44
## plot settings, restored on exit
45
opar <- par(no.readonly=TRUE); on.exit(par(opar))
46
plot.new() # start (empty) new page with 'graphics'
47
gl <- grid.layout(nx., ny.,
48
## units in npc as for pdf(); no square plotting region otherwise:
49
default.units="npc",
50
widths=c(axlabspc[1], rep(c(pspc[1], spc[1]), nx-1), pspc[1], labspc[1]),
51
heights=c(labspc[2], rep(c(pspc[2], spc[2]), ny-1), pspc[2], axlabspc[2]))
52
if(show.layout) grid.show.layout(gl, vp=viewport(width=1.25, height=1.25))
53
pushViewport(viewport(layout=gl)) # use this layout in a viewport
54
55
## --- plot data ---
56
for(i in 1:nx) { # rows
57
i. <- 2*i # column index in layout (for jumping over gaps)
58
if(verbose) cat(sprintf("plot row %d (%d): [columns:] ", i, i.))
59
yrange <- range(x[i,,,]) # for forcing the same y axis limits per row
60
for(j in 1:ny) { # columns
61
j. <- 2*j # row index in layout (for jumping over gaps)
62
if(verbose) cat(sprintf("%d (%d) ", j, j.))
63
pushViewport(viewport(layout.pos.row=i., layout.pos.col=j.))
64
65
## plot
66
grid.rect(gp=gpar(col=NA, fill=auxcol[3])) # background
67
## start a 'graphics' plot
68
par(plt = gridPLT())
69
## Hmm, this is not really useful for debugging:
70
## rp <- tryCatch(par(plt=gridPLT()), error = function(e)e)
71
## if(inherits(rp, "error")) {
72
## cat("\n *** ERROR in mplot() :\n", rp$message,"\n"); return(gl)
73
## }
74
par(new=TRUE) # always do this before each new 'graphics' plot
75
## set up coordinate axes:
76
plot(zrange, yrange, log=log, type="n", ann=FALSE, axes=FALSE)
77
## background grid:
78
grid(col=auxcol[4], lty="solid", lwd=grid.lwd, equilogs=FALSE)
79
## plot corresponding points/lines
80
for(k in 1:nv) points(z, x[i,j,k,], type="b", col=v.col[k])
81
## axes
82
c1 <- auxcol[1]
83
if(i == nx) # x axes
84
axis(1, lwd=ax.lwd, col=NA, col.ticks=c1, col.axis=c1)
85
if(j == 1) { # y axes
86
if(packageVersion("sfsmisc") >= "1.0-21")
87
## allow for adjusting colors of small ticks
88
eaxis(2, lwd=ax.lwd, col=NA, col.ticks=c1, col.axis=c1,
89
small.args=list(col=NA, col.ticks=c1, col.axis=c1))
90
else
91
eaxis(2, lwd=ax.lwd, col=NA, col.ticks=c1, col.axis=c1)
92
}
93
upViewport()
94
95
## column labels
96
if(i == 1) {
97
pushViewport(viewport(layout.pos.row=1, layout.pos.col=j.))
98
grid.rect(gp=gpar(col=NA, fill=auxcol[2]))
99
grid.text(parse(text=dn[[cvar]][j]), x=0.5, y=0.5, gp=gpar(cex=tx.cex))
100
upViewport()
101
}
102
103
## row labels
104
if(j == 2) {
105
pushViewport(viewport(layout.pos.row=i., layout.pos.col=nx.))
106
grid.rect(gp=gpar(col=NA, fill=auxcol[2]))
107
grid.text(parse(text=dn[[rvar]][i]), x=0.5, y=0.5, gp=gpar(cex=tx.cex), rot=-90)
108
upViewport()
109
}
110
}## for(j ..)
111
if(verbose) cat("\n")
112
}## for(i ..)
113
114
## legend
115
pushViewport(viewport(layout.pos.row=ny., layout.pos.col=2:(ny.-1)))
116
ll <- 0.01 # line length
117
118
## [... ... made example smaller ... ESS-bug still shows ....]
119
120
upViewport()
121
invisible(gl)
122
}
123
124