Learn R Programming

sjPlot (version 1.7)

set_var_labels: Attach variable label(s) to a single variable or data frame

Description

This function sets variable labels to a single variable or to a set of variables in a data frame. To each variable, the attribute "variable.label" with the related variable name is attached. Most of this package's functions can automatically retrieve the variable name to use it as axis labels or plot title.

Usage

set_var_labels(x, lab, attr.string = NULL)

Arguments

Value

x, with attached "variable.label" attribute(s), which contains the variable name(s).

See Also

Examples

Run this code
# sample data set, imported from SPSS. Variable labels are attached
# as attribute to the data frame (so variables currently don't have this attribute)
data(efc)
# get variable labels
variable.labels <- get_var_labels(efc)
# set variable labels as attribute to each single variable of data frame
efc <- set_var_labels(efc, variable.labels)

sjt.frq(efc$e42dep)
sjt.frq(data.frame(efc$e42dep, efc$e16sex))

# ---------------------------------------------
# manually set value and variable labels
# ---------------------------------------------
dummy <- sample(1:4, 40, replace=TRUE)
dummy <- set_val_labels(dummy, c("very low", "low", "mid", "hi"))
dummy <- set_var_labels(dummy, "Dummy-variable")
# auto-detection of value labels by default, auto-detection of
# variable labels if parameter "title" set to NULL.
sjp.frq(dummy, title=NULL)

Run the code above in your browser using DataLab