0

I can plot with following data using plot_likert function from sjPlot R package.

library(tidyverse)
df1 <-
  data.frame(
  matrix(
    data = sample(x = c("Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"), size = 500, replace = TRUE),
    ncol = 5
    )
  ) %>% 
  mutate_all(., ~ ordered(., levels = c("Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree")))

df1
library(sjPlot)
plot_likert(
   items       = df1
  , cat.neutral = 3
  )

enter image description here

I wonder how to get the following color scheme:

Strongly Disagree = Dark Red
Disagree          = Light Red
Neutral           = Gray
Agree             = Light Green
Strongly Agree    = Dark Green
MYaseen208
  • 22,666
  • 37
  • 165
  • 309

1 Answers1

1

You could set your desired colors via the arguments geom.colors and cat.neutral.color:

Note: As R has no color named lightred I switched to firebrick1.

library(tidyverse)
library(sjPlot)

df1 <- data.frame(
    matrix(
      data = sample(x = c("Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"), size = 500, replace = TRUE),
      ncol = 5
    )
  ) %>% 
  mutate_all(., ~ ordered(., levels = c("Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree")))

plot_likert(items = df1, cat.neutral = 3, 
            geom.colors = c("darkred", "firebrick1", "lightgreen", "darkgreen"),
            cat.neutral.color = "gray")

stefan
  • 90,330
  • 6
  • 25
  • 51