我已经看过这个问题了,它向我展示了如何将百分比标签添加到图中( 显示百分比值的李克特图)。
但是,我似乎无法让它与多面板图一起使用。
library(HH)
#my hacky approach to add some custom labels
my_panel_func <- function (...) {
#panel.likert(...) #If commented out returns no bars, if uncommented only returns two bars rather than 5
DF <- data.frame(correctX = rep(c(-50, 0, 75), each = 5),
abs = rep(c(-50, 0, 75), each = 5),
perc = c(c(4.1, 2.9, 5, 3.2, 5.9),
c(35.6, 15.6, 47.2, 28.2, 47.9),
c(60.3, 81.5, 47.9, 68.7, 46.2)),
y = rep(5:1, times = 3))
panel.text(x = DF$correctX,
y = DF$y,
label = paste0(DF$perc,'%'), cex=0.7)
}
但是,我正在处理一个包含多个面板的图,请参见此处。
我很确定我需要以panel.likert
某种方式编辑该位。
#示例数据
example_data <- data.frame(c(51232212, 31321, 3124, 3132, 3212), c(93123, 3123, 1232316, 1239, 1230), c(3723132, 12314577, 2231320, 26232131, 113211
), c(43235, 211236, 23119, 321365, 72130), c(13255, 63120, 9513, 111, 4413), c(3029,
101320, 212309, 161230, 113249), c(271322, 2163, 209132, 1200, 173122), type = c("All/nSurvey Responses",
"A", "A", "S", "S"), attribute = c("", "B",
"B", "C", "C"))
HH::likert(
attribute ~ . | type,
as.percent = TRUE,
ReferenceZero = 4,
between = list(y = 0),
data = example_data,
layout = c(1, 3),
h.resizePanels = c(1, 2, 2),
panel = my_panel_func)