如何更改R包中的所有不同文本的文本字体,大小和颜色? [英] How do I change the text font, size and colour of all the different texts in the R package, Likert?

查看:1301
本文介绍了如何更改R包中的所有不同文本的文本字体,大小和颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,只有一些功能可以改变百分比的字体,但我想更改Likert包条形图中所有文本的字体,大小和颜色。

At the moment, there is only features in place to change the font of the percentages, but I would like to change the font, size and colour of all text in the Likert package's bar plot. How would I go about doing this?

推荐答案

你几乎可以做任何 ggplot :通过添加 theme()选项。

You do it pretty much how you would any ggplot: by adding theme() options. (At least, how you'd fine-tune things anyway.)

使用的示例数据?likert

library("likert")
data(pisaitems)
items29 <- pisaitems[,substr(names(pisaitems), 1,5) == 'ST25Q']
names(items29) <- c("Magazines", "Comic books", "Fiction",
                    "Non-fiction books", "Newspapers")
l29 <- likert(items29)
summary(l29)

p1 <- plot(l29) # assign the plot to an object

# modify some stuff
p1 + theme(text = element_text(size = rel(6), colour = "red"),
           axis.text.y = element_text(colour = "blue",
                                      family = "Courier"))

可以看看主题调用的返回,例如 theme_bw()查看所有可以修改的方法。在 plot.likert 代码中设置的任何东西(例如y轴文本颜色)都需要显式修改,它不会继承更一般的 text 。如果大部分是要修改的文本,?element_text 可能会有帮助。

In general, you can look at the return of a theme call, e.g. theme_bw() to see all the things that can be modified this way. Anything that is set in the plot.likert code will (e.g. the y axis text colour) will need to be explicitly modified, it won't inherit from the more general text. If it's mostly text you're modifying, ?element_text will probably be helpful.

重新使用RStudio设置字体系列可能不会更改绘图在绘图窗口,但它将工作,如果您导出的图作为PDF。 (至少对于我来说,在Windows上。)

Also note that if you're using RStudio setting the font family may not change the plot in the plot window, but it will work if you export the plot as a PDF. (At least for me, on Windows.)

如果要更改作为绘图一部分的文本(由 geom_text ),你可能需要实际上攻击该函数。它是所有在github ,所以只是让你的自己的包的叉。

If you want to change the text that is part of the plot (set by geom_text), you'll probably need to actually hack the function. It's all on github, so just make your own fork of the package.

这篇关于如何更改R包中的所有不同文本的文本字体,大小和颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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