Flipping likert scale colours

Hi there,

I would like to flip or invert the colour scale used as default in the likert analysis. I have tried reverse.levels but I get the following error message "Error in reverse.levels(p) : Unsupported format: likert"

Here is some sample data and code.

question1<- c(1,5,3,4,1,1,1,3,4,5)
question2<- rev(c(1,5,3,4,1,1,1,3,4,5))
question3<- c(1,1,1,2,2,2,3,3,4,5)
question4<- c(5,5,5,4,4,4,3,3,2,1)
testData<-data.frame(question1,question2,question3,question4)
testData <- lapply(testData, factor, levels= c(1:5), ordered = TRUE)
testData <- as.data.frame(testData)

df.reverse <- reverse.levels(testData)
#> Error in reverse.levels(testData): could not find function "reverse.levels"


p <- (likert(testData))
#> Error in likert(testData): could not find function "likert"
plot(p)
#> Error in plot(p): object 'p' not found

df.reverse <- reverse.levels(p)
#> Error in reverse.levels(p): could not find function "reverse.levels"

Created on 2022-11-21 with reprex v2.0.2

Produces the following:

I would like the dark green to be for response 1, not 5 etc

Any help or advice is greatly appreciated.

1 Like

you could use this syntax in ggplot:

... +
scale_fill_manual(breaks = c("1", "2", "3", "4", "5"), 
                    values = c("#59B4AB", "#ACD9D5", "#E5E5E5", "#EBD9B2", "#D7B365"))

I get a NULL from

p + scale_fill_manual(breaks = c("1", "2", "3", "4", "5"), 
                    values = c("#59B4AB", "#ACD9D5", "#E5E5E5", "#EBD9B2", "#D7B365"))

But the likert::plot is ok with

library(likert)
#> Loading required package: ggplot2
#> Loading required package: xtable
question1<- c(1,5,3,4,1,1,1,3,4,5)
question2<- rev(c(1,5,3,4,1,1,1,3,4,5))
question3<- c(1,1,1,2,2,2,3,3,4,5)
question4<- c(5,5,5,4,4,4,3,3,2,1)
testData<-data.frame(question1,question2,question3,question4)
testData <- lapply(testData, factor, levels= c(1:5), ordered = TRUE)
testData <- as.data.frame(testData)

df.reverse <- reverse.levels(testData)

p <- (likert(testData))
plot(p)

p <- (likert(df.reverse))
plot(p,colors = c("red", "pink", "green", "blue", "yellow"))

Thank you @technocrat and @Flm for your replies.

I pulled up an error with

p + scale_fill_manual(breaks = c("1", "2", "3", "4", "5"), 
                    values = c("#59B4AB", "#ACD9D5", "#E5E5E5", "#EBD9B2", "#D7B365"))

as well. But manually setting the colours worked, as per:

p <- (likert(df.reverse))
plot(p,colors = c("red", "pink", "green", "blue", "yellow"))

Many thanks!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.