简体   繁体   English

如何在绘图中指定字体大小(用于PDF输出)?

[英]How to specify font size in a plot (for PDF output)?

Any ideas on how to calibrate cex to font size units? 关于如何将CEX校准为字体大小单位的任何想法?

Specifically, I'd like to work with the default family 'Helvetica' and specify font sizes to correspond to .doc font sizes. 具体来说,我想使用默认系列'Helvetica'并指定字体大小以对应.doc字体大小。 For example, use font size 12 for main titles and font size 10 for axis titles. 例如,对于主标题使用字体大小12,对于轴标题使用字体大小10。

I'd appreciate your advise and suggestions. 非常感谢您的建议。 thanks! 谢谢!

You can set the default font on a plot by plot basis. 您可以在每个图的基础上设置默认字体。

par(family = 'Helvetica')
plot(rnorm(10), main = 'Something In Helvetica')

There is also a par('font') that you can use to set whether the font is bold, italic, etc. For the size, besides the cex group of parameters mentioned by Brandon that allow one to set the font size as a relative term, there is also cin, cra, and I believe more that allow one to set sizes in inches or in pixels. 还有一个par('font')可用于设置字体是否为粗体,斜体等。对于大小,除了Brandon提到的cex参数组外,它允许将字体大小设置为相对大小。术语,还有cin,cra,而且我相信还有更多可以让人们以英寸或像素为单位设置尺寸。 Unfortunately, you can't specify in a standard font size of 10 or 12. 不幸的是,您不能指定10或12的标准字体大小。

Check the help for par() and read it very carefully. 检查par()的帮助,并仔细阅读。

Your first question requires a bit of heavy lifting. 您的第一个问题需要一些繁重的工作。 There is a good set of instructions here: http://www.jameskeirstead.ca/typography/changing-the-fonts-in-r-plots/ I'm not aware of an "easier way". 这里有一组很好的说明: http : //www.jameskeirstead.ca/typography/changing-the-fonts-in-r-plots/我不知道“更简便的方法”。 But I'd love to see one. 但我很想看看一个。

For your second question: See ?par specifically the part about cex. 关于第二个问题:请参阅?par特别是有关cex的部分。

cex
cex.axis
cex.lab
cex.main

Additionally, you can mess with the pointsize setting in ?pdf to adjust the relative sizes. 此外,还可以惹pointsize的设置?pdf调整相对大小。

Maybe try to use pointsize = 12 , within your quartz() ? 也许尝试在您的quartz()使用pointsize = 12 https://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/quartz.html https://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/quartz.html

quartz(pointsize = 12)

For some reason, my family="Helvetica" doesn't work, when placed within quartz() . 由于某种原因,当我放置在quartz()时,我的家人=“ Helvetica”无法正常工作。

Both changes - change font and fontsize works in this order: 两项更改-更改字体fontsize的顺序如下:

quartz(pointsize = 12) # define point size
par(mar=c(3,3,1,1), family = "Helvetica")    # define family
plot(...)

Thus, for pdf() plot exporting and quartz() output, as they don't run at the same time - I'm using the pdf() for exporting my plots, but quartz() just to copy a plot to MS Word document 因此,对于pdf()图导出和quartz()输出,因为它们不能同时运行-我使用pdf()导出图,但是crystal()只是将图复制到MS Word文献

library(extrafont)       # library needed to have your fonts
loadfonts() ## for pdf() 

# pdf plot export - now doesn't run, because now I want just check changes in my quartz() plotting
# pdf("my_plot_in_pdf.pdf", height = 4, width = 4, family = "Helvetica") 

quartz(height = 4, width = 4, pointsize = 12)  # check my changes in plot, if I want to export my plot, I just set #quartx(...)
    par(mar=c(4,4,1,1), family = "Helvetica")
    plot(cars, main = "Helvetica, 12", ylab = "y label", xlab = "x label", cex = 1)
    dev.off()

在此处输入图片说明

OR change my family and points size: 或更改我的家庭和积分大小:

quartz(height = 4, width = 4, pointsize = 20)
par(mar=c(4,4,1,1), family = "Times New Roman")
plot(cars, main = "Times New Roman, 20", ylab = "y label", xlab = "x label", cex = 1)
dev.off()

在此处输入图片说明

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

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