12:43 PM
0
Q: Legend in Likert plot appear white instead of color in R

Homer Jay Simpsoni have a data frame in R called df which is a subset of pisaitems data of likert package. The problem i face is that when i plot the result of the likert function the legend of level "Agree" appear in white color because there are no data for this category.But i want this category-level to have a...

 
Does this answer your question? stackoverflow.com/q/32167573/7669319
 
@FelixJassler no because he/she is using HH package that has the same function likert() but takes different data frame structure input. My problem is specific to likert package.This package is that i use in real data.
 
Hm... I'm not sure I see the problem, is it not possible to set the col parameter inside plot()? (i.e., plot(df_plot, col=c('#d8b366', '#ebd9b1', '#acd8d4', 'red')))
Also note that the data does not contain any Agree response, which might be why it doesn't appear properly.
 
@FelixJassler if you run it you will see again the color in the legend of the agree level is white.I know that there are no data for agree level.But nonetheless i want the legend to be colored appropriately
 
Have you tried adding a couple of 3L to the data to see if the Agree response is being rendered?
 
12:43 PM
@FelixJassler yes is being rendered but this is not the case.
tell me
 
Ah sorry for the confusion, I think I understand your problem better now. For some reason, Agree still shows the color on my side however
Maybe you have to update the package
 
you added data ?
 
install.packages('likert')
 
ok lets see
 
I took the df from your question (then one that does not have any 3L in it)
 
12:48 PM
likert package does not need update
 
strange
what R version do you use? R.Version()$version.string
 
R.Version()$version.string
[1] "R version 4.3.3 (2024-02-29 ucrt)"
 
I just restarted RStudio and let this whole block run. The results look fine to me (with `Agree` being colored in green in the legend – even when not setting the `col` parameter)


```
library(likert)
df <- structure(
list(
ST24Q01=structure(c(2,2,4,2,1,2,2,2,2,4,2,2,1,1,1,1,1,2,1,2,2,2,4,2,2,2,1,2,1,4,2,2,2,1,1,1,1,2,2,1,1,2,1,2,2,2,1,1,2,1), levels=c("Strongly disagree","Disagree","Agree","Strongly agree"), class="factor"),
ST24Q02=structure(c(4,1,1,2,2,1,2,1,2,1,2,2,2,2,2,4,2,4,4,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,4,2,2,2,2,2,2,2,4,2,2,2,2,2,2,4), levels=c("Strongly disagree","Disagree","Agre
Your version number seems fine. I'm not sure what other discrepancy there is :/
 
This probably also won't make a difference, but does it render the same thing in a shiny app?

```
library(shiny)
shinyApp(
fluidPage(plotOutput('plot')),
function(input, output, session) {
output$plot <- renderPlot(plot(df_plot))
}
)
```
 
I also had a look at the available options (github.com/jbryer/likert/blob/master/R/likert.options.R), but I am certain there is just some quirk on your system. Maybe a botched install (you could try uninstalling and reinstalling some packages with remove.packages()). Sorry I can't provide further help
 
1:30 PM
ty
 
no problem. good luck!