td: Set lattice parameters for multiple groups

View source: R/graphics.R

tdR Documentation

Set lattice parameters for multiple groups

Description

Easier alternative to using trellis.par.set and trellis.par.get to change lattice colors, line types, etc.

Usage

td(...)

gd(
  n = 8,
  pal = "Dark2",
  col = brewer.pal(n, pal),
  lty = 1:n,
  lwd = 1,
  pch = 19,
  cex = 1.4,
  font = 1,
  fill = "transparent",
  col.line = col,
  col.symbol = col,
  alpha = 1,
  alpha.line = alpha,
  alpha.symbol = alpha,
  len = n,
  h = c(0, 360) + 15,
  l = 65,
  c = 100,
  h.start = 0,
  direction = 1,
  low = "#3B4FB8",
  high = "#B71B1A",
  space = "rgb",
  basecol = NULL,
  colsets = c("plot.symbol", "plot.line", "dot.symbol", "dot.line", "cloud.3d",
    "box.dot"),
  superpose = TRUE,
  gginit = FALSE,
  gglike = TRUE,
  ...
)

gd_(...)

tps(...)

tps_(...)

tpg(...)

Arguments

...

FIXME parameter: e.g. plot.symbol=list(cex=2,col='red'). Particular useful for the cex, col, lty, lwd, alpha, pch parameters in plot.line and plot.symbol.

n

number of groups for which to set colors, line types, etc. using RColorBrewer.

col

FIXME

lty

FIXME

lwd

FIXME

pch

FIXME

cex

FIXME for each level of the groups variable

font

FIXME

fill

FIXME

col.line

FIXME not given

col.symbol

FIXME 'groups' not given

alpha

FIXME

alpha.line

FIXME

alpha.symbol

graphical parameters for superpose.line and superpose.symbol

len

extend the length of parameters by recycling to length 'len'

basecol

FIXME

colsets

FIXME

new

If new = TRUE, open a new window, otherwise modify the existing active window, if there is one.

long

if TRUE generate a default combination of col, lty and pch with length 42.

record

If TRUE, set history to 'recording'. Caution: this can use a lot of memory in .GlobalEnv. Consider adding selected graphs to memory with the 'Insert' key instead.

Details

Designed to easily set lattice parameters for multiple groups. Setting parameters before calling the lattice function allows parameters to be used consistently in the group key.

'td' calls 'trellis.device' and sets graphical parameters for 'superpose.line' and 'superpose.symbol'. 'td' also initializes a new trellis device with a white background if new = TRUE.

'gd' is similar to 'td' except that it uses a theme that resembles that of 'ggplot'

Functions

  • gd(): with ggplot2-like theme

  • gd_(): gd to set non-group parameters

  • tps(): trellis par set for superpose parameters

  • tps_(): trellis par set for all parameters, special treatment for col, lwd, lty, pch, padding

  • tpg(): trellis par set for superpose parameters

Author(s)

Georges Monette

Examples

td( lty = 1:7)   # sets line types for 7 groups
gd(7)            # sets line types for 7 groups using colors from RColorBrewer
td( plot.symbol = list(col = 'red', pch = 17))
gd_(col='blue')  # set main color to 'blue'
#   - setting colors for groups, i.e. 'superpose.symbol' in trellis.par.get():
gd(5)  # where 5 is the number of groups
gd(5, lwd = 2, lty = 1)
gd(5, col = brewer.pal(5,"Dark2"),cex = 1.5)

# To set colors when not using groups (superpose = FALSE)
gd_(col='tomato4')
# changing the default color for lines and symbols
gd(plot.line=list(col='red',lwd=2),
           plot.symbol=list(col='blue', cex = 1.3))
# OR using superpose = FALSE
gd(superpose = FALSE, col = 'red', lwd = 2)
# OR using the utility function 'gd_':
gd_(col = 'red', lwd = 2)
#
# To set colors for lattice::barchart:
library(lattice)
gd(superpose.polygon = list(col=brewer.pal(4,'Paired'), border='black'))
barchart(Titanic, 
    auto.key=list(title = 'survived',
                  space = 'right',
                  reverse.rows = T), 
    horizontal = F)
#  For a complete list of elements that can be changed:
names(trellis.par.get())
# For a list of colors
colors()
grepv('pink',colors()) # types of pink
# Using magrittr
library(magrittr)
colors()  %>%  grepv('blue', .)  %>%
  pal  %>%
  as.data.frame %>%
  sortdf( ~ red)  %>%
  as.matrix  %>%
  divide_by(255)  %>%
  rgb  %>%
  pal

gmonette/spida2 documentation built on July 14, 2024, 12:45 p.m.