简体   繁体   English

R:更改 hist 和 barplot 的字体

[英]R: change font for hist and barplot

I tried to change the font of my hist and barplot (with R), but I can not succeed... I tried the extrafont package but I can not find how to change it...我试图改变我的 hist 和 barplot 的字体(用 R),但我不能成功......我尝试了 extrafont 包,但我找不到如何改变它......

How can I simply change all of the fonts for all of my graph (hist and barcharts) ?如何简单地更改所有图形(直方图和条形图)的所有字体? I only have axis labels and of course the numbers on the axis.我只有轴标签,当然还有轴上的数字。

On Windows, set it globally like this在 Windows 上,像这样全局设置它

windowsFonts(times = windowsFont("Times New Roman")) 
par(family = "times", font = 2, font.lab = 2, font.axis = 2)
barplot(1, names.arg = 1, xlab = "x", ylab = "y")
hist(rnorm(1:100))

or path it to the plotting function itself like this或者像这样将它路径到绘图函数本身

barplot(1, names.arg = 1, xlab = "x", ylab = "y", family = "serif", font = 2, font.lab = 2, font.axis = 2)

Have a look at the help ?par for further info on the parameters like font.lab.查看帮助?par以获取有关 font.lab 等参数的更多信息。

It is easy for people to point to the par help page.人们很容易指向par帮助页面。 But at least for R version 3.5.2 the solution is not on that page!但至少对于 R 版本 3.5.2,该解决方案不在该页面上!

In the barplot the x-axis is technically not an axis since it uses the names of the supplied vector.barplot ,x 轴在技术上不是轴,因为它使用提供的向量的名称。 So, you need to set cex.names = 0.5 for smaller text.因此,您需要为较小的文本设置cex.names = 0.5 Alternatively, you can use a larger value for larger text.或者,您可以为较大的文本使用较大的值。

a <- c(1:3)
names(a) <- c(1:3)
barplot(a, cex.names = 2)

Good luck!祝你好运!

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM