Reputation: 21
I have developed a script to plot a Likert scale. The Script works properly and the plot is correct. I want to change the response label which would be, "Strongly Disagree","Disagree","Slightly Disagree","Slightly Agree","Agree", "Strongly Agree" in an orderly list. I have tried different solutions but none seems to work
Q1 <- read_excel("C:\\Users\\users\\Desktop\\Survey Responses\\Business Survey\\BusinessLikert.xlsx")
df <- data.frame(respondent = c(Q1$Respondent), Score = c(Q1$Q1))
df1 <- likert(items=df[,2, drop = FALSE], nlevels = 6)
summary(df1)
likert.bar.plot(df1)
likert.density.plot(df1)
Upvotes: 1
Views: 2637
Reputation: 6244
As stated in the documentation of the likert
function (?likert::likert
), the columns of the data.frame in items
should be factors. The level names then specify the response labels used in the derived likert plots. Since your data is not reproducible, consider the following artificial example:
library(likert)
set.seed(1)
df <- data.frame(Score = factor(sample(1:6, size = 100, replace = TRUE),
labels = c("Strongly Disagree", "Disagree", "Slightly Disagree", "Slightly Agree", "Agree", "Strongly Agree")))
(df_likert <- likert(items = df))
#> Item Strongly Disagree Disagree Slightly Disagree Slightly Agree Agree
#> 1 Score 19 18 12 15 15
#> Strongly Agree
#> 1 21
likert.bar.plot(df_likert)
Edit: for multiple (e.g. numeric) columns representing individual response groups in the data.frame, recode the columns as factors first and then apply the likert
function to the recoded data.frame:
## initial data.frame of integers
df <- data.frame(
sapply(c("Q1", "Q2", "Q3"), function(x) sample(1:6, size = 100, replace = TRUE))
)
## recode each column as a factor
df_factor <- as.data.frame(
lapply(df, function(x) factor(x,
labels = c("Strongly Disagree", "Disagree", "Slightly Disagree",
"Slightly Agree", "Agree", "Strongly Agree"))
)
)
(df_likert <- likert(items = df_factor))
#> Item Strongly Disagree Disagree Slightly Disagree Slightly Agree Agree
#> 1 Q1 19 18 12 15 15
#> 2 Q2 19 16 19 18 15
#> 3 Q3 18 15 8 21 20
#> Strongly Agree
#> 1 21
#> 2 13
#> 3 18
likert.bar.plot(df_likert)
Upvotes: 1