doubleYScale          package:latticeExtra          R Documentation

_D_r_a_w _t_w_o _p_l_o_t _s_e_r_i_e_s _w_i_t_h _d_i_f_f_e_r_e_n_t _y _s_c_a_l_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     Overplot two trellis objects with different y scales, optionally
     in different styles, adding a second y axis, and/or a second y
     axis label.

     _Note:_ drawing plots with multiple scales is often a bad idea as
     it can be misleading.

_U_s_a_g_e:

     doubleYScale(obj1, obj2, use.style = TRUE, add.axis = TRUE,
                  add.ylab2 = FALSE, style1 = 1, style2 = 2,
                  text = NULL, auto.key = if (!is.null(text))
                    list(text, points = points, lines = lines, ...),
                  points = FALSE, lines = TRUE, ...)

_A_r_g_u_m_e_n_t_s:

obj1, obj2: trellis objects. Note that most settings, like
          main/sub/legend/etc are taken only from 'obj1'; only the
          panel, axis and ylab are taken from obj2. 

use.style: if TRUE, set plot style (with 'trellis.par.set') to
          different style settings for each series. The settings are
          taken mainly from 'trellis.par.get("superpose.line")'. These
          will also be applied to the y-axes and ylab, if relevant. 

add.axis: if TRUE, draw a second y axis (for the 'obj2' series) on the
          right side of the plot. 

add.ylab2: if TRUE, draw a second y axis label (from 'obj2$ylab') on
          the right side of the plot. Note, this will replace any
          existing key or legend on the right side, i.e. with 'space =
          "right"'. 

style1, style2: if 'use.style' is TRUE, these give the `group number'
          for obj1 and obj2 respectively. The style is taken from these
          indices into the values of
          'trellis.par.get("superpose.line")'. Therefore these should
          be integers between 1 and 6; a value of 0 can be given to
          leave the default settings. 

text, auto.key, points, lines, ...: if non-NULL, add a 'key' to the
          display, using entries named by 'text'. Further arguments are
          passed on to 'simpleKey' at plot time. 

_D_e_t_a_i_l_s:

     Panels from the trellis object 'obj2' will be drawn in the
     corresponding panel of 'obj1'.

     Axis settings are taken from the trellis objects, so most 'scales'
     arguments such as 'draw', 'at', 'labels' etc from 'obj2' will
     carry over to the second y axis.

_V_a_l_u_e:

     a merged trellis object.

_A_u_t_h_o_r(_s):

     Felix Andrews felix@nfrac.org

_S_e_e _A_l_s_o:

     'as.layer'

_E_x_a_m_p_l_e_s:

     set.seed(1)
     foo <- list(x = 1:100, y = cumsum(rnorm(100)))
     ## show original data
     xyplot(y + y^2 ~ x, foo, type = "l")
     ## construct separate plots for each series
     obj1 <- xyplot(y ~ x, foo, type = "l")
     obj2 <- xyplot(y^2 ~ x, foo, type = "l")
     ## simple case: no axis for the overlaid plot
     doubleYScale(obj1, obj2, add.axis = FALSE)
     ## draw second y axis
     doubleYScale(obj1, obj2)
     ## ...with second ylab
     doubleYScale(obj1, obj2, add.ylab2 = TRUE)
     ## ...or with a key
     doubleYScale(obj1, obj2, text = c("obj1", "obj2"))

     ## different plot types
     x <- rnorm(60)
     doubleYScale(histogram(x), densityplot(x), use.style = FALSE)

     ## multi-panel example
     ## a variant of Figure 5.13 from Sarkar (2008)
     ## http://lmdvr.r-forge.r-project.org/figures/figures.html?chapter=05;figure=05_13
     data(SeatacWeather)
     temp <- xyplot(min.temp + max.temp ~ day | month,
                    data = SeatacWeather, type = "l", layout = c(3, 1))
     rain <- xyplot(precip ~ day | month, data = SeatacWeather, type = "h")

     doubleYScale(temp, rain, style1 = 0, style2 = 3, add.ylab2 = TRUE,
        text = c("min. T", "max. T", "rain"), columns = 3)

     ## re-plot with different styles
     update(trellis.last.object(),
        par.settings = simpleTheme(col = c("black", "red", "blue")))

