1

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)

image

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66

1 Answers1

1

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)

Likert plot multiple groups

Joris C.
  • 5,721
  • 3
  • 12
  • 27
  • ...and you could use something like this to convert the existing 1:6 into the respective factor: `df$Score_factor = factor(df$Score, labels = c("Strongly Disagree", "Disagree", "Slightly Disagree", "Slightly Agree", "Agree", "Strongly Agree"))` – Jon Spring Jul 01 '19 at 04:38
  • Thanks Joris for your help. I do not get where is should place the input of my data in your script the 2 lines below Q1 <- read_excel("C:\\Users\\users\\Desktop\\Survey Responses\\Business Survey\\BusinessLikert.xlsx") df <- data.frame(respondent = c(Q1$Respondent), Score = c(Q1$Q1)). – user11557166 Jul 01 '19 at 06:07
  • As @JonSpring commented, you can convert the existing Score column in your data.frame to a factor with `factor` and specify its level-names. You can read more about factors in R here: https://www.stat.berkeley.edu/~s133/factors.html – Joris C. Jul 01 '19 at 06:09
  • Forgot to mention the data input is a 11 colums Q1, Q2, Q3, Q4 etc with the response scores from the survey. In total 47 responses for each column, so for instance, Q1 has 47 cell with responses between 1 and 6 – user11557166 Jul 01 '19 at 06:10
  • As is, your data is not reproducible, consider including (part of) your data in the question with `dput` or include an artificially created dataset with similar structure, see also https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Joris C. Jul 01 '19 at 06:20
  • @user11557166 I included an example that recodes multiple columns of a data.frame as factors before calling the `likert` function – Joris C. Jul 01 '19 at 13:51