错误使用宋体.eps图与extrafont包 [英] Error using Arial in .eps figure with extrafont package
问题描述
loadfonts(device =postscript)
应该将所有导入的字体(包括Arial)注册到postscript设备。但是,当我运行我的代码,并尝试使用此代码保存我的数字:$ g $ p $ g $ gplot()+ geom_point(aes(x = xvar,y = yvar))+ theme_minimal(base_family =Arial)
library(extrafont)
font_import()
loadfonts(device =postscript)
ggsave =myfile.eps)
我仍然得到这个错误:
Grid.Call中的错误(L_textBounds,as.graphicsAnnot(x $ label),x $ x,x $ y,
:不包含系列'Arial'在postscript()设备中
我缺少什么?
假设您在Windows操作系统上,您可以使用 $ b $ pre $ library $(showtext)
## add therel =nofollow> showtext package
font.add(Arial,regular =arial.ttf,
bold =arialbd.ttf,italic =ariali.ttf,粗体italic =arialbi.ttf)
setEPS()
postscript(some_graph.eps)
showtext.begin()##打开设备后调用该函数
ggplot()+ geom_point(aes(x = xvar,y = yvar))+
theme_minimal(base_family =Arial)
dev.off()
缺点是不能使用 ggsave()
函数,而是自己调用设备函数。
对于 showtext
包的使用,自述文件在 https://github.com/yixuan/showtext 上给出。
I'm using ggplot2 in R to generate figures for a publication in which all figures need to be .eps format and all fonts needs to be Arial. I've been following this guide to doing this using the extrafont package. As I understand it, the line loadfonts(device = "postscript")
should register all of the fonts I imported (which includes Arial) with the postscript device. But when I run my code and try to save my figure using this code:
ggplot() + geom_point(aes(x=xvar, y=yvar)) + theme_minimal(base_family = "Arial")
library(extrafont)
font_import()
loadfonts(device = "postscript")
ggsave(filename = "myfile.eps")
I still get this error:
Error in grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : family 'Arial' not included in postscript() device
What am I missing?
Assuming you are on a Windows OS, you can alternatively create the graph using the showtext package.
library(showtext)
## add the Arial font
font.add("Arial", regular = "arial.ttf",
bold = "arialbd.ttf", italic = "ariali.ttf", bolditalic = "arialbi.ttf")
setEPS()
postscript("some_graph.eps")
showtext.begin() ## call this function after opening a device
ggplot() + geom_point(aes(x=xvar, y=yvar)) +
theme_minimal(base_family = "Arial")
dev.off()
The drawback is that you cannot use the ggsave()
function, but instead call the device function by yourself.
For the usage of the showtext
package, a README is given at https://github.com/yixuan/showtext.
这篇关于错误使用宋体.eps图与extrafont包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!