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 96 - (view) (download)

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

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