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

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

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