group_var(var, groupsize = 5, asNumeric = TRUE, rightInterval = FALSE,
autoGroupCount = 30)
groupsize=5
. Use groupsize="auto"
to automatically
resize a variable into a maximum of 30 groups (which is the ggplot-defTRUE
(default), the recoded variable will be returned as numeric vector.
If FALSE
, a factor is returned.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 groupsize="auto"
). Default is 30. If groupsize
is not set to "auto"
,
this parameter will be ignored.asNumeric
).groupsize
is set to a specific value, the variable is recoded
into several groups, where each group has a maximum range of groupsize
.
Hence, the amount of groups differ depending on the range of var
.
If groupsize = "auto"
, the variable is recoded into a maximum of
autoGroupCount
groups. Hence, independent from the range of
var
, always the same amount of groups are created, so the range
within each group differs (depending on var
's range).age <- abs(round(rnorm(100, 65, 20)))
age.grp <- group_var(age, 10)
hist(age)
hist(age.grp)
# 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