<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/visualisation-of-likert-scale-results/"></div></div><div><a data-url="https://www.r-bloggers.com/visualisation-of-likert-scale-results/" data-counturl="https://www.r-bloggers.com/visualisation-of-likert-scale-results/" data-count="horizontal" data-text="Visualisation of Likert scale results" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://rcrastinate.blogspot.com/2016/07/visualisation-of-likert-scale-results.html"> Rcrastinate</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>I wrote a function to visualise results of Likert scale items. Please find the function below the post. Here is an example plot:
<div><a target="_blank" href="https://i0.wp.com/4.bp.blogspot.com/-tM8cBPfH-MY/V5sX0cCE49I/AAAAAAAACvc/eTWZD_XDTRMbgdiesNA4NIqUKP1nJ0lPgCLcB/s1600/test.png?ssl=1"><img src="https://i0.wp.com/4.bp.blogspot.com/-tM8cBPfH-MY/V5sX0cCE49I/AAAAAAAACvc/eTWZD_XDTRMbgdiesNA4NIqUKP1nJ0lPgCLcB/s640/test.png?resize=456%2C137&ssl=1" border="0" data-recalc-dims="1"></a></div>
<div>The function is called ‘plot.likert’ and takes the following arguments:</div>
<div>– vec: The vector with the raw results</div>
<div>– possible.values: A vector with all the possible values. This is sometimes important if not all possible responses were actually ticked by your participants. Defaults to all values found in vec.</div>
<div>– left: Annotation for the left side of the plot</div>
<div>– right: Annotation for the right side of the plot</div>
<div>– plot.median: Plot the median as a little line at the top? Defaults to FALSE.</div>
<div>– plot.sd: Plot the standard deviation around the mean? Defaults to TRUE.</div>
<div>– include.absolutes: Include the absolute values as small bold black numbers above the plot? Defaults to TRUE.</div>
<div>– include.percentages: Include the percentage values as blue numbers above the plot? Defaults to TRUE.</div>
<div>– own.margins: Override the default margins for the plot. Defaults to c(2,2,3,2).</div>
<div>– othermean: Plot another mean into the visualisation as grey line above the bars. I used this to compare the results to older results for the same questions. Defaults to NULL (no other mean is plotted in this case).</div>
<div>– …: Other parameters might be passed that are used for the first call to plot().</div>
<div></div>
<div>The example call for the plot shown above is:</div>
<div><span>plot.likert(sample(-2:2, 75, replace = T,</span></div>
<div><span>                   prob = c(0, .2, .2, .3, .3)),</span></div>
<div><span>            left = “strongly disagree”,</span></div>
<div><span>            right = “strongly agree”,</span></div>
<div><span>            own.margins = c(2,2,5,2),</span></div>
<div><span>            main = “I like this visualisation of Likert scale</span></div>
<div><span>                    results.”,</span></div>
<div><span>            possible.values = -2:2,</span></div>
<div><span>            othermean = 1.09</span><span>)</span></div>
<div><span><br></span></div>
<div><span>NB: I know of all the stuff regarding the calculation of means on Likert scale items. However, it is still done a lot and you can also include the median after all…</span></div>
<div><span><br></span></div>
<div><span>Here’s the function:</span></div>
<div><span><br></span></div>
<div><span>plot.likert &lt;- function (vec, possible.values = sort(unique(vec)), left = “linker Pol”, right = “rechter Pol”,</span></div>
<div><span>                         plot.median = F, plot.sd = T, include.absolutes = T, include.percentages = T, own.margins = c(2, 2, 3, 2),</span></div>
<div><span>                         othermean = NULL, …) {</span></div>
<div><span>  tab &lt;- table(vec)</span></div>
<div><span>  if (length(tab) != length(possible.values)) {</span></div>
<div><span>    values.not.in.tab &lt;- possible.values[!(possible.values %in% names(tab))]</span></div>
<div><span>    for (val in values.not.in.tab) {</span></div>
<div><span>      tab[as.character(val)] &lt;- 0</span></div>
<div><span>    }</span></div>
<div><span>    tab &lt;- tab[sort(names(tab))]</span></div>
<div><span>  }</span></div>
<div><span>  prop.tab &lt;- prop.table(tab) * 100</span></div>
<div><span>  v.sd &lt;- sd(vec, na.rm = T)</span></div>
<div><span>  v.m &lt;- mean(vec, na.rm = T)</span></div>
<div><span>  v.med &lt;- median(vec, na.rm = T)</span></div>
<div><span>  old.mar &lt;- par(“mar”)</span></div>
<div><span>  par(mar = own.margins)</span></div>
<div><span>  # Setting-up plot region</span></div>
<div><span>  plot(x = c(min(as.numeric(names(tab)), na.rm = T) – 1.1, max(as.numeric(names(tab)), na.rm = T) + 1.1),</span></div>
<div><span>       y = c(0, 100), type = “n”, xaxt = “n”, yaxt = “n”,</span></div>
<div><span>       xlab = “”, ylab = “”, bty = “n”, …)</span></div>
<div><span>  # Bars</span></div>
<div><span>  rect(xleft = as.numeric(names(prop.tab)) – .4,</span></div>
<div><span>       ybottom = 0,</span></div>
<div><span>       xright = as.numeric(names(prop.tab)) + .4,</span></div>
<div><span>       ytop = prop.tab,</span></div>
<div><span>       border = “#00000000”, col = “#ADD8E6E6”)</span></div>
<div><span>  # Lower black line</span></div>
<div><span>  lines(x = c(min(as.numeric(names(tab)), na.rm = T) – .6, max(as.numeric(names(tab)), na.rm = T) + .6),</span></div>
<div><span>        y = c(0, 0), col = “black”, lwd = 2)</span></div>
<div><span>  # Upper black line</span></div>
<div><span>  lines(x = c(min(as.numeric(names(tab)), na.rm = T) – .6, max(as.numeric(names(tab)), na.rm = T) + .6),</span></div>
<div><span>        y = c(100, 100), col = “black”, lwd = 2)</span></div>
<div><span>  # Blue lines</span></div>
<div><span>  for (n.i in names(tab)) {</span></div>
<div><span>    lines(x = c(n.i, n.i), y = c(0, 100), col = “blue”)</span></div>
<div><span>  }</span></div>
<div><span>  # Grey rectangles at sides</span></div>
<div><span>  rect(xleft = min(as.numeric(names(tab)), na.rm = T) – 1.1,</span></div>
<div><span>       ybottom = 0,</span></div>
<div><span>       xright = min(as.numeric(names(tab)), na.rm = T) – .6,</span></div>
<div><span>       ytop = 100,</span></div>
<div><span>       border = “#00000000”, col = “grey”)</span></div>
<div><span>  rect(xleft = max(as.numeric(names(tab)), na.rm = T) + .6,</span></div>
<div><span>       ybottom = 0,</span></div>
<div><span>       xright = max(as.numeric(names(tab)), na.rm = T) + 1.1,</span></div>
<div><span>       ytop = 100,</span></div>
<div><span>       border = “#00000000”, col = “grey”)</span></div>
<div><span>  mtext(names(prop.tab), side = 1, at = names(prop.tab))</span></div>
<div><span>  # Percentages and numbers at the top</span></div>
<div><span>  if (include.percentages) mtext(paste(round(prop.tab, 0), “%”), side = 3, at = names(prop.tab), line = -.3, col = “blue”)</span></div>
<div><span>  if (include.absolutes) mtext(tab, side = 3, at = names(tab), line = .5, cex = .8, font = 2)</span></div>
<div><span>  # Mean line</span></div>
<div><span>  lines(x = c(v.m, v.m), y = c(95, 85), lwd = 6, col = “blue”)</span></div>
<div><span>  # Median line</span></div>
<div><span>  if (plot.median) lines(x = c(v.med, v.med), y = c(95, 85), lwd = 4, col = “#00FF00AA”)</span></div>
<div><span>  # Other mean line</span></div>
<div><span>  if (!is.null(othermean)) lines(x = c(othermean, othermean), y = c(85, 75), lwd = 6, col = “#00000099”)</span></div>
<div><span>  # SD lines</span></div>
<div><span>  if (plot.sd) { arrows(x0 = c(v.m, v.m), x1 = c(v.m – v.sd, v.m + v.sd), y0 = c(90, 90), y1 = c(90, 90),</span></div>
<div><span>                        angle = 90, length = 0, lwd = 1) }</span></div>
<div><span>  # Left label</span></div>
<div><span>  mtext(left, side = 2, line = -.5)</span></div>
<div><span>  # Right label</span></div>
<div><span>  mtext(right, side = 4, line = -.5)</span></div>
<div><span>  par(mar = old.mar)</span></div>
<div></div>
<div><span>}</span></div>
<div></div>
<p></p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/visualisation-of-likert-scale-results/"></div></div><div><a data-url="https://www.r-bloggers.com/visualisation-of-likert-scale-results/" data-counturl="https://www.r-bloggers.com/visualisation-of-likert-scale-results/" data-count="vertical" data-text="Visualisation of Likert scale results" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://rcrastinate.blogspot.com/2016/07/visualisation-of-likert-scale-results.html"> Rcrastinate</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/Rf0KMF0ZpvU"></a></div>