Learn R Programming

sjmisc (version 1.0.2)

group_labels: Create labels for recoded groups

Description

Creates the related labels for the grouped variable created by the group_var function.

Usage

group_labels(var, groupsize = 5, rightInterval = FALSE,
  autoGroupCount = 30)

Arguments

var
The variable, which should recoded into groups.
groupsize
The group-size, i.e. the range for grouping. By default, for each 5 categories new group is built, i.e. groupsize=5. Use groupsize="auto" to automatically resize a variable into a maximum of 30 groups (which is the ggplot-default
rightInterval
If TRUE, grouping starts with the lower bound of groupsize. In this case, groups cover the ranges from 50-54, 55-59, 60-64 etc. If FALSE (default), grouping starts with the upper bound of groupsize. In
autoGroupCount
Sets the maximum number of groups that are built when auto-grouping is on (groupsize="auto"). Default is 30. If groupsize is not set to "auto", this parameter will be ignored.

Value

  • A string vector containing labels based on the grouped counts of var, formatted as "from lower bound to upper bound", e.g. "10-19" "20-29" "30-39" etc. See example below.

Details

See 'Details' in group_var.

See Also

Examples

Run this code
age <- abs(round(rnorm(100, 65, 20)))
age.grp <- group_var(age, 10)
hist(age)
hist(age.grp)

age.grpvar <- group_labels(age, 10)
table(age.grp)
print(age.grpvar)

# histogram with EUROFAMCARE sample dataset
# variable not grouped
data(efc)
library(sjPlot)
sjp.frq(efc$e17age,
        title = get_var_labels(efc$e17age),
        type = "h",
        showValueLabels = FALSE)

# bar plot with EUROFAMCARE sample dataset
# grouped variable
data(efc)
ageGrp <- group_var(efc$e17age)
ageGrpLab <- group_labels(efc$e17age)
library(sjPlot)
sjp.frq(ageGrp,
        title = get_var_labels(efc$e17age),
        axisLabels.x = ageGrpLab)

Run the code above in your browser using DataLab