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

时间:2021-06-03 23:16:15

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. For example, use font size 12 for main titles and font size 10 for axis titles.

具体来说,我想使用默认系列'Helvetica'并指定字体大小以对应.doc字体大小。例如,对于主标题使用字体大小12,对于轴标题使用字体大小10。

I'd appreciate your advise and suggestions. thanks!

我很感激你的建议和建议。谢谢!

3 个解决方案

#1


3  

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. Unfortunately, you can't specify in a standard font size of 10 or 12.

还有一个par('font')可用于设置字体是粗体,斜体等。对于尺寸,除了Brandon提到的cex参数组,允许将字体大小设置为相对术语,也有cin,cra,我相信更多,允许一个人以英寸或像素为单位设置尺寸。遗憾的是,您无法指定标准字体大小为10或12。

Check the help for par() and read it very carefully.

检查par()的帮助并仔细阅读。

#2


2  

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". But I'd love to see one.

你的第一个问题需要一些繁重的工作。这里有一套很好的说明:http://www.jameskeirstead.ca/typography/changing-the-fonts-in-r-plots/我不知道“更简单的方法”。但我很乐意看到一个。

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.

此外,您可以使用?pdf中的pointsize设置来调整相对大小。

#3


0  

Maybe try to use pointsize = 12, within your quartz()? https://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/quartz.html

也许尝试在你的quartz()中使用pointsize = 12? 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().

出于某种原因,我的家人=“Helvetica”在放入quartz()时不起作用。

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()导出我的绘图,但quartz()只是为了将绘图复制到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()

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

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()

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

#1


3  

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. Unfortunately, you can't specify in a standard font size of 10 or 12.

还有一个par('font')可用于设置字体是粗体,斜体等。对于尺寸,除了Brandon提到的cex参数组,允许将字体大小设置为相对术语,也有cin,cra,我相信更多,允许一个人以英寸或像素为单位设置尺寸。遗憾的是,您无法指定标准字体大小为10或12。

Check the help for par() and read it very carefully.

检查par()的帮助并仔细阅读。

#2


2  

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". But I'd love to see one.

你的第一个问题需要一些繁重的工作。这里有一套很好的说明:http://www.jameskeirstead.ca/typography/changing-the-fonts-in-r-plots/我不知道“更简单的方法”。但我很乐意看到一个。

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.

此外,您可以使用?pdf中的pointsize设置来调整相对大小。

#3


0  

Maybe try to use pointsize = 12, within your quartz()? https://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/quartz.html

也许尝试在你的quartz()中使用pointsize = 12? 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().

出于某种原因,我的家人=“Helvetica”在放入quartz()时不起作用。

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()导出我的绘图,但quartz()只是为了将绘图复制到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()

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

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()

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