来自 sjPlot 的 plot_likert 函数的自定义调色板
Custom color palette for plot_likert function from sjPlot
我可以使用 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
您可以通过参数 geom.colors
和 cat.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")
我可以使用 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
您可以通过参数 geom.colors
和 cat.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")