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

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