R中的Likert图编辑

3

我正在使用R包likert根据问卷制作图表。这些图表基本上只是偏好谱,并且看起来非常像这个reprex(没有原始数据,无法公开):

data("pisaitems")
title <- "How often do you read these materials because you want to?"
items29 <- pisaitems[,substr(names(pisaitems), 1,5) == 'ST25Q']
head(items29); ncol(items29)
names(items29) = c("Magazines", "Comic books", "Fiction", "Non-fiction books", "Newspapers")
l29 <- likert(items29)
str(l29)
l29s <- likert(summary = l29$results)
str(l29s)
scale_height = knitr::opts_chunk$get('fig.height')*0.5
scale_width = knitr::opts_chunk$get('fig.width')*1.25
knitr::opts_chunk$set(fig.height = scale_height, fig.width = scale_width)
theme_update(legend.text = element_text(size = rel(0.7)))
plot(l29s) + ggtitle(title)

以下是我的问题:
  1. 我正在为一家德国公司进行分析,但似乎无法去掉图表中的“百分比”标签?
  2. 如何将轴上的刻度改为每次增加10%?
  3. 如何使项目名称左对齐并居中标题?如何将图例与左下角对齐?
我已经成功地设置了大部分图形参数,但这最后3个问题仍然困扰着我。
提示:示例源自此网站: https://rpubs.com/m_dev/likert_summary
1个回答

4

likert包中的plot函数返回一个ggplot对象。您可以像平常一样更新/覆盖该对象的方面。(在上一行中,您已经使用+ ggtitle()更新了一次)。

请注意,图表被旋转,因此有时需要参考y轴,在旋转后会显示为x轴。

我解决了您的前两个问题,并将第三个问题留作练习,由您或其他人完成。

library(likert)
data(pisaitems)
title <- "How often do you read these materials because you want to?"
items29 <- pisaitems[, substr(names(pisaitems), 1,5) == 'ST25Q']
names(items29) <- c("Magazines", "Comic books", "Fiction", "Non-fiction books", "Newspapers")
l29 <- likert(items29)
l29s <- likert(summary = l29$results)

# Make axis tick labels left aligned with 'axis.text.y'
theme_update(legend.text = element_text(size = rel(0.7)),
             axis.text.y = element_text(hjust = 0))

# Override default label for axis with 'labs()'
# Override breaks of axis with 'continuous_scale()'
plot(l29s) + 
    labs(title = title, y = "Prozent") +
    scale_y_continuous(labels = likert:::abs_formatter, lim = c(-100, 100),
                       breaks = seq(-100, 100, 25))

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接