我正在使用 R 中的 Likert 包创建一个 Likert 图。一个变量(在下面的代表中使用)是一个只有正响应的有序因子。该条形图不以 y 轴为中心(即从上到下),而是显示在图的底部。我想创建一个以 y 轴水平居中的条形图。
注意我指的是以 y 轴(即上下)为中心,而不是 x 轴(左右)。我知道中性类别以 x 轴为中心,右侧为正值,左侧为负值。
下图说明了条形图如何未在 y 轴上居中对齐。
下图说明了当我包含“负”响应水平时,条形图如何在 y 轴上居中对齐。
最后的情节进一步说明了这个问题。蓝线表示 y 轴上的水平中心线,条形图位于该线下方,而不是以其为中心。黄色突出显示表示相应的意外大量空白。
# Load likert
library(likert)
# Create a data frame
ben_DF <- data.frame(Farm = factor(c("Small increase in crop farmland",
"Small increase in crop farmland",
"Small increase in crop farmland",
"Large increase in crop farmland",
"Small increase in crop farmland",
"Large increase in crop farmland",
"Small increase in crop farmland",
"Small increase in crop farmland"),
levels = c("Large decrease in crop farmland",
"Small decrease in crop farmland",
"No change in crop farmland",
"Small increase in crop farmland",
"Large increase in crop farmland"),
ordered = TRUE))
# Plot Likert
plot(likert(ben_DF)) +
theme(legend.position = "right",
legend.direction = "vertical")
按照@jay.sf的建议,“解决方案”是使用不同的包(特别是来自ggstats的gglikert)。为了完整起见,提供如下。
# Load packages
library(ggstats)
library(labelled)
# Create a data frame
ben_DF <- data.frame(Farm = factor(c("Small increase in crop farmland",
"Small increase in crop farmland",
"Large increase in crop farmland",
"Small increase in crop farmland",
"Large increase in crop farmland",
"Small increase in crop farmland",
"Small increase in crop farmland"),
levels = c("Large decrease in crop farmland",
"Small decrease in crop farmland",
"No change in crop farmland",
"Small increase in crop farmland",
"Large increase in crop farmland"),
ordered = TRUE))
# Plot Likert
ben_DF <- tibble(ben_DF)
colnames(ben_DF) <- "q1"
gglikert(ben_DF, variable_labels = c(q1 = "Farm")) +
theme(legend.position = "right",
legend.direction = "vertical")+
scale_x_continuous(limits = c(-1.1, 1.1), labels = scales::percent_format(accuracy = 1))