R - ggplot2 - plot_likert - 在一张图上绘制关于相关主题的两个不同的李克特量表

R - ggplot2 - plot_likert - Plot two different likert scales about related topic on one graph

如果有办法使用 ggplot2 或类似工具来绘制它,那将节省我的时间。我有关于员工福利的李克特量表数据。一个问题会问福利有多重要,下一个问题会问员工对福利的满意度如何。


dat <- structure(list(`Medical Insurance` = structure(c(3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("Neutral / Undecided", 
"Not at all Important", "Very Important"), class = "factor"), 
    `Medical: Overall` = structure(c(3L, 3L, 4L, 4L, 4L, 3L, 
    4L, 4L, 3L, 3L), .Label = c("Don't Use", "Less Satisfied", 
    "Satisfied", "Very Satisfied"), class = "factor"), `Wellness Program` = structure(c(3L, 
    3L, 1L, 3L, 3L, 1L, 3L, 3L, 3L, 1L), .Label = c("Neutral / Undecided", 
    "Not at all Important", "Very Important"), class = "factor"), 
    `Medical: Wellness Program` = structure(c(3L, 3L, 4L, 4L, 
    4L, 3L, 3L, 4L, 3L, 1L), .Label = c("Don't Use", "Less Satisfied", 
    "Satisfied", "Very Satisfied"), class = "factor"), `Employee Assistance Program` = structure(c(1L, 
    3L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L), .Label = c("Neutral / Undecided", 
    "Not at all Important", "Very Important"), class = "factor"), 
    `Employee Assistance Program2` = structure(c(1L, 4L, 3L, 
    1L, 4L, 1L, 3L, 4L, 2L, 1L), .Label = c("Don't Use", "Less Satisfied", 
    "Satisfied", "Very Satisfied"), class = "factor")), row.names = c(NA, 
10L), class = "data.frame")

我可以分别绘制每个尺度:

ben.imp <- dat[,seq(1,5,2)]
ben.sat <- dat[,seq(2,6,2)]

library(ggthemes)
library(stringr)
library(sjPlot)
library(sjmisc)
library(ggplot2)
library(wesanderson)

col2 <- c(wes_palettes$GrandBudapest1[2],wes_palettes$Cavalcanti1[4])

likert.ben <- plot_likert(ben.imp, cat.neutral = 1, sort.frq="neg.desc", reverse.colors=T, values = "show",
            show.n=F, digits=0, show.prc.sign=T, show.legend=T, geom.colors=col2, cat.neutral.color=col1[1])+  
                    theme(
                legend.title=element_text(size=14), 
                axis.text=element_text(size=12, face="bold"),
                    legend.text=element_text(size=12),               
                panel.background = element_rect(fill = "transparent",colour = NA),
                    plot.background = element_rect(fill = "transparent",colour = NA),
                    #panel.border=element_blank(),
                    panel.grid.major=element_blank(),
                    panel.grid.minor=element_blank()
                    )+
                guides(fill = guide_legend(reverse=TRUE))+
    geom_text(size=5, position = position_dodge2(width=0.9), vjust=0)



col4 <- c("gray", wes_palettes$GrandBudapest1[2],wes_palettes$Darjeeling2[4], wes_palettes$Cavalcanti1[4])

likert.bensat <- plot_likert(ben.sat, catcount=4,  sort.frq="neg.desc", 
                     reverse.colors=T, values = "show",
            show.n=F, digits=0, show.prc.sign=T, show.legend=T, geom.colors=col4, cat.neutral.color=col1[1])+  
                    theme(
                legend.title=element_text(size=14), 
                axis.text=element_text(size=12, face="bold"),
                    legend.text=element_text(size=12),               
                panel.background = element_rect(fill = "transparent",colour = NA),
                    plot.background = element_rect(fill = "transparent",colour = NA),
                    #panel.border=element_blank(),
                    panel.grid.major=element_blank(),
                    panel.grid.minor=element_blank()
                    )+
                guides(fill = guide_legend(reverse=TRUE))+
    geom_text(size=5, position = position_dodge2(width=0.9), vjust=0)

但我希望看到这样的情节:

那有多容易?还是我只需要在 photoshop 中完成? :/

我不知道你是否可以用 plot_likert 做到这一点,但你可以用 ggplot 本机做到这一点。不过,您需要先稍微重塑一下数据:

library(tidyr)
library(dplyr)

names(ben.imp) <- c("Insurance", "Wellness", "Assistance")
names(ben.sat) <- c("Insurance", "Wellness", "Assistance")

ben.imp <- pivot_longer(ben.imp, 1:3) %>% mutate(class = "Importance")
ben.sat <- pivot_longer(ben.sat, 1:3) %>% mutate(class = "Satisfaction")

df <- rbind(ben.imp, ben.sat)
df$value <- factor(df$value, c())

ggplot(df, aes(x = class, fill = value)) + 
  geom_bar() +
  facet_grid(~name, switch = "x") +
  scale_x_discrete(expand = c(0.1, 0.4)) +
  scale_fill_manual(values = c("#a04ca4", "#c7bfe6", "#00000000", 
                               "#4d7b9c", "#ea9138", "#e05554")) +
  theme_classic() +
  theme(panel.spacing = unit(0, "points"),
        strip.background = element_blank(),
        strip.placement = "outside")