SCM

SCM Repository

[latticeextra] Annotation of /pkg/R/horizonplot.R
ViewVC logotype

Annotation of /pkg/R/horizonplot.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 95 - (view) (download)

1 : felix 95
2 :    
3 :     horizonplot <- function(x, data, ...)
4 :     UseMethod("horizonplot")
5 :    
6 :     horizonplot.default <-
7 :     function(x, data = NULL, ...,
8 :     panel = panel.horizonplot,
9 :     prepanel = prepanel.horizonplot,
10 :     strip = FALSE, groups = NULL,
11 :     layout = c(1, Inf),
12 :     default.scales = list(y = list(relation = "sliced")))
13 :     {
14 :     stopifnot(is.null(data))
15 :     if (!is.null(groups))
16 :     stop("'groups' does not work in this plot")
17 :     ans <- xyplot(x, ..., panel = panel, prepanel = prepanel,
18 :     strip = strip,
19 :     layout = layout,
20 :     default.scales = default.scales)
21 :     ans$call <- match.call()
22 :     ans
23 :     }
24 :    
25 :    
26 :     panel.horizonplot <-
27 :     function(x, y, ..., origin,
28 :     border = NA, col.regions = regions$col)
29 :     {
30 :     regions <- trellis.par.get("regions")
31 :     origin <- current.panel.limits()$y[1]
32 :     #if (is.function(origin))
33 :     # origin <- origin(y)
34 :     #scale <- max(abs(range(y, finite = TRUE) - origin)) / 3
35 :     scale <- diff(current.panel.limits()$y)
36 :     ## ordered for drawing, from least extreme to most extreme
37 :     sections <- c(-1, 0, -2, 1, -3, 2, -4, 3) ## these are the lower bounds
38 :     #ycut <- cut(y, breaks = c(-Inf, breaks, Inf))
39 :     ii <- quantile(seq_along(col.regions),
40 :     (sections - min(sections)) / (length(sections)-1),
41 :     type = 1)
42 :     #col <- col.regions[1 + (length(col.regions)-1) * 0:5/5]
43 :     col <- col.regions[ii]
44 :     for (i in seq_along(sections)) {
45 :     section <- sections[i]
46 :     yi <- y
47 :     if (section < 0) {
48 :     yi <- origin + origin - y
49 :     section <- abs(section) - 1
50 :     }
51 :     baseline <- origin + section * scale
52 :     if (all(yi <= baseline, na.rm = TRUE))
53 :     next
54 :     yi <- yi - baseline
55 :     yi <- origin + pmax(pmin(yi, scale), 0)
56 :     panel.xyarea(x, yi, border = border, col = col[i], ...)
57 :     }
58 :     }
59 :    
60 :     prepanel.horizonplot <-
61 :     function(x, y, ..., origin = function(y) na.omit(y)[1])
62 :     {
63 :     if (is.function(origin))
64 :     origin <- origin(y)
65 :     ans <- prepanel.default.xyplot(x, y, ...)
66 :     scale <- max(abs(ans$ylim - origin)) / 3
67 :     ans$ylim <- origin + c(0, scale)
68 :     ans
69 :     }

R-Forge@R-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge