I am using the gglikert() function from the ggstats package to create horizontal stacked bar charts centered on the neutral response. I would like to know how to manually set the x-axis limits to 100% on either side of 0%. Here is an example dataframe and code:
example_data <- data.frame(
Pre = as.factor(c("Somewhat Familiar","Unfamiliar","Somewhat Familiar",
"Somewhat Unfamiliar","Somewhat Familiar","Unfamiliar",
"Neither Unfamiliar or Familiar","Unfamiliar",
"Neither Unfamiliar or Familiar","Unfamiliar")),
Post = as.factor(c("Very Familiar",
"Very Familiar","Somewhat Familiar",
"Very Familiar","Very Familiar","Very Familiar",
"Very Familiar","Somewhat Familiar","Very Familiar",
"Somewhat Familiar"))
)
gglikert(example_data,
add_totals = FALSE)
enter image description here
Here, you can see that the function has set the axis limits based on the percentages within each of the groups. I would like the x-axis to go to 100% (as there are other questions with different data distributions and I would like all the axes to be the same, though the answers are slightly different, so I can’t facet them).
I have looked at the documentation for gglikert() and searched Google/Stack overflow, and I do not see an option for the axis limits.
I’ve tried setting the limits with typical ggplot2 approaches (e.g., xlim(0, 100) or xlim (-100, 100), but because the x-axis isn’t on a typical sequential scale like from -100 to 100, these approaches haven’t worked.
I’ve opted for this approach rather than the likert package as it has better functionality for the downstream formatting I want to apply (more control over faceting, facet labels, and bar labels), so would prefer solutions that use gglikert().