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

发布于 2024-12-03 15:00:15 字数 143 浏览 2 评论 0原文

关于如何将 cex 校准为字体大小单位有什么想法吗?

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

我非常感谢您的意见和建议。谢谢!

Any ideas on how to calibrate cex to font size units?

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.

I'd appreciate your advise and suggestions. thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

北方。的韩爷 2024-12-10 15:00:15

您可以逐个绘图地设置默认字体。

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

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

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

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.

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

小帐篷 2024-12-10 15:00:15

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

对于第二个问题:请参阅 ?par 特别是有关 cex 的部分。

cex
cex.axis
cex.lab
cex.main

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

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.

For your second question: See ?par specifically the part about cex.

cex
cex.axis
cex.lab
cex.main

Additionally, you can mess with the pointsize setting in ?pdf to adjust the relative sizes.

差↓一点笑了 2024-12-10 15:00:15

也许尝试在您的 quartz() 中使用 pointsize = 12 ? https://stat.ethz.ch/ R-manual/R-devel/library/grDevices/html/quartz.html

quartz(pointsize = 12)

由于某种原因,当我的 family="Helvetica" 放在 quartz() 中时,它不起作用。

这两个更改 - 更改 fontfontsize 按以下顺序工作:

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

因此,对于 pdf() 绘图导出和 < strong>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()

在此处输入图像描述

或者更改我的系列和点大小:

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

在此处输入图像描述

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)

For some reason, my family="Helvetica" doesn't work, when placed within quartz().

Both changes - change font and fontsize works in this order:

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

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

enter image description here

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

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文