R-ggplot2-plot_likert-하나의 그래프에 관련 주제에 대한 두 개의 서로 다른 likert 척도를 플로팅합니다.

그냥 sabbyATL

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)

하지만 다음과 같은 플롯을보고 싶습니다.

여기에 이미지 설명 입력

얼마나 쉬울까요? 아니면 포토샵에서해야합니까? : /

앨런 카메론

을 사용하여이 작업을 수행 할 수 있는지 모르겠지만 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")

여기에 이미지 설명 입력

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관