我正在使用 likert() 來生成調查資料圖。這些圖是百分比水平的裁剪顯示,如下所示:

對于同一資料集中的其他類似圖,這或多/少嚴重(所以這里只是百分比符號,但在其他情況下會剪輯成數字) - 我想知道是否有人對如何調整這個位有一個好主意的李克特顯示,以便標簽在繪圖網格內。
# data for reproducible example:
q25_data <- structure(list(Q25_self_and_family = c(4, 2, 3, 5, 3, 3, 4, 2,
4, 2, 4, 4, 3, 3, 2, 5, 3, 4, 1, 3, 3, 2, 4, 2, 2, 2, 4, 3, 3,
3, 2, 5, 5, 4, 2, 2, 2, 3, 1, 3, 2, 1, 2, 4, 2), Q25_local_area = c(3,
3, 3, 5, 3, 2, 4, 2, 4, 2, 4, 3, 2, 3, 2, 5, 4, 5, 1, 4, 3, 3,
4, 2, 3, 2, 3, 3, 2, 3, 2, 5, 5, 2, 2, 2, 2, 3, 1, 1, 2, 1, 2,
4, 3), Q25_uk = c(4, 3, 3, 5, 2, 3, 5, 2, 4, 2, 4, 3, 3, 3, 3,
5, 4, 5, 2, 3, 3, 2, 4, 2, 4, 3, 4, 3, 2, 4, 4, 5, 5, 4, 3, 3,
2, 4, 2, 5, 2, 2, 2, 3, 3), Q25_outside_uk = c(4, 4, 3, 5, 4,
4, 5, 2, 4, 3, 3, 3, 3, 4, 3, 5, 4, 5, 4, 3, 3, 2, 4, 2, 5, 3,
3, 2, 2, 3, 4, 4, 5, 4, 4, 3, 2, 4, 4, 5, 2, 3, 2, 2, 2)), row.names = c(NA,
-45L), class = c("tbl_df", "tbl", "data.frame"))
# libraries:
library(tidyverse)
library(likert)
# here goes!
title <- "How serious a threat do you think \nclimate change poses to the following?"
names(q25_data) <- c("You and your family in the UK", "People in your local area or city", "The UK as a whole", "Your family and/or friends living outside the UK")
# Set up levels text for question responses
q25_levels <- paste(c("not at all", "somewhat", "moderately", "very", "extremely"),
"serious")
q25_likert_table <- q25_data %>%
mutate(across(everything(),
factor, ordered = TRUE, levels = 1:5, labels=q25_levels)) %>%
as.data.frame %>%
likert
plot(q25_likert_table, wrap=20, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048')
ggtitle(title)
labs(title = title, y="")
guides(fill = guide_legend(title = NULL))
theme_ipsum_rc()
theme(axis.text.y = element_text(size = 9))
uj5u.com熱心網友回復:
使用開箱即用的選項時,這始終是個麻煩。(:
每個 ggplot 的兩個快速選項是擴展limits或 增加比例的擴展(通過 eg expand = c(.1, 0))為標簽騰出更多空間。
請注意,在引擎蓋下likert使用,因此相關比例為. 默認情況下,限制設定為 -105 到 105,我增加到 -110 到 110。此外,對于標簽,使用olute 值。coord_flipscale_y_continuousabs
p <- plot(q25_likert_table, wrap = 20, text.size = 3, ordered = TRUE, low.color = "#B18839", high.color = "#590048")
ggtitle(title)
labs(title = title, y = "")
guides(fill = guide_legend(title = NULL))
theme_ipsum_rc()
theme(axis.text.y = element_text(size = 9))
p
scale_y_continuous(labels = abs, limits = c(-110, 110))
#> Scale for 'y' is already present. Adding another scale for 'y', which will
#> replace the existing scale.

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/444772.html
上一篇:Numpy:如何重新排序陣列的行以匹配另一個陣列的行?
下一篇:CDO4.17和Java11
