使用R likert包绘制问卷图谱的四类格式调整技术问询
针对Likert偏好光谱图的格式调整方案
咱们一个个搞定这些格式问题,直接给你可复用的代码调整方案,结合你现有的分析流程:
- 移除“Percentage”标签:在绘图代码里添加
theme(axis.title.x = element_blank()),直接去掉x轴的默认标签 - 设置坐标轴刻度为10%增量:用
scale_x_continuous(breaks = seq(-100, 100, 10))指定x轴刻度间隔,刚好对应10%的增量 - 项目名称左对齐+标题居中:项目名称(y轴文本)左对齐用
theme(axis.text.y = element_text(hjust = 0));标题居中通过theme(plot.title = element_text(hjust = 0.5))实现,和ggtitle配合使用 - 图例对齐至左下角:用
theme(legend.position = c(0, 0), legend.justification = c(0, 0)),把图例固定在绘图区域的左下角位置
修改后的完整代码
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) + # 移除Percentage标签 theme(axis.title.x = element_blank()) + # 设置10%增量的坐标轴刻度 scale_x_continuous(breaks = seq(-100, 100, 10)) + # 项目名称左对齐 + 标题居中 theme(axis.text.y = element_text(hjust = 0), plot.title = element_text(hjust = 0.5)) + # 图例对齐左下角 theme(legend.position = c(0, 0), legend.justification = c(0, 0))
内容的提问来源于stack exchange,提问作者Gmichael
相关产品推荐
相关产品推荐

