在 R 中用两组创建李克特图
Create likert plot with two groups in R
我在尝试创建包含两个组的李克特图时遇到问题。我在两个社区进行了一项调查。我现在想比较这两个社区。 [那是我的数据框][1]。到目前为止,我已经加载了一个包含 3 列的 sheet。一列表示位置(社区 1、社区 2),一列包含有关 econ_comm (1-6) 的答案,一列包含有关 future_persp (1-6) 的答案。我创建了一个李克特对象和第一个图形。
g_likert = likert(g[1:6])
plot(g_likert, ordered = FALSE, group.order = names(g[2:3]))
...它奏效了。以下是我到目前为止得到的。
[![在此处输入图片描述][2]][2]
我认为现在首先创建一个双对象很重要:both<-g$Location
(有效)
现在我开始惹麻烦了。以下代码显示错误:
both_likert_2 = likert(both[, c(1:3), drop=FALSE], grouping = both$location)
plot(both_likert_2, include.histogram = TRUE)
错误是:
Error in [.data.frame (g, 1:6) : undefined columns selected
Error in [.default (both, , c(1:3), drop = FALSE) :
wrong number of dimensions
- Objekt 'both_likert_2' not found
[我现在还附上了我的 R 的屏幕截图,以确保确定。][4]
我现在已经挣扎了很长一段时间,如果能得到一些帮助,我将非常感激。
最好,
菲利克斯
编辑:
[![这是我在R中的现状][5]][5]
这是我重现它的代码:
library(likert)
g<-read.csv2("C:/Users/felix/OneDrive/Documents/R/SurveyData2.csv", sep=";", dec=",", header=TRUE)
both<-g$Location
g <- within(g, {
gold_21cent <- factor(gold_21cent, levels=1:6, labels=c("Completely agree", "Agree", "Slightly agree", "Slightly disagree", "Disagree", "Completely disagree"))
future_persp <- factor(future_persp, levels=1:6, labels=c("Completely agree", "Agree", "Slightly agree", "Slightly disagree", "Disagree", "Completely disagree"))
jobs_comm <- factor(jobs_comm, levels=1:6, labels=c("Completely agree", "Agree", "Slightly agree", "Slightly disagree", "Disagree", "Completely disagree"))
} )
.........etc............
comm_likert = likert(g[,2:14], grouping=g[,1])
plot(comm_likert)
library(dplyr)
g %>%
重命名(It offers important economic perspectives
=future_persp,
It provides economic prosperity to the community
=econ_comm) %>%
里克特(分组=位置)%>%
情节()
编辑:使用 dput(g)
structure(list(Location = structure(c(2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L), .Label = c("Huan", "TP"), class = "factor"),
gold_21cent = structure(c(6L, 6L, 3L, 3L, 2L, 2L, 2L, 2L,
2L, 6L, 3L, 2L, 2L, 3L, 2L, 3L, 1L, 3L, 2L, NA, NA, 1L, 1L,
6L, 4L, 6L, 5L, 2L, 2L, 2L, 4L, 4L, 3L, 3L, 2L, 3L, 2L, 3L,
3L, NA, 2L, 3L, 2L, NA, 2L, 2L, 3L, 5L, 3L, 3L, 3L, 3L, 3L,
3L, 4L, 2L, 3L, 6L), .Label = c("Completely agree", "Agree",
"Slightly agree", "Slightly disagree", "Disagree", "Completely disagree"
), class = "factor"), life_quality = structure(c(3L, 3L,
6L, 6L, 5L, 5L, 6L, 5L, 6L, 3L, 3L, 6L, 4L, 6L, 6L, 6L, 6L,
6L, 6L, NA, NA, 3L, 5L, 6L, 2L, 6L, 5L, 3L, 2L, 3L, 1L, 1L,
2L, 2L, 3L, 1L, 3L, 2L, 3L, 1L, 3L, 3L, 2L, 3L, 1L, 2L, NA,
3L, 2L, 2L, 3L, 3L, 3L, 5L, 5L, 3L, 2L, 3L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), coexist_tradact = structure(c(6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 2L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 5L, 5L, 6L, 2L, 6L, 1L, 6L, 5L, 6L, 6L, 6L, 1L,
4L, 2L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 4L, 3L, 2L, 3L, 3L, 3L,
4L, 4L, 3L, 2L, 4L, 5L, 4L, 2L, 4L, 6L, 3L, 2L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), emigration_comm = structure(c(6L,
6L, 6L, 6L, 6L, 6L, 6L, 5L, 6L, 6L, 5L, NA, 6L, 6L, 6L, 6L,
6L, 6L, 6L, NA, NA, 4L, 2L, 1L, 3L, 1L, 1L, 6L, 6L, 6L, 2L,
1L, 3L, 3L, 3L, 1L, 3L, 1L, 2L, 1L, 2L, 2L, 3L, 3L, 2L, 1L,
4L, 5L, 5L, 2L, 3L, 3L, 3L, 2L, 2L, 3L, 3L, 3L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), future_persp = structure(c(3L,
3L, 5L, 5L, 5L, 5L, 6L, 5L, 5L, 3L, 5L, 6L, 6L, 5L, 3L, 6L,
5L, 5L, 3L, 3L, 3L, 2L, 1L, 6L, 3L, 6L, 5L, 3L, 3L, 3L, 1L,
3L, 2L, 2L, 2L, 2L, 3L, 3L, 4L, 2L, 4L, 2L, 2L, 3L, 1L, 2L,
4L, 4L, 4L, 2L, 4L, 2L, 3L, 5L, 5L, 3L, 2L, 3L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), workers_comm = structure(c(6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 5L, 6L, 6L, 2L, 6L, 6L,
6L, 6L, 6L, 4L, 5L, NA, 1L, 6L, 1L, 6L, 5L, 6L, 6L, 6L, 1L,
2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 1L, 4L, 3L, 4L, 5L, 3L, 3L, 4L, 4L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), work_project = structure(c(6L,
6L, 6L, 6L, 5L, 5L, 6L, 5L, 6L, 6L, 6L, 6L, 5L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 5L, 3L, 6L, 4L, 6L, 5L, 6L, 6L, 6L, 6L,
3L, 2L, 2L, 1L, 1L, 3L, 6L, 3L, 3L, 2L, 6L, 3L, 3L, 3L, 1L,
3L, 6L, 5L, 6L, 5L, 1L, 6L, 6L, 5L, 6L, 2L, 3L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), agree_comm = structure(c(6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 5L, 6L, 6L, 6L, 5L, 6L,
6L, 6L, 6L, 5L, 5L, 5L, 3L, 6L, 2L, 5L, 6L, 6L, 6L, 6L, 3L,
3L, 2L, 3L, 3L, 1L, 3L, 3L, 3L, 2L, 4L, 1L, 3L, NA, 3L, 2L,
3L, 3L, NA, 3L, 3L, 4L, 3L, 3L, 3L, 4L, 2L, 3L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), informed_deals = structure(c(4L,
4L, 1L, 1L, 5L, 6L, 5L, 5L, 5L, 6L, 4L, 5L, 5L, 6L, 4L, 6L,
5L, 6L, 4L, 6L, 6L, 6L, 1L, 6L, 3L, 6L, 1L, 2L, 2L, 2L, 4L,
2L, 3L, 3L, 2L, 1L, 5L, 6L, 5L, 2L, 3L, 5L, 3L, 3L, 4L, 4L,
2L, 4L, 4L, 5L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), fear_environ = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 5L, 1L,
1L, 1L, 1L, 6L, 6L, 1L, 2L, 1L, 4L, 1L, NA, 1L, 1L, 1L, 4L,
4L, 3L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 2L, 2L, 2L, 1L,
NA, 1L, 1L, 2L, 2L, 2L, 3L, 1L, 2L, 2L, 3L, 2L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), water_quant = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 6L, 1L, 2L, 1L,
1L, 1L, 6L, 6L, 6L, 5L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 3L, 1L, 3L, 3L, NA, 2L, 1L,
5L, 1L, 1L, 2L, 4L, 1L, 3L, 1L, 2L, 3L, 3L, 2L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), support_govern = structure(c(6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 5L, 6L, 6L, 4L, 5L, 6L, 1L, 5L, 6L, 3L, 3L, 3L, 3L,
3L, 2L, 3L, 3L, 2L, 5L, 5L, 3L, 2L, 4L, 3L, 3L, NA, 1L, 1L,
2L, 6L, 3L, 3L, 3L, 4L, 4L, 6L, 4L, 4L, 3L, 3L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), proud_comm = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 6L, 1L, 1L, 1L,
3L, 1L, 2L, 1L, 1L, 2L, 5L, 2L, 1L, 2L, 2L, 2L, NA, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 3L, 1L, 2L, 1L, 3L, 2L, 2L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), econ_comm = structure(c(6L,
6L, 6L, 6L, 5L, 6L, 5L, 5L, 6L, 6L, 3L, 6L, 6L, 5L, 3L, 5L,
3L, 4L, 5L, 2L, 2L, 5L, 5L, 6L, 2L, 6L, 5L, 5L, 5L, 5L, 3L,
2L, 3L, 3L, 1L, 1L, 3L, 2L, 3L, 2L, 3L, 3L, 3L, 2L, 3L, 1L,
3L, 2L, 3L, 1L, 5L, 3L, 2L, 5L, 2L, 6L, 3L, 4L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), jobs_comm = structure(c(6L,
6L, 4L, 4L, 6L, 6L, 6L, 6L, 6L, 6L, 5L, 6L, 6L, 4L, 6L, 4L,
6L, 4L, 5L, 5L, 5L, 3L, 2L, 6L, 1L, 6L, 5L, 5L, 5L, 5L, 2L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 1L,
2L, 2L, 2L, 1L, 5L, 2L, 3L, 4L, 2L, 2L, 3L, 2L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), inequality_comm = structure(c(1L,
1L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 1L, 3L, 6L, 1L, 2L, 6L, 2L,
6L, 2L, 6L, NA, NA, 5L, 1L, 6L, 3L, 6L, 5L, 5L, 5L, 5L, 1L,
3L, 3L, 2L, 3L, 4L, 2L, 3L, 4L, 3L, 2L, 4L, 3L, 3L, 5L, 3L,
4L, 5L, 3L, 1L, 4L, 3L, 4L, 2L, 3L, NA, 3L, 3L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), exp_growth = structure(c(6L,
6L, 4L, 4L, 6L, 6L, 6L, 5L, 6L, 6L, 4L, 4L, 6L, 2L, 2L, 2L,
5L, 2L, 3L, NA, NA, 3L, 3L, 6L, 1L, 6L, 5L, 3L, 2L, 6L, 4L,
2L, 2L, 3L, 2L, 3L, 5L, 2L, 3L, 2L, 3L, 4L, 2L, 3L, 2L, 1L,
2L, 5L, 3L, 4L, 2L, 4L, 2L, 6L, 3L, 3L, 3L, 3L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), future_region = structure(c(6L,
6L, 6L, 6L, 6L, 6L, 6L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
5L, 6L, 5L, 2L, 2L, 2L, 2L, 6L, 3L, 6L, 5L, 6L, 6L, 3L, 4L,
2L, 3L, 3L, 2L, 4L, 5L, 5L, 5L, 2L, 4L, 2L, 4L, 3L, 4L, 1L,
NA, 6L, 3L, 3L, 3L, 4L, 3L, 4L, 5L, 5L, 2L, 2L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), contamination_environ = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 6L, 1L, 6L, 1L,
6L, 1L, 1L, 6L, 6L, 6L, 4L, 1L, 4L, 6L, 1L, 1L, 1L, 1L, 4L,
1L, 2L, 1L, 3L, 3L, 1L, 2L, 1L, 3L, 3L, 5L, 2L, 2L, 1L, 1L,
NA, 1L, 1L, 1L, 1L, 5L, 2L, 1L, 3L, 2L, 3L, 2L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), conflicts_comm = structure(c(6L,
6L, 1L, 1L, 6L, 6L, 6L, 6L, 6L, 1L, 2L, 1L, 1L, 1L, 2L, 1L,
2L, 1L, 6L, 5L, 5L, 5L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 4L,
3L, 3L, 3L, 3L, 1L, 3L, 2L, 4L, 3L, 3L, 4L, 3L, NA, 4L, 2L,
3L, 2L, 3L, 3L, 5L, 4L, 4L, 1L, 3L, 5L, 3L, 4L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), infrastructure_comm = structure(c(6L,
6L, 6L, 6L, 6L, 6L, 6L, 5L, 6L, 6L, 4L, 6L, 5L, 6L, 5L, 6L,
5L, 6L, 3L, 3L, 3L, NA, 1L, 6L, 1L, 6L, 6L, 4L, 4L, 3L, 1L,
4L, 3L, NA, 3L, 1L, 5L, 6L, 2L, 3L, 3L, 4L, 3L, 2L, 1L, 2L,
2L, 4L, 2L, 3L, 6L, 4L, 3L, 3L, 3L, 3L, 2L, 2L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), included_mining = structure(c(1L,
1L, 1L, 1L, 5L, 6L, 6L, 6L, 6L, 6L, 3L, 6L, 6L, 6L, 5L, 6L,
6L, 6L, 3L, 5L, 5L, 6L, 3L, NA, 3L, NA, NA, 6L, 5L, 5L, 1L,
3L, 3L, 3L, 3L, 5L, 4L, 6L, 3L, 3L, 2L, 6L, 2L, NA, 2L, 3L,
2L, 5L, 5L, 3L, 5L, 3L, 3L, 2L, 4L, 5L, 3L, NA), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), investment_region = structure(c(1L,
1L, 3L, 3L, 6L, 6L, 6L, 5L, 6L, 1L, 2L, 1L, 6L, 2L, 4L, 1L,
2L, 2L, 3L, NA, NA, 4L, 1L, 5L, 3L, 5L, 5L, 1L, 2L, 2L, 4L,
2L, 2L, 2L, 4L, 1L, 2L, 3L, 3L, 2L, 3L, 1L, 3L, NA, 3L, 2L,
NA, 2L, 3L, 3L, 4L, 4L, 3L, 3L, 2L, 2L, 2L, 4L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), water_qual = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 6L, 5L, 5L, 5L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
4L, 3L, 1L, 2L, 3L, 1L, 3L, 2L, 3L, 1L, 3L, 3L, NA, 3L, 1L,
4L, 1L, 1L, 3L, 4L, 2L, 2L, 1L, 2L, 3L, 3L, 2L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor")), row.names = c(NA,
-58L), class = "data.frame")
我想你只是犯了一个简单的打字错误。而且您实际上并不需要创建 both
向量,因为您可以在函数调用中传递分组变量。尝试:
both_likert_2 = likert(g[, c(1:3), drop=FALSE], grouping = g$Location)
编辑:根据提供的新信息,这个怎么样:
g <- within(g, {
future_persp <- factor(future_persp, levels=1:6)
econ_comm <- factor(econ_comm, levels=1:6)
} )
comm_likert = likert(g[,2:3], grouping=g[,1])
plot(comm_likert)
编辑:OP 想要将 y 轴刻度标签更改为更合适的内容。
更改列的名称,但使用 dplyr 这样您就不必进行永久更改:
library(dplyr)
g %>%
dplyr::select(future_persp, econ_comm) %>%
rename(`It offers important economic perspectives`=future_persp,
`It provides economic prosperity to the community`=econ_comm) %>%
likert(grouping=g[, "Location"]) %>%
plot()
我在尝试创建包含两个组的李克特图时遇到问题。我在两个社区进行了一项调查。我现在想比较这两个社区。 [那是我的数据框][1]。到目前为止,我已经加载了一个包含 3 列的 sheet。一列表示位置(社区 1、社区 2),一列包含有关 econ_comm (1-6) 的答案,一列包含有关 future_persp (1-6) 的答案。我创建了一个李克特对象和第一个图形。
g_likert = likert(g[1:6])
plot(g_likert, ordered = FALSE, group.order = names(g[2:3]))
...它奏效了。以下是我到目前为止得到的。 [![在此处输入图片描述][2]][2]
我认为现在首先创建一个双对象很重要:both<-g$Location
(有效)
现在我开始惹麻烦了。以下代码显示错误:
both_likert_2 = likert(both[, c(1:3), drop=FALSE], grouping = both$location)
plot(both_likert_2, include.histogram = TRUE)
错误是:
Error in [.data.frame (g, 1:6) : undefined columns selected
Error in [.default (both, , c(1:3), drop = FALSE) : wrong number of dimensions - Objekt 'both_likert_2' not found
[我现在还附上了我的 R 的屏幕截图,以确保确定。][4] 我现在已经挣扎了很长一段时间,如果能得到一些帮助,我将非常感激。 最好, 菲利克斯
编辑: [![这是我在R中的现状][5]][5] 这是我重现它的代码:
library(likert)
g<-read.csv2("C:/Users/felix/OneDrive/Documents/R/SurveyData2.csv", sep=";", dec=",", header=TRUE)
both<-g$Location
g <- within(g, {
gold_21cent <- factor(gold_21cent, levels=1:6, labels=c("Completely agree", "Agree", "Slightly agree", "Slightly disagree", "Disagree", "Completely disagree"))
future_persp <- factor(future_persp, levels=1:6, labels=c("Completely agree", "Agree", "Slightly agree", "Slightly disagree", "Disagree", "Completely disagree"))
jobs_comm <- factor(jobs_comm, levels=1:6, labels=c("Completely agree", "Agree", "Slightly agree", "Slightly disagree", "Disagree", "Completely disagree"))
} )
.........etc............
comm_likert = likert(g[,2:14], grouping=g[,1])
plot(comm_likert)
library(dplyr)
g %>%
重命名(It offers important economic perspectives
=future_persp,
It provides economic prosperity to the community
=econ_comm) %>%
里克特(分组=位置)%>%
情节()
编辑:使用 dput(g)
structure(list(Location = structure(c(2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L), .Label = c("Huan", "TP"), class = "factor"),
gold_21cent = structure(c(6L, 6L, 3L, 3L, 2L, 2L, 2L, 2L,
2L, 6L, 3L, 2L, 2L, 3L, 2L, 3L, 1L, 3L, 2L, NA, NA, 1L, 1L,
6L, 4L, 6L, 5L, 2L, 2L, 2L, 4L, 4L, 3L, 3L, 2L, 3L, 2L, 3L,
3L, NA, 2L, 3L, 2L, NA, 2L, 2L, 3L, 5L, 3L, 3L, 3L, 3L, 3L,
3L, 4L, 2L, 3L, 6L), .Label = c("Completely agree", "Agree",
"Slightly agree", "Slightly disagree", "Disagree", "Completely disagree"
), class = "factor"), life_quality = structure(c(3L, 3L,
6L, 6L, 5L, 5L, 6L, 5L, 6L, 3L, 3L, 6L, 4L, 6L, 6L, 6L, 6L,
6L, 6L, NA, NA, 3L, 5L, 6L, 2L, 6L, 5L, 3L, 2L, 3L, 1L, 1L,
2L, 2L, 3L, 1L, 3L, 2L, 3L, 1L, 3L, 3L, 2L, 3L, 1L, 2L, NA,
3L, 2L, 2L, 3L, 3L, 3L, 5L, 5L, 3L, 2L, 3L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), coexist_tradact = structure(c(6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 2L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 5L, 5L, 6L, 2L, 6L, 1L, 6L, 5L, 6L, 6L, 6L, 1L,
4L, 2L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 4L, 3L, 2L, 3L, 3L, 3L,
4L, 4L, 3L, 2L, 4L, 5L, 4L, 2L, 4L, 6L, 3L, 2L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), emigration_comm = structure(c(6L,
6L, 6L, 6L, 6L, 6L, 6L, 5L, 6L, 6L, 5L, NA, 6L, 6L, 6L, 6L,
6L, 6L, 6L, NA, NA, 4L, 2L, 1L, 3L, 1L, 1L, 6L, 6L, 6L, 2L,
1L, 3L, 3L, 3L, 1L, 3L, 1L, 2L, 1L, 2L, 2L, 3L, 3L, 2L, 1L,
4L, 5L, 5L, 2L, 3L, 3L, 3L, 2L, 2L, 3L, 3L, 3L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), future_persp = structure(c(3L,
3L, 5L, 5L, 5L, 5L, 6L, 5L, 5L, 3L, 5L, 6L, 6L, 5L, 3L, 6L,
5L, 5L, 3L, 3L, 3L, 2L, 1L, 6L, 3L, 6L, 5L, 3L, 3L, 3L, 1L,
3L, 2L, 2L, 2L, 2L, 3L, 3L, 4L, 2L, 4L, 2L, 2L, 3L, 1L, 2L,
4L, 4L, 4L, 2L, 4L, 2L, 3L, 5L, 5L, 3L, 2L, 3L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), workers_comm = structure(c(6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 5L, 6L, 6L, 2L, 6L, 6L,
6L, 6L, 6L, 4L, 5L, NA, 1L, 6L, 1L, 6L, 5L, 6L, 6L, 6L, 1L,
2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 1L, 4L, 3L, 4L, 5L, 3L, 3L, 4L, 4L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), work_project = structure(c(6L,
6L, 6L, 6L, 5L, 5L, 6L, 5L, 6L, 6L, 6L, 6L, 5L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 5L, 3L, 6L, 4L, 6L, 5L, 6L, 6L, 6L, 6L,
3L, 2L, 2L, 1L, 1L, 3L, 6L, 3L, 3L, 2L, 6L, 3L, 3L, 3L, 1L,
3L, 6L, 5L, 6L, 5L, 1L, 6L, 6L, 5L, 6L, 2L, 3L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), agree_comm = structure(c(6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 5L, 6L, 6L, 6L, 5L, 6L,
6L, 6L, 6L, 5L, 5L, 5L, 3L, 6L, 2L, 5L, 6L, 6L, 6L, 6L, 3L,
3L, 2L, 3L, 3L, 1L, 3L, 3L, 3L, 2L, 4L, 1L, 3L, NA, 3L, 2L,
3L, 3L, NA, 3L, 3L, 4L, 3L, 3L, 3L, 4L, 2L, 3L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), informed_deals = structure(c(4L,
4L, 1L, 1L, 5L, 6L, 5L, 5L, 5L, 6L, 4L, 5L, 5L, 6L, 4L, 6L,
5L, 6L, 4L, 6L, 6L, 6L, 1L, 6L, 3L, 6L, 1L, 2L, 2L, 2L, 4L,
2L, 3L, 3L, 2L, 1L, 5L, 6L, 5L, 2L, 3L, 5L, 3L, 3L, 4L, 4L,
2L, 4L, 4L, 5L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), fear_environ = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 5L, 1L,
1L, 1L, 1L, 6L, 6L, 1L, 2L, 1L, 4L, 1L, NA, 1L, 1L, 1L, 4L,
4L, 3L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 2L, 2L, 2L, 1L,
NA, 1L, 1L, 2L, 2L, 2L, 3L, 1L, 2L, 2L, 3L, 2L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), water_quant = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 6L, 1L, 2L, 1L,
1L, 1L, 6L, 6L, 6L, 5L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 3L, 1L, 3L, 3L, NA, 2L, 1L,
5L, 1L, 1L, 2L, 4L, 1L, 3L, 1L, 2L, 3L, 3L, 2L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), support_govern = structure(c(6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 5L, 6L, 6L, 4L, 5L, 6L, 1L, 5L, 6L, 3L, 3L, 3L, 3L,
3L, 2L, 3L, 3L, 2L, 5L, 5L, 3L, 2L, 4L, 3L, 3L, NA, 1L, 1L,
2L, 6L, 3L, 3L, 3L, 4L, 4L, 6L, 4L, 4L, 3L, 3L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), proud_comm = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 6L, 1L, 1L, 1L,
3L, 1L, 2L, 1L, 1L, 2L, 5L, 2L, 1L, 2L, 2L, 2L, NA, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 3L, 1L, 2L, 1L, 3L, 2L, 2L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), econ_comm = structure(c(6L,
6L, 6L, 6L, 5L, 6L, 5L, 5L, 6L, 6L, 3L, 6L, 6L, 5L, 3L, 5L,
3L, 4L, 5L, 2L, 2L, 5L, 5L, 6L, 2L, 6L, 5L, 5L, 5L, 5L, 3L,
2L, 3L, 3L, 1L, 1L, 3L, 2L, 3L, 2L, 3L, 3L, 3L, 2L, 3L, 1L,
3L, 2L, 3L, 1L, 5L, 3L, 2L, 5L, 2L, 6L, 3L, 4L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), jobs_comm = structure(c(6L,
6L, 4L, 4L, 6L, 6L, 6L, 6L, 6L, 6L, 5L, 6L, 6L, 4L, 6L, 4L,
6L, 4L, 5L, 5L, 5L, 3L, 2L, 6L, 1L, 6L, 5L, 5L, 5L, 5L, 2L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 1L,
2L, 2L, 2L, 1L, 5L, 2L, 3L, 4L, 2L, 2L, 3L, 2L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), inequality_comm = structure(c(1L,
1L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 1L, 3L, 6L, 1L, 2L, 6L, 2L,
6L, 2L, 6L, NA, NA, 5L, 1L, 6L, 3L, 6L, 5L, 5L, 5L, 5L, 1L,
3L, 3L, 2L, 3L, 4L, 2L, 3L, 4L, 3L, 2L, 4L, 3L, 3L, 5L, 3L,
4L, 5L, 3L, 1L, 4L, 3L, 4L, 2L, 3L, NA, 3L, 3L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), exp_growth = structure(c(6L,
6L, 4L, 4L, 6L, 6L, 6L, 5L, 6L, 6L, 4L, 4L, 6L, 2L, 2L, 2L,
5L, 2L, 3L, NA, NA, 3L, 3L, 6L, 1L, 6L, 5L, 3L, 2L, 6L, 4L,
2L, 2L, 3L, 2L, 3L, 5L, 2L, 3L, 2L, 3L, 4L, 2L, 3L, 2L, 1L,
2L, 5L, 3L, 4L, 2L, 4L, 2L, 6L, 3L, 3L, 3L, 3L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), future_region = structure(c(6L,
6L, 6L, 6L, 6L, 6L, 6L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
5L, 6L, 5L, 2L, 2L, 2L, 2L, 6L, 3L, 6L, 5L, 6L, 6L, 3L, 4L,
2L, 3L, 3L, 2L, 4L, 5L, 5L, 5L, 2L, 4L, 2L, 4L, 3L, 4L, 1L,
NA, 6L, 3L, 3L, 3L, 4L, 3L, 4L, 5L, 5L, 2L, 2L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), contamination_environ = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 6L, 1L, 6L, 1L,
6L, 1L, 1L, 6L, 6L, 6L, 4L, 1L, 4L, 6L, 1L, 1L, 1L, 1L, 4L,
1L, 2L, 1L, 3L, 3L, 1L, 2L, 1L, 3L, 3L, 5L, 2L, 2L, 1L, 1L,
NA, 1L, 1L, 1L, 1L, 5L, 2L, 1L, 3L, 2L, 3L, 2L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), conflicts_comm = structure(c(6L,
6L, 1L, 1L, 6L, 6L, 6L, 6L, 6L, 1L, 2L, 1L, 1L, 1L, 2L, 1L,
2L, 1L, 6L, 5L, 5L, 5L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 4L,
3L, 3L, 3L, 3L, 1L, 3L, 2L, 4L, 3L, 3L, 4L, 3L, NA, 4L, 2L,
3L, 2L, 3L, 3L, 5L, 4L, 4L, 1L, 3L, 5L, 3L, 4L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), infrastructure_comm = structure(c(6L,
6L, 6L, 6L, 6L, 6L, 6L, 5L, 6L, 6L, 4L, 6L, 5L, 6L, 5L, 6L,
5L, 6L, 3L, 3L, 3L, NA, 1L, 6L, 1L, 6L, 6L, 4L, 4L, 3L, 1L,
4L, 3L, NA, 3L, 1L, 5L, 6L, 2L, 3L, 3L, 4L, 3L, 2L, 1L, 2L,
2L, 4L, 2L, 3L, 6L, 4L, 3L, 3L, 3L, 3L, 2L, 2L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), included_mining = structure(c(1L,
1L, 1L, 1L, 5L, 6L, 6L, 6L, 6L, 6L, 3L, 6L, 6L, 6L, 5L, 6L,
6L, 6L, 3L, 5L, 5L, 6L, 3L, NA, 3L, NA, NA, 6L, 5L, 5L, 1L,
3L, 3L, 3L, 3L, 5L, 4L, 6L, 3L, 3L, 2L, 6L, 2L, NA, 2L, 3L,
2L, 5L, 5L, 3L, 5L, 3L, 3L, 2L, 4L, 5L, 3L, NA), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), investment_region = structure(c(1L,
1L, 3L, 3L, 6L, 6L, 6L, 5L, 6L, 1L, 2L, 1L, 6L, 2L, 4L, 1L,
2L, 2L, 3L, NA, NA, 4L, 1L, 5L, 3L, 5L, 5L, 1L, 2L, 2L, 4L,
2L, 2L, 2L, 4L, 1L, 2L, 3L, 3L, 2L, 3L, 1L, 3L, NA, 3L, 2L,
NA, 2L, 3L, 3L, 4L, 4L, 3L, 3L, 2L, 2L, 2L, 4L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor"), water_qual = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 6L, 5L, 5L, 5L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
4L, 3L, 1L, 2L, 3L, 1L, 3L, 2L, 3L, 1L, 3L, 3L, NA, 3L, 1L,
4L, 1L, 1L, 3L, 4L, 2L, 2L, 1L, 2L, 3L, 3L, 2L), .Label = c("Completely agree",
"Agree", "Slightly agree", "Slightly disagree", "Disagree",
"Completely disagree"), class = "factor")), row.names = c(NA,
-58L), class = "data.frame")
我想你只是犯了一个简单的打字错误。而且您实际上并不需要创建 both
向量,因为您可以在函数调用中传递分组变量。尝试:
both_likert_2 = likert(g[, c(1:3), drop=FALSE], grouping = g$Location)
编辑:根据提供的新信息,这个怎么样:
g <- within(g, {
future_persp <- factor(future_persp, levels=1:6)
econ_comm <- factor(econ_comm, levels=1:6)
} )
comm_likert = likert(g[,2:3], grouping=g[,1])
plot(comm_likert)
编辑:OP 想要将 y 轴刻度标签更改为更合适的内容。 更改列的名称,但使用 dplyr 这样您就不必进行永久更改:
library(dplyr)
g %>%
dplyr::select(future_persp, econ_comm) %>%
rename(`It offers important economic perspectives`=future_persp,
`It provides economic prosperity to the community`=econ_comm) %>%
likert(grouping=g[, "Location"]) %>%
plot()