R-Change plot glyphs, embed fonts in PDF

Source: Internet
Author: User

Two problems with the recent use of R drawing

1. Use a different font

2. Save plot to PDF when font is embedded in PDF (embed the font)


These two problems can be solved by using Extrafont and Ghostscript.

1. Ghostscript

Installation: http://www.ghostscript.com/download/gsdnld.html


2. Extrafont (R package)

The following commands are executed in R

-Installation

> install.packages ("Extrafont") > Library (extrafont)      > #这一步定位系统字体. C:\windows\fonts\*.ttf, for example, takes a few minutes > Font_import () > Loadfonts ()

-Using

> #查看可用的font family> fonts ()
> Library (GGPLOT2) > #使用字体Times New Roman drawing > P <-ggplot (Mtcars, AES (X=WT, Y=mpg)) + geom_point () +  Xlab ("W Eight ") + Ylab (" Miles per gallon ") +  Theme (Text=element_text (family=" Times New Roman ") > #保存pdf > Ggsave (" Font _ggplot.pdf ", plot=p)

-Embed fonts into PDF

> #指定ghostscript的路径 > sys.setenv (r_gscmd = "C:/Program Files/gs/gs9.05/bin/gswin32c.exe") > #嵌入字体 > Embed_ Fonts ("Font_ggplot.pdf", outfile= "Font_ggplot_embed.pdf")

The font_ggplot_embed.pdf you get is the PDF you need!

Ability to see if a font is embedded by using Fonts, Properties, Adobe Reader, File-

(The above content is from http://cran.r-project.org/web/packages/extrafont/README.html)


Bonus: Embed fonts directly into PDF using Ghostscript command line

(Execute in cmd, don't forget to add ghostscript environment variable)

Gswin32c-sfontpath=c:\windows\fonts-sdevice=pdfwrite-dembedallfonts=true-o output.pdf Input.pdf



Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

R-Change plot glyphs, embed fonts in PDF

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.