【问题标题】:Likert package barplot is adding some groups to the plot twice, how can I remove them -- what am I doing wrong?Likert 包 barplot 两次向图中添加了一些组,我该如何删除它们——我做错了什么?
【发布时间】:2022-01-07 12:10:48
【问题描述】:

我正在尝试绘制以下李克特项目:

    structure(list(`Likelihood of attending more frequently` = structure(c(4L, 
4L, 4L, 3L, 4L, 4L, 3L, 4L, 5L, 4L, 4L, 4L, 4L, 5L, 3L, 5L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 1L, 4L, 5L, 4L, 3L, 2L, 3L, 
3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 5L, 4L, 4L, 4L, 3L, 
4L, 5L, 3L, 3L, 2L, 4L, 4L, 3L, 4L, 1L, 3L, 3L, 4L, 5L, 4L, 4L, 
4L, 4L, 4L, 3L, 4L, 4L, 5L, 4L, 2L, 5L, 3L, 2L, 3L, 3L, 5L, 4L, 
4L, 2L, 3L, 2L, 4L, 5L, 3L, 4L, 4L, 4L, 4L, 5L, 4L, 4L, 3L, 4L, 
4L, 4L, 5L, 3L, 3L, 4L, 3L, 4L, 3L, 3L, 5L, 5L, 4L, 4L, 5L, 2L, 
1L, 4L, 4L, 4L, 1L, 4L, 3L, 2L, 4L, 4L, 4L, 4L, 5L, 4L, 5L, 4L, 
5L, 4L, 2L, 5L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 3L, 
3L, 4L, 4L, 4L, 5L, 5L, 4L, 5L, 5L, 3L, 2L, 4L, 5L, 5L, 1L, 5L, 
2L, 1L, 5L, 4L, 1L, 4L, 5L, 4L, 2L, 4L, 4L, 4L, 5L, 3L, 2L, 5L, 
5L, 5L, 4L), .Label = c("Highly unlikely", "Somewhat unlikely", 
"Neither likely nor unlikely", "Somewhat likely", "Highly likely"
), class = "factor"), Reason = structure(c(1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 7L, 7L, 7L, 7L, 7L, 7L, 
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L), .Label = c("Class times conflict with my schedule", 
"I am not interested in the content offered", "I don't have time", 
"I don't have transportation", "I don't know where to find information on classes, programs, and events", 
"Other", "There are not classes near me"), class = "factor")), row.names = c(NA, 
-180L), class = "data.frame")

当我检查组项目的因子水平时,它显示 7 ,但是,likert.bar.plot 有 9 个组,因为 2 个重复。

like<-likert(freq[, c(1), drop=FALSE], grouping = freq$Reason)
likert.bar.plot(like,wrap.grouping = 40)

我检查了文本字符串是否不同,但它们完全相同。 知道是什么原因造成的吗?

【问题讨论】:

  • 不幸的是,您提供的示例数据无法重现您的问题。但是,从您发布的图像来看,您的重复组实际上是不同的,即看起来好像某些 obs 的标签。包括换行符。因此,这些组被视为不同的类别。
  • 如果有帮助,我可以包含整个数据集,但是当我使用 wrap.grouping 时会创建中断
  • @stefan 我已经包含了整个 df。出于某种奇怪的原因,wrap.grouping 仅适用于非重复组。
  • 嗯。奇怪的。这对我来说似乎是一个错误。我仔细查看了绘图代码。据我所知,问题在于,对于条形,使用了未包装的组标签,而对于百分比标签,则使用了包装的标签。因此,我们最终得到了重复的组。
  • 有意思,我会在github上发布问题。看起来@jbryer 在响应错误方面做得很好。感谢您帮助确定问题,即使我们无法解决。

标签: ggplot2 axis-labels likert


【解决方案1】:

正如我在评论中已经提到的,这对我来说似乎是一个错误。从likert.bar.plot 的源代码和图像来看,似乎使用了未包装的组标签,而使用了包装的百分比标签。因此,我们最终得到了重复的组。

但是,作为一种解决方法,您可以在传递给 likert 之前手动包装组标签。要完成这项工作,您还必须为 wrap.grouping 参数设置相同的宽度:

library(likert)

levels(freq$Reason) <- stringr::str_wrap(levels(freq$Reason), width = 40)
like <- likert(freq[, 1, drop = FALSE], grouping = freq$Reason)
likert.bar.plot(like, wrap.grouping = 40)

【讨论】:

  • 这绝对有效,这也是我试图对轴 lebel 做的事情。您的解决方法将非常有用。已填写错误报告。
猜你喜欢
  • 2023-03-21
  • 1970-01-01
  • 2013-10-20
  • 2011-11-06
  • 2011-08-17
  • 2011-06-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多