【问题标题】:Custom color palette for plot_likert function from sjPlot来自 sjPlot 的 plot_likert 函数的自定义调色板
【发布时间】:2021-09-04 09:08:51
【问题描述】:

我可以使用 sjPlot R 包中的 plot_likert 函数绘制以下数据。

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
  )

我想知道如何获得以下配色方案:

Strongly Disagree = Dark Red
Disagree          = Light Red
Neutral           = Gray
Agree             = Light Green
Strongly Agree    = Dark Green

【问题讨论】:

    标签: r plot sjplot likert


    【解决方案1】:

    您可以通过参数geom.colorscat.neutral.color 设置您想要的颜色:

    注意:由于 R 没有名为 lightred 的颜色,所以我切换到了 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")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-08
      • 2023-03-24
      • 2019-04-07
      • 1970-01-01
      • 2020-04-28
      • 2015-05-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多