使用 ggplot2 在 R 中的 Likert 图表中注释文本

问题描述 投票:0回答:1

我正在使用 R 中的 Likert 包中找到的 PISA 项目数据集。我已将数据图表分为两个区域:“警告”区域”和“无警告区域”。“警告”区域”从 95% 到 100 % 所以我想将文本“警告”区域”以红色放在图中左侧(不是右侧)的最后一个栏中,但水平方向和垂直方向上的文本“无警告区域”从 0% 到其余部分96% 也在左边。

如何使用 ggplot2 在 R 中执行此操作?


library(tidyverse)
library(likert)

data(pisaitems) 

items28 <- pisaitems[, substr(names(pisaitems), 1, 5) == "ST24Q"] 
dim(items28)
items28[items28 == "Agree"] <- "Disagree"
colnames(items28)

df= items28[1:50,]


anno =
 partial(
   annotate,
   "text",
   x = 0,
   angle = 90,
   size = 3,
   fontface = "bold"
 )
p =  likert::likert.bar.plot(df)+geom_vline(
 xintercept = c(1.5),
 linetype = "dashed",
 colour = "grey20"
) 


r ggplot2 likert
1个回答
0
投票

您需要先使用

likert
功能。

l <- likert(df)

p <- likert::likert.bar.plot(l) + geom_vline(
  xintercept = c(1.5),
  linetype = "dashed",
  colour = "grey20"
) 

p +
  annotate("text", y=-80, x=1, label="Warning Zone", col="red") +
  annotate("text", y=-80, x=6, label="No Warning Zone", col="red", angle = 90)  

© www.soinside.com 2019 - 2024. All rights reserved.