我正在使用该likert
软件包,并且可以生成分组结果。但是,我不知道如何处理两个(或多个)组,即按两列(性别和国家)对结果进行分组
格式错误,类似的东西
likert(ds[,3:7], grouping=ds[,1:2]) %>%
plot()
或者:
likert(ds[,3:7], grouping=ds[,1]) %>%
plot() +
facet_wrap(~country)
想要的结果可以是这个
数据和代码如下
ds <-structure(list(sex_female = structure(c(1L, 2L, 2L, 2L, 1L, 2L,
1L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L,
1L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L,
2L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L,
1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L,
1L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 1L), .Label = c("male",
"female"), class = "factor"), country = structure(c(2L, 2L, 2L,
1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 2L,
2L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L,
2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 1L,
2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 1L,
2L), .Label = c("br", "sp"), class = "factor"), eat1_c = structure(c(1L,
1L, 1L, 3L, 4L, 4L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 4L,
2L, 1L, 2L, 1L, 1L, 1L, 4L, 4L, 1L, 2L, 3L, 1L, 2L, 4L, 1L, 2L,
1L, 2L, 1L, 1L, 2L, 3L, 1L, 3L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 4L,
1L, 1L, 2L, 1L, 4L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 4L, 1L,
1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
4L, 3L, 3L, 4L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 3L, 2L, 3L, 1L, 1L,
1L, 1L, 3L), .Label = c("0", "1", "2", "3"), class = "factor"),
eat2_c = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 4L, 1L, 1L,
2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L,
NA, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, NA, 3L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
1L), .Label = c("0", "1", "2", "3"), class = "factor"), eat3_c = structure(c(2L,
3L, 3L, 4L, 4L, NA, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, NA, 2L,
1L, 1L, 3L, 2L, 3L, 1L, 1L, 3L, NA, 2L, 1L, 2L, 3L, 1L, 2L,
1L, 3L, 1L,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1L, 2L, 2L, 1L, 1L, 1L,
1L, 4L, 2L, 2L, 3L, 3L, 3L, 1L, 3L, 1L, 4L, 2L, 2L, 1L, 1L,
1L, 1L, 3L, 1L, 4L, 1L, 1L), .Label = c("0", "1", "2", "3"
), class = "factor")), row.names = c(NA, -100L), class = "data.frame")
library(likert)
likert(ds[,3:7], grouping=ds[,1]) %>%
plot()