0

我是使用 R 的新手,我正在尝试制作一个发散堆积条形图,如此此处所示。

我有以下从工作代码修改的 R 代码。我修改后的代码给了我一个错误。我得到的错误是Error: id variables not found in data: Item. 我不明白为什么会收到此错误。

library("devtools")
library("likert")

scale_height = knitr::opts_chunk$get('fig.height')*0.5
scale_width = knitr::opts_chunk$get('fig.width')*1.25
knitr::opts_chunk$set(fig.height = scale_height, fig.width = scale_width)

theme_update(legend.text = element_text(size = rel(0.7)))

# u = understandability
title_u = "Understandability"

headers_u_n_a = c("Type", "Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree")

y_label = "Video Transformation"

understandability_csv_text = "Type  Strongly Disagree   Disagree    Neutral Agree   Strongly Agree
WT  0.00    0.00    0.00    27.27   72.73
WoT 0.00    18.18   18.18   18.18   45.45
TF  9.09    9.09    36.36   27.27   18.18"

u_data = read.csv(text=understandability_csv_text, header=TRUE, sep="\t")
u_data$Type = as.factor(u_data$Type)
names(u_data) = headers_u_n_a
u_data_summary = likert(summary = u_data)
plot(u_data_summary, plot.percent.neutral=TRUE, plot.percent.low=FALSE, plot.percent.high=FALSE) + ylab(y_label) + ggtitle(title_u)

我正在修改以下 MWE:

library("devtools")
library("likert")

scale_height = knitr::opts_chunk$get('fig.height')*0.5
scale_width = knitr::opts_chunk$get('fig.width')*1.25
knitr::opts_chunk$set(fig.height = scale_height, fig.width = scale_width)

theme_update(legend.text = element_text(size = rel(3)))
theme_update(axis.title = element_text(size = rel(4)))
theme_update(plot.title = element_text(size = rel(4)))
theme_update(axis.text = element_text(size = rel(4)))

title_q1 = "I'm satisfied with the way the results are ranked"

headers_q1 = c("Item","Strongly Disagree",  "Disagree", "Neither Agree nor Disagree",   "Agree",    "Strongly Agree")

xlab_first = "Position"

CSV_Text = "K,Strongly Disagree,Disagree,Neither Agree nor Disagree,Agree,Strongly Agree
10,2.752293578,15.59633028,18.34862385,48.62385321,14.67889908
5,1.739130435,5.217391304,6.086956522,48.69565217,38.26086957
1,1.639344262,0,0,13.93442623,84.42622951
20,11.76470588,33.33333333,22.54901961,27.45098039,4.901960784"

first_q1 = read.csv(text=CSV_Text, header=TRUE, sep=",")
first_q1$K= as.factor(first_q1$K)
names(first_q1) = headers_q1
s_first_q1 = likert(summary = first_q1)
plot(s_first_q1, plot.percent.neutral=FALSE, plot.percent.low=FALSE, plot.percent.high=FALSE) + xlab(xlab_first) + ggtitle(title_q1)
4

1 回答 1

0

我能够修复它并通过更改使其工作

headers_u_n_a = c("Type", "Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree")

headers_u_n_a = c("Item", "Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree")

但是,我仍然不确定为什么需要这样做。

于 2021-03-31T03:33:32.463 回答