r 李克特图编辑

r likert graph editing

我正在使用 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. 我正在为一家德国公司做这项分析,我似乎无法摆脱图表中的标签 "Percentage"?
  2. 如何将轴上的刻度更改为 10% 的增量?
  3. 如何将项目名称左对齐并使标题居中?如何将图例与左下角对齐?

我已经设法让大部分图表设置符合我的喜好,但最后这 3 个一直让我望而却步。

fyi:示例是从此站点生成的: https://rpubs.com/m_dev/likert_summary

likert 包中的 plot 函数 returns 一个 ggplot 对象。您可以像往常一样 update/override 该对象的各个方面。 (您已经在 + 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))