我正在使用 R 包 Likert 根据调查问卷制作图表。这些图表基本上只是偏好谱,看起来非常像这个表示(没有原始数据,不能透露):
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)
Run Code Online (Sandbox Code Playgroud)
所以这是我的问题:
我已经设法让大部分图表设置符合我的喜好,但最后 3 个设置一直让我困惑。
仅供参考:示例是从该站点生成的: https: //rpubs.com/m_dev/likert_summary
Likert 包中的绘图函数返回一个 ggplot 对象。您可以照常更新/覆盖该对象的各个方面。(您已经在最后一行中使用+ ggtitle().
进一步注意,绘图会旋转,因此有时您需要参考 y 轴,旋转后,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))
Run Code Online (Sandbox Code Playgroud)