简体   繁体   中英

Error: id variables not found in data: Item when trying to plot in R

I am new to using R, and I am trying to make a diverging stacked bar chart, as demonstrated here and here .

I have the following R code that I modified from working code. My modified code is giving me an error. The error I am getting is Error: id variables not found in data: Item . I do not understand why I'm getting this error.

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)

I was modifying this following 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)

I was able to fix it and get it working by changing

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

to

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

However, I am still unsure why this was needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM