ggplot2like.theme | R Documentation |
A theme for Lattice based on some of the default styles used in the
ggplot2 package by Hadley Wickham. Specifically, parts of the
functions scale_colour_hue
, scale_colour_gradient
and
theme_gray
were copied. Although superficially similar, the
implementation here lacks much of the flexibility of the ggplot2
functions: see http://had.co.nz/ggplot2/.
ggplot2like(..., n = 6, h = c(0,360) + 15, l = 65, c = 100, h.start = 0, direction = 1, low = "#3B4FB8", high = "#B71B1A", space = "rgb") ggplot2like.opts() axis.grid(side = c("top", "bottom", "left", "right"), ..., ticks = c("default", "yes", "no"), scales, components, line.col)
... |
further arguments passed on to |
n |
number of |
h, c, l, h.start, direction |
range of hues, starting hue and direction to generate a discrete
colour sequence with |
low, high, space |
extreme colors to interpolate with |
side, ticks, scales, components, line.col |
see |
ggplot2like()
produces a list of settings which can be
passed as the par.settings
argument to a high-level Lattice
plot, or to trellis.par.set
.
ggplot2like.opts()
produces a list which can be passed as the
lattice.options
argument to a high-level Lattice plot, or to
lattice.options
.
Felix Andrews felix@nfrac.org; copied and adapted from ggplot2 by Hadley Wickham.
the ggplot2 package: http://had.co.nz/ggplot2/.
custom.theme
, scale.components
set.seed(0) ## basic theme does not include white grid lines xyplot(exp(1:10) ~ 1:10, type = "b", par.settings = ggplot2like()) ## add lines for axis ticks with custom axis function xyplot(exp(1:10) ~ 1:10, type = "b", par.settings = ggplot2like(), axis = axis.grid) ## this can be used together with scale.components ## (minor lines only visible on devices supporting translucency) xyplot(exp(rnorm(500)) ~ rnorm(500), scales = list(y = list(log = TRUE)), yscale.components = yscale.components.log10ticks, par.settings = ggplot2like(), axis = axis.grid) ## ggplotlike.opts() specifies axis = axis.grid as well as ## xscale.components.subticks / yscale.components.subticks xyg <- make.groups( "group one" = rnorm(80, 1), "group two" = rnorm(80, 5), "group three" = rnorm(80, 2)) xyg$x <- rev(xyg$data) ## group styles: specify number of equi-spaced hues xyplot(data ~ x, xyg, groups = which, auto.key = TRUE, par.settings = ggplot2like(n = 3), lattice.options = ggplot2like.opts()) + glayer(panel.smoother(...)) ## or set it as the default: opar <- trellis.par.get() trellis.par.set(ggplot2like(n = 4, h.start = 180)) oopt <- lattice.options(ggplot2like.opts()) bwplot(voice.part ~ height, data = singer) histogram(rnorm(100)) barchart(Titanic[,,,"No"], main = "Titanic deaths", layout = c(1, 2), auto.key = list(columns = 2)) ## reset trellis.par.set(opar) lattice.options(oopt) ## axis.grid and scale.components.subticks can be used alone: ## (again, lines for minor ticks need transculency-support to show up) xyplot(exp(1:10) ~ 1:10, type = "b", lattice.options = ggplot2like.opts(), par.settings = list(axis.line = list(col = NA), reference.line = list(col = "grey")), scales = list(tck = c(0,0)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.