Chapter 21 Likert

Shijie He and Chutian Chen

21.1 Overview

This section covers how to make stacked bar chart on likert data.

Likert data is the data with likert scale. Likert scale is a several point scale which is used to allow people to express how much they agree or disagree with a particular statement. And It’s commonly used in survey and research.

21.3 Simple examples

Too complicated! Let’s see some simpler examples first.

For the below examples, we will use the survey of the satisfaction of Trump for male and female.

##   Gender Great Good Average Poor Terrible
## 1   Male     4   14      15   17       44
## 2 Female     2    6      16   17       48

For more info on this dataset, go to https://d25d2506sfb94s.cloudfront.net/cumulus_uploads/document/psse08hgpj/YouGov%20-%20Trump%20state%20visit%20190520.pdf.

21.3.1 Stacked bar chart

To create a stacked bar chart, we will simply use likert function.

It is easy to compare the end values using stacked bar chart, but it is hard to compare the neutral percentage.

21.3.2 Diverging stacked bar chart

To create a diverging stacked bar chart, we will modify ReferenceZero to the neutral category.

It is easy to visualize the overall shape of likes and dislikes, and the percentage of neutrals. However, it is hard to compare the value of like and dislike categories.

21.4 Stacked bar chart using ggplot

In fact, we can make likert plot using ggplot. There is a easy way through dividing the data into two parts which represent agreement and disagreement respectively. Then we can generate the two plots on same place with one of the value of plot is negative. If there is neutral option in data, we have to divide it into two parts, which will be a little more complicated.

library(ggplot2)
library(reshape2)
library(RColorBrewer)
library(dplyr)
library(ggthemes)
library(stringr)
library(forcats)

d <- data_2
d[,2:6] <- d[,2:6]/rowSums(d[,2:6])

mytitle <- "Satisfaction of Trump"
mylevels <- c("Great", "Good", "Average", "Poor",  "Terrible")

# Generate mid value of neutral category
numlevels <- length(d[1,])-1
numcenter <- ceiling(numlevels/2) + 1
d$midvalues <- d[,numcenter]/2
d_2<-cbind(d[,1],d[,2:ceiling(numlevels/2)], d$midvalues, d$midvalues,d[,numcenter:numlevels+1])
colnames(d_2)<-c("Sex",mylevels[1:floor(numlevels/2)],"Midlow",
  "Midhigh",mylevels[numcenter:numlevels])

# Split into six categories
numlevels<-length(mylevels)+1
point1<-2
point2<-((numlevels)/2)+1
point3<-point2+1
point4<-numlevels+1

# Assign color to each categories
numlevels<-length(d[1,])-1
temp.rows<-length(d_2[,1])
pal<-brewer.pal((numlevels-1),"RdBu")
pal[ceiling(numlevels/2)]<-"#DFDFDF"
legend.pal<-pal
pal<-c(pal[1:(ceiling(numlevels/2)-1)], pal[ceiling(numlevels/2)], 
       pal[ceiling(numlevels/2)], pal[(ceiling(numlevels/2)+1):(numlevels-1)])

# Generate new data frame including all information
d_3<-melt(d_2,id="Sex")
d_3$col<-rep(pal,each=temp.rows)
d_3$value<-d_3$value*100
d_3$Sex<-str_wrap(d_3$Sex, width = 40)
d_3$Sex<-factor(d_3$Sex, levels = d_2$Sex[order(-(d_2[,5]+d_2[,6]+d_2[,7]))])
highs<-na.omit(d_3[(length(d_3[,1])/2)+1:length(d_3[,1]),])
lows<-na.omit(d_3[1:(length(d_3[,1])/2),])

# Plot
ggplot() + geom_bar(data=highs, aes(x = Sex, y=value, fill=col), position="stack", stat="identity", width = 0.5) +
  geom_bar(data=lows, aes(x = Sex, y=-value, fill=fct_inorder(col)), position="stack", stat="identity", width = 0.5) +
  geom_hline(yintercept = 0, color =c("white")) +
  scale_fill_identity("Percent", labels = mylevels, breaks=legend.pal, guide="legend") + 
  theme_fivethirtyeight() + 
  coord_flip() +
  labs(title=mytitle, y="",x="") +
  theme(plot.title = element_text(size=14, hjust=0.5)) +
  theme(axis.text.y = element_text(hjust=0)) +
  theme(legend.position = "bottom") 

21.5 Theory

Likert data is a type of rating scale commonly used in surveys. It’s a bipolar data, representing the attitude to a statement. We can add neutral options to help candidate make choices when they are uncertain.

A typical Likert scale may look like

    1. Strongly disagree
    1. Disagree
    1. Agree
    1. Strongly agree

or

    1. Strongly disagree
    1. Disagree
    1. Neither agree or disagree
    1. Agree
    1. Strongly agree

The options of likert scale can avoid the distortion of the survey result which is likely to be too extreme.

21.6 When to use

When the data is from survey and is likert scale.

21.7 External resources