licorice is an R package that eases the plotting of Likert-like
data. It has been heavily inspired by the
package from Bryer and
licorice makes use of the
ggplot2 plotting engine in such a way that
interference by the
licorice package in terms of theming is kept to a
minimum (the graphs diplayed belowed are themed using the
package). When using the
licorice function a
ggplot2 object is
returned which can then be added upon to your liking.
For now, no CRAN version exists and you'll have to install from GitHub
licorice function expects a given structure of data. The example
pisatest dataset can be used as a reference.
A minimal requirement is the presence of the
count column. Additionally a
group column can be added.
library(licorice) ## Warning: replacing previous import by 'tidyr::%>%' when loading 'licorice' head(pisatest) ## question response group count ## 1 ST24Q01 Agree Canada 5623 ## 2 ST24Q01 Agree Mexico 12622 ## 3 ST24Q01 Agree United States 1755 ## 4 ST24Q01 Disagree Canada 7938 ## 5 ST24Q01 Disagree Mexico 13872 ## 6 ST24Q01 Disagree United States 1705
For example the
gapsample dataset is not structured as it should be.
Some simple preparations make it suited for
head(gapsample) ## StudentId question response ## 1 1 Financial Aid Agree ## 2 2 Financial Aid Strongly disagree ## 3 3 Financial Aid Agree somewhat ## 4 4 Financial Aid Strongly agree ## 5 5 Financial Aid Strongly agree ## 6 6 Financial Aid Agree library(dplyr) gap_fixed<- gapsample %>% group_by(question, response) %>% summarise(count = n()) head(gap_fixed) ## Source: local data frame [6 x 3] ## Groups: question  ## ## question response count ## (fctr) (fctr) (int) ## 1 Financial Aid Strongly disagree 7 ## 2 Financial Aid Disagree 3 ## 3 Financial Aid Disagree somewhat 2 ## 4 Financial Aid Undecided 3 ## 5 Financial Aid Agree somewhat 9 ## 6 Financial Aid Agree 7
Three main plots are available. First a centered plot is shown; here the
junction between two categories (which can be controlled by the
middle_pos parameter) is centered. If the factor levels of the reponse
variable are not set correctly, they can be specified using the
answer_order parameter. If a
middle_pos value of e.g. 2 is given,
the results are centered at the junction between the second and third
my_order<- c("Strongly disagree","Disagree", "Agree", "Strongly agree") licorice(pisatest, answers_order = my_order, middle_pos = 2, type = "center", sort=T)
One can also fill the vertical space using a filled plot (also notice
licorice(pisatest, answers_order = my_order, type = "fill", sort=TRUE)
We can also have a look at the count data.
licorice(pisatest, answers_order = my_order, type = "count")
You can also show plots in combination with each other using existing
library(gridExtra) grid.arrange( licorice(pisatest, my_order, middle_pos = 2.5, type = "center", sort=TRUE), licorice(pisatest, my_order, type = "count", sort=TRUE) + theme(axis.text.y=element_blank()) + scale_fill_discrete(""), ncol = 2, widths = c(3/4,1/4) )
Groups (as the countries in the graph above) are shown automatically
group column is available in the data set. For example, when
using the generated
gap_fixed data set (where not
group column is
present), no group is shown;
levels(gap_fixed$response) ##  "Strongly disagree" "Disagree" "Disagree somewhat" ##  "Undecided" "Agree somewhat" "Agree" ##  "Strongly agree" licorice(gap_fixed, middle_pos = 4, sort=TRUE) + theme(legend.position="right")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.