Search code examples
rlikert

Likert Graphs disappear when moving section labels to top instead of left?


I'm hoping to create a graph similar to this example, where each question has two groups under it using the two factors in the type column. My summary data is at the end of the post.

target graph

This code has gotten me pretty close to my goal. But the labels are on the left instead of over each section.

likert(type ~ . | Item, data = first_questions_data, layout = c(1,20),
       scales = list(y = list(relation = "free")), between = list(y = 1),
       strip.left = strip.custom(bg = "gray97"), strip = FALSE,
       par.strip.text = list(cex = 1.1, lines = 2), ylab = NULL, cex = 1.2,
       ReferenceZero = 3, as.percent = TRUE, positive.order = TRUE,
       main = "As a result of the Dobbs decision I spend more time...",
       xlim = c(-100, -80, -60, -40, -20, 0, 20, 40, 60, 80, 100), 
       resize.height.tuning = 1)

closest graph so far

I've changed strip.left to FALSE and strip to strip = strip.custom(bg = "gray97") and the label appears on top, but with no graphs. Shown below.

How do I move the titles to the top of each graph and still maintain space for the graphs themselves?

I've tried changing the values of between = list(y = 2) and resize.height.tuning = 1 but even if more space appears between the labels, the graphs still do not show up.

likert(type ~ . | Item, data = first_questions_data, layout = c(1,20),
+        scales = list(y = list(relation = "free")), between = list(y = 1),
+        strip.left = FALSE, strip = strip.custom(bg = "gray97"),
+        par.strip.text = list(cex = 1.1, lines = 2), ylab = NULL, cex = 1.2,
+        ReferenceZero = 3, as.percent = TRUE, positive.order = TRUE,
+        main = "As a result of the Dobbs decision I spend more time...",
+        xlim = c(-100, -80, -60, -40, -20, 0, 20, 40, 60, 80, 100), 
+        resize.height.tuning = 1)

enter image description here


Solution

  • (I can't reproduce your example, because you don't state which packages you are using nor all of the steps you took before plotting the graph. The call to likert fails with an "unused arguments" error. This means this answer is mostly guessing.)

    Are you sure they aren't plotted? R just tries to fit the plot to the size of the output device. That's why you get such a squashed plot in your first example. When you move the facet's panel's to the top, they take up the little space you had for the graphs themselves, so they get even more squashed, to the point of collapsing into a line.

    What happens if you resize the output window, to make it taller (or change the fig.height, if this is a chunk in a rmarkdown document, for example)?

    I suspect the layout = c(1, 20) is forcing the plot to reserve space for 20 plots, when you are plotting only 10 (that's why you only have plots on the upper half), which makes the problem worse. Try changing that 20 to 10 and see if things change. Again, without a MWE, one can only guess.