我正在创建用于回答调查问题的图表,这些问题具有“非常真实”到“根本不真实”的 5 点 Likert 风格量表。该调查在参加活动之前和之后进行。有些问题是积极提出的(即,朝着“非常真实”的方向发展将被认为是一种改进),而有些问题是消极地提出的(即,朝着“根本不正确”发展)将是一种改进。
我使用 HH 包中的 Likert 函数创建了图表。我想做的是翻转负面措辞问题的色标,以便更直观地看到哪里发生了改进(即,向粉红色的转变总是积极的,无论这是否是“非常真实” ”或“根本不正确”)。
有没有简单的方法可以做到这一点?
这就是我拥有的东西:
##Packages
library (HH)
# Data
section_1 <- data.frame(
question = c("I know when I have understood a new concept or idea","After I finish a test, I can't tell whether I have done well or not until I get the results","I know when I have understood a new concept or idea","After I finish a test, I can't tell whether I have done well or not until I get the results"),
pre_post=c("PRE","PRE","POST","POST"),
"Very true"=c(4,9,15,4),
"Mostly true"=c(5,6,8,3),
"A little bit true"=c(5,12,4,8),
"Not really true"=c(7,6,3,11),
"Not true at all"=c(5,9,17,4))
# creating the graph
fig1 <- likert(pre_post~.| question,
data = section_1,
as.percent = TRUE,
ReferenceZero = 3,
ylab = "Question",
xlim=c(-100, 100),
main = list("Knowledge of Cognition", x=unit(.55, "npc")),
col= c("#E6007E","#F380BF" ,"#DDDFE4" , "#80CFF1", "#009FE3"),
strip=strip.custom(factor.levels=c("I know when I have understood \na new concept or idea", "After I finish a test, I \ncan't tell whether I have \ndone well or not until I get \nthe results")),
par.strip.text=list(cex=0.6, lines=5),
)
因此,与第一个( “我知道什么时候我理解了一个新概念或想法”)。
如果我只是将列表中的颜色添加到“col”参数中,它只会向图例添加更多颜色。
有人有什么想法吗?如果在这里不可能,是否可以通过在例如 ggplot2 中制作类似的图表来实现?我一直在努力让它发挥作用,以避免从头开始,但如果需要的话我会的。
PS 我基本上是自学 R 的,主要是从反复试验中学习的,我经常发现自己很难完全理解这里问题的答案,所以如果你能尝试尽可能清楚地解释任何事情,我将非常感激!预先感谢!
您可以尝试创建两个单独的图表并将它们组合起来。对你有用吗?
# Data
section_1 <- data.frame(
question = c("I know when I have understood a new concept or idea", "I know when I have understood a new concept or idea"),
pre_post = c("PRE", "POST"),
"Very true"=c(4,15),
"Mostly true"=c(5,8),
"A little bit true"=c(5,4),
"Not really true"=c(7,3),
"Not true at all"=c(5,17)
)
section_2 <- data.frame(
question = c("After I finish a test, I can't tell whether I have done well or not until I get the results", "After I finish a test, I can't tell whether I have done well or not until I get the results"),
pre_post = c("PRE", "POST"),
"Very true"=c(9,4),
"Mostly true"=c(6,3),
"A little bit true"=c(12,8),
"Not really true"=c(6,11),
"Not true at all"=c(9,4)
)
# creating graphs
p1 <- likert(pre_post~.| question,
data = section_1,
as.percent = TRUE,
ReferenceZero = 3,
ylab = "Question",
xlim=c(-100, 100),
main = list("Knowledge of Cognition", x=unit(.55, "npc")),
col= c("#E6007E","#F380BF" ,"#DDDFE4" , "#80CFF1", "#009FE3")
)
p2 <- likert(pre_post~.| question,
data = section_2,
as.percent = TRUE,
ReferenceZero = 3,
ylab = "Question",
xlim=c(-100, 100),
main = list("", x=unit(.55, "npc")),
col= c("blue","red" ,"yellow" , "purple", "orange")
)
# combining graphs
grid.arrange(p1, p2, nrow = 2)