# create 4-category-items
x <- sample(1:4, 100, replace=TRUE)
# create 3-category-items
y <- sample(1:3, 100, replace=TRUE)
# plot "cross tablulation" of x and y
sjp.xtab(y,x)
# plot "cross tablulation" of x and y, including labels
sjp.xtab(y, x,
axisLabels.x = c("low", "mid", "high"),
legendLabels = c("Grp 1", "Grp 2", "Grp 3", "Grp 4"))
# plot "cross tablulation" of x and y
# as stacked proportional bars
sjp.xtab(y, x,
tableIndex = "row",
barPosition = "stack",
coord.flip = TRUE)
# example with vertical labels
data(efc)
sjp.setTheme(geom.label.angle = 90)
# hjust-aes needs adjustment for this
library(ggplot2)
update_geom_defaults('text', list(hjust = -0.1))
sjp.xtab(efc$e42dep,
efc$e16sex,
showTableSummary = FALSE,
labelPos = "center")
# grouped bars with EUROFAMCARE sample dataset
# dataset was importet from an SPSS-file, using:
# efc <- read_spss("efc.sav", enc="UTF-8")
data(efc)
efc.val <- get_val_labels(efc)
efc.var <- get_var_labels(efc)
sjp.xtab(efc$e42dep,
efc$e16sex,
title=efc.var['e42dep'],
axisLabels.x=efc.val[['e42dep']],
legendTitle=efc.var['e16sex'],
legendLabels=efc.val[['e16sex']])
sjp.xtab(efc$e16sex,
efc$e42dep,
title=efc.var['e16sex'],
axisLabels.x=efc.val[['e16sex']],
legendTitle=efc.var['e42dep'],
legendLabels=efc.val[['e42dep']])
sjp.xtab(efc$e16sex,
efc$e42dep,
title=efc.var['e16sex'],
axisLabels.x=efc.val[['e16sex']],
legendTitle=efc.var['e42dep'],
legendLabels=efc.val[['e42dep']],
tableIndex="row",
barPosition="stack",
coord.flip=TRUE,
jitterValueLabels=TRUE)
# -------------------------------
# auto-detection of labels
# -------------------------------
efc <- set_var_labels(efc, efc.var)
sjp.xtab(efc$e16sex, efc$e42dep)
Run the code above in your browser using DataLab