metaplot | R Documentation |
Metaplot creates univariate, bivariate, or multivariate plots depending on the number and types of variables represented by the anonymous arguments. Types are either numeric (NUM, e.g. real, integer) or categorical (CAT, e.g. factor, character). A variable stored as numeric that nonetheless has an encode
d guide
attribute will be treated as categorical. Mnemonic: x %>% metaplot(yvars, xvar, groupvar, facets)
where arguments are unquoted column names, and only xvar is required. Column attributes label
, guide
, reference
, and symbol
modify the behavior of the default handlers.
metaplot(x, ...)
x |
object |
... |
passed arguments |
Design your plot by specifying y variables (optional), the x variable, the groups variable (optional) and the conditioning variables (i.e., facets, optional).
The single groups variable, if any, is the first categorical in the third position or later. An earlier categorical gives a "mixed" bivariate plot or mosaic plot, depending on the type of the remaining variable.
The x variable is the last variable before groups, if present.
The y variables are those before x. If none, the result is univariate. If one, the result is typically a boxplot or scatterplot, depending on x. Several numeric y followed by a numeric x are treated as multivariate (scatterplot matrix). But if all y have the same guide
attribute and it is different from that for x, the result is bivariate (i.e, an overlay
scatterplot).
A single categorical variable results in a simple mosaic plot (see link[graphics]{mosaicplot}
and vcd for more sophisticated treatment). Mosaic plots support only a single y variable; thus, whenever the first two variables are categorical, a two-way mosaic plot results, with remaining variables understood as groups and facets.
Wherever a groups argument is meaningful, it may be missing. This allows specification of facets in the absence of groups, e.g., (metaplot(y, x, , facet1, facet2))
. For multiple y (overlay), the sources of y are the implied groups: any trailing categorical arguments are treated as facets.
Template designs follow; substitute behaviors by setting global options (see argument list).
univariate (densityplot)
categorical (one-way mosaic plot)
categorical (two-way mosaic plot)
grouped mosaic
grouped mosaic with one facet
non-grouped mosaic with one facet
mixedvariate (vertical boxplot)
mixedvariate (horizontal boxplot)
mixedvariate with one facet
bivariate (scatterplot)
grouped bivariate (grouped scatterplot)
non-grouped bivariate with one facet
grouped bivariate with one facet
grouped bivariate with two facets
multivariate, or grouped bivariate for overlay
multivariate, or faceted bivariate for overlay
multivariate, or bivariate with two facets for overlay
Variable attributes may be supplied by conventional means; pack
and unpack
support storing and retrieving scalar column attributes. The following scalar attributes are currently supported.
A variable descriptor. If present, panel functions will use label to create informative axis labels. See axislabel
.
Units for a numeric variable, or an encoding (scalar string giving codes and possibly decodes) for a categorical item. If present, units will be used to inform the corresponding axis label (axislabel
). If present, codes will be used to impose sort order on categorical variables. If present, decodes will be used as substitutes for stored values when presenting categorical labels, legends, and facet names. For more on encodings, see encode
.
Some variables have values to which they can be compared. For example, residual error is often expected to be centered at zero. Default panel functions plot corresponding reference lines if this attribute is present. See for example dens_panel
.
Variable names are useful for programming, and variable labels are useful as axis labels. A symbol can be more formal than a variable name and more compact than a label. For example, diag_label
will use variable names as labels for the diagonal panels of a scatterplot matrix; but it will prefer labels, if available; and will prefer symbols most of all. Markup rules for symbols are given in wikisym2plotmath_
.
Other generic functions:
axislabel()
,
categorical()
,
corsplom()
,
densplot()
,
pack()
,
scatter()
,
test_metaplot()
,
unpack()
Other metaplot:
boxplot_data_frame()
,
categorical_data_frame()
,
corsplom_data_frame()
,
densplot_data_frame()
,
metaplot_key()
,
scatter_data_frame()
,
test_metaplot()
library(magrittr)
library(dplyr)
library(csv)
x <- as.csv(system.file(package = 'metaplot', 'extdata/theoph.csv'))
x %<>% pack
# setOption(gg = TRUE)
# setOption(verbose = TRUE) # all messages; equiv. to metaplot(verbose = T,...)
# setOption(verbose_densplot = TRUE) # densplot messages
# sample plots
x %>% metaplot(sres)
x %>% metaplot(site)
x %>% metaplot(conc, arm)
x %>% densplot(conc, arm)
x %>% metaplot(arm, conc)
x %>% metaplot(conc, arm, site)
x %>% metaplot(conc, site, arm)
x %>% metaplot(conc, time)
x %>% metaplot(arm, site)
x %>% metaplot(arm, site, cohort)
x %>% metaplot(arm, site, cohort, space = 'top')
x %>% metaplot(arm, site, , cohort)
x %>% metaplot(conc, time, subject)
x %>% metaplot(conc, time, , subject)
x %>% metaplot(conc, time, subject, site)
x %>% metaplot(conc, time, subject, site, arm)
x %>% metaplot(lKe, lKa, lCl)
x %>% metaplot(
lKe, lKa, lCl,
col = 'black',smooth.col = 'red', pin.col = 'red',
dens.col='blue',dens.alpha = 0.1
)
x %>% metaplot(conc, pred, ipred, time, space = 'top')
x %>% metaplot(conc, pred, ipred, time, subject, space = 'top')
x %>% metaplot(conc, pred, ipred, time, subject,
colors = c('black','blue','orange'),
points = c(0.9,0, 0.4),
lines = c(F,T,T),
types = c('blank','dashed','solid'),
space = 'top'
)
x %>% metaplot(conc, ipred, time, site, arm, space = 'top')
x %>% metaplot(res, conc, yref = 0, ysmooth = T, conf = T, grid = T, loc = 1)
x %>% metaplot(res, conc, arm, ysmooth = T, conf = T )
x %>% metaplot(res, conc, arm, ysmooth = T, conf = T, global = T, ref.col = 'red')
x %>% metaplot(subject,conc)
# manage metadata
attr(x$arm, 'guide') # //1/Arm A//2/Arm B//
x %>% metaplot(conc, arm) # default
x %>% mutate(arm = arm %>%
structure(guide = '//2/Arm B//1/Arm A//')) %>%
metaplot(conc, arm) # different presentation order
x %>% mutate(arm = arm %>%
structure(guide = '//1/Both Arms//2/Both Arms//')) %>%
metaplot(conc, arm) # collapse cases
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.