ggplot2标签超出了李克特标度 [英] ggplot2 label out of the graph in likert scale

查看:309
本文介绍了ggplot2标签超出了李克特标度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由jason.bryer所使用的Likert包构成的Likert标度的ggplot(请参阅).如果您使用原始数据运行代码 此处,然后我的极值标签(在最右边)不在不再显示图形(请参见下图).我该如何解决?

I have a ggplot made of a likert-scale using the package likert by jason.bryer (see). If you run the code with the original data here, then my extrem label (in the far right) is not in the graph anymore (see picture below). How can I fix it?

我使用的代码:

library(ggplot2)
library(likert)
library(gridExtra)
competence_bachelor <- rawdata[, substr(names(rawdata), 1, 4) == "Q002"]
competence_bachelor <- rename(competence_bachelor, c(Q002_01 = "Ability to propose new ideas and new solutions", Q002_02 = "Ability to present in public", Q002_03 = "Ability to use a computer", Q002_04 = "Ability to use the Internet", Q002_05 = "Ability to use statistical programs", Q002_06 = "Ability to write reports", Q002_07 = "Knowledge of economic concepts", Q002_08 = "Knowledge of legal concepts", Q002_09 = "Ability to understand the other's point of view", Q002_10 = "Ability to rapidly acquire new knowledge", Q002_11 = "Ability to team work", Q002_12 = "Ability to do analysis with quantitative methods", Q002_13 = "Ability to do analysis with qualitative methods", Q002_14 = "Knowledge of English", Q002_15 = "Knowledge of another foreign language"))
i <- 1
while(i<=ncol(competence_bachelor)) {
  competence_bachelor[[i]] = factor(competence_bachelor[[i]],labels = c("insignificant", "2", "3", "4", "5", "6", "7", "8", "9", "very relevant"), levels=c(1:10))
  i <- i + 1
}
competence_bachelor_plot <- likert(competence_bachelor)
p <- plot(competence_bachelor_plot, centered = FALSE, include.histogram = FALSE) + ggtitle("How do you rate your skills gained with the Bachelor's?*") + theme(axis.text.y = element_text(colour = "black"), axis.text.x = element_text(colour = "black"))
g <- arrangeGrob(p, sub = textGrob("*Order of questions was randomized and only extremes labeled in online questionaire.", x = 0, hjust = -0.1, vjust=0.1, gp = gpar(fontface = "italic", fontsize = 10)))
print(p)
ggsave((filename="competence_bachelor.pdf"), scale = 1, width = par("din")[1], height = par("din")[2], units = c("in", "cm", "mm"), dpi = 300, limitsize = TRUE, g)

推荐答案

因此,首先,虽然图例的最右边的元素未显示,但它们确实在pdf中呈现.

So first of all, while the far right elements of the legend do not display, they do render properly in the pdf.

问题在于,图例太长了,因此会被剪切掉.当然,一种选择是仅增大显示窗口.另一个是使图例变小.您可以通过在p的定义末尾添加一行来实现这一点:

The problem is that the legend is just too long, so it gets clipped. One option of course is to just make the display window larger. Another is to make the legend smaller. You can do that by adding one line to the end of the definition of p:

p <- plot(competence_bachelor_plot, centered = FALSE, include.histogram = FALSE) + 
  ggtitle("How do you rate your skills gained with the Bachelor's?*") + 
  theme(axis.text.y = element_text(colour = "black"), axis.text.x = element_text(colour = "black"))+
  theme(legend.key.size=unit(.01,"npc"))

您也可以删除名称("Response"),因为它是多余的并且会干扰对称性.这也可以使图例本身变大.

You can also remove the name ("Response"), since it's redundant and disturbs the symmetry. This also allows you to make the legend itself larger.

p <- plot(competence_bachelor_plot, centered = FALSE, include.histogram = FALSE) + 
  ggtitle("How do you rate your skills gained with the Bachelor's?*") + 
  theme(axis.text.y = element_text(colour = "black"), axis.text.x = element_text(colour = "black"))+
  theme(legend.key.size=unit(0.02,"npc"))+guides(fill=guide_legend(""))

这篇关于ggplot2标签超出了李克特标度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆