使用R的sjPlot包时,如果包含“权重”变量,表值标签就会消失

时间:2016-02-24 02:16:53

标签: r

如果在生成表时未使用权重,则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)

1 个答案:

答案 0 :(得分:0)

这是sjt.xtab中的错误,现在已修复。如果您想测试,可以从 sjPlot -package下载最新的GitHub-build