如果在生成表时未使用权重,则sjPlot按预期交付,请参阅:Without Weights。但是,如果使用权重,则应用权重,但值标签消失,请参阅: With Weights
我做错了什么? 上面的表可以使用以下脚本进行复制(最初包含在sjPlot包中。我刚刚在原始数据框中添加了一个名为“MYweights”的字段,以便说明我的问题)
library(sjmisc)
library (sjPlot)
data(efc)
efc.labels <- get_labels(efc)
# print simple cross table with labels
## Not run:
sjt.xtab(efc$e16sex, efc$e42dep)
# print cross table with manually set
# labels and expected values
sjt.xtab(efc$e16sex,
efc$e42dep,
variableLabels = c("Elder's gender",
"Elder's dependency"),
valueLabels = list(efc.labels[['e16sex']],
efc.labels[['e42dep']]),
showExpected = TRUE)
efc$MYweights <- 1.2
# ## Without weights, value labels appear
sjt.xtab(efc$e16sex, efc$e42dep,
showHorizontalLine = FALSE,
showCellPerc = FALSE,
highlightTotal = TRUE,
showSummary=FALSE)
## With weights, value labels vanish
sjt.xtab(efc$e16sex, efc$e42dep,
weightBy = efc$MYweights,
showHorizontalLine = FALSE,
showCellPerc = FALSE,
highlightTotal = TRUE,
,showSummary=FALSE)