Gmichael
Gmichael

Reputation: 568

r likert graph editing

I am using the R package likert to make graphs according to a questionnaire. The graphs are basically just preference spectrums and look very much like this reprex (no original data, cannot be disclosed):

data("pisaitems")
title <- "How often do you read these materials because you want to?"
items29 <- pisaitems[,substr(names(pisaitems), 1,5) == 'ST25Q']
head(items29); ncol(items29)
names(items29) = c("Magazines", "Comic books", "Fiction", "Non-fiction books", "Newspapers")
l29 <- likert(items29)
str(l29)
l29s <- likert(summary = l29$results)
str(l29s)
scale_height = knitr::opts_chunk$get('fig.height')*0.5
scale_width = knitr::opts_chunk$get('fig.width')*1.25
knitr::opts_chunk$set(fig.height = scale_height, fig.width = scale_width)
theme_update(legend.text = element_text(size = rel(0.7)))
plot(l29s) + ggtitle(title)

So here are my problems:

  1. I am doing this analysis for a GERMAN company and I can't seem to get rid of the label "Percentage" in the graph?
  2. How do I change the ticks on the axis to 10% increments?
  3. How do I align the Item names with the left and center the title? How do I align the legend with the bottom left corner?

I have managed to get most of the graph settings to my preferences but these last 3 keep eluding me.

fyi: Example was generate from this site: https://rpubs.com/m_dev/likert_summary

Upvotes: 3

Views: 3703

Answers (1)

hplieninger
hplieninger

Reputation: 3504

The plot function from the likert package returns a ggplot object. You can update/override aspects of that object as usual. (You already did this once in your last line with + ggtitle().

Note further that the plot is rotated so that sometimes you need to refer to the y-axis, which---after rotation---is displayed as the x-axis.

I solved your first two questions and leave the third one as an exercise for you or for somebody else.

library(likert)
data(pisaitems)
title <- "How often do you read these materials because you want to?"
items29 <- pisaitems[, substr(names(pisaitems), 1,5) == 'ST25Q']
names(items29) <- c("Magazines", "Comic books", "Fiction", "Non-fiction books", "Newspapers")
l29 <- likert(items29)
l29s <- likert(summary = l29$results)

# Make axis tick labels left aligned with 'axis.text.y'
theme_update(legend.text = element_text(size = rel(0.7)),
             axis.text.y = element_text(hjust = 0))

# Override default label for axis with 'labs()'
# Override breaks of axis with 'continuous_scale()'
plot(l29s) + 
    labs(title = title, y = "Prozent") +
    scale_y_continuous(labels = likert:::abs_formatter, lim = c(-100, 100),
                       breaks = seq(-100, 100, 25))

Upvotes: 5

Related Questions