【问题标题】:Add percentage signs to horizontal scale in R likert plot在 R 李克特图中将百分比符号添加到水平刻度
【发布时间】:2019-12-24 12:27:38
【问题描述】:

我正在使用 R 中的 likert 包来绘制此图:

横轴上的标签不正确。绘制的是百分比。 如何在屏幕截图中指示的位置添加百分号?

library("likert")
library("scales")
d <- likert(d)
plot(d, col=myColor) +
  ggtitle("Mechanical Turk") +
  theme(text = element_text(size=20)) +
  # scale_x_discrete(labels=percent) +
  # scale_y_discrete(labels=percent) +
  # scale_y_discrete(breaks=c("A","B","C","D","E")) +
  # scale_y_discrete(labels=c("100" = "100%", "50" = "50%","0" = "0%")) +
  ylab("Percentage of all responses")

我尝试添加 scale_x_discrete(labels=percent) 但这给出了错误(“x * 比例错误:二进制运算符的非数字参数”)。 cmets 显示了我尝试过的其他内容。

【问题讨论】:

  • 你能试试scale_x_continuous(labels = scales::percent)吗?
  • 没关系,好​​像某处的坐标发生了翻转(因此你的ylab 给出了一个 x 标签)。试试scale_y_continuous(labels = scales::percent)

标签: r ggplot2 likert


【解决方案1】:

李克特图上有一个 coord_flip()(参见 likert.bar.plot)。试试下面的:

library(likert)
library(ggplot2)

data(pisaitems)
items29 <- pisaitems[,substr(names(pisaitems), 1,5) == 'ST25Q']
names(items29) <- c("Magazines", "Comic books", "Fiction", 
                        "Non-fiction books", "Newspapers")
l29 <- likert(items29)

plot(l29) + scale_y_continuous(labels=c("100%","50%","0%","50%","100%"),limits=c(-105,105))

【讨论】:

  • 谢谢!这应该作为默认值添加到 likert 包中。
猜你喜欢
  • 1970-01-01
  • 2016-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-09
  • 1970-01-01
相关资源
最近更新 更多