简体   繁体   中英

Save text as curves with ggplot ggsave

The following code will create a plot in a PDF file

library(ggplot2)

ggplot(data=mtcars, aes(x=cyl, y=hp))+
  geom_point() +
ggsave(filename="test1.pdf")

There are only very few characters, but they are fragile as long they are not curves. I want to conserve the appeareance.

$ pdffonts test1.pdf 
name                                 type              emb sub uni object ID
------------------------------------ ----------------- --- --- --- ---------
ZapfDingbats                         Type 1            no  no  no      10  0
Helvetica                            Type 1            no  no  no      11  0

How can I convert the text and symbols to curves?

running R 2.15 on debian squeeze

picture explaining what text-to-curves means

Copied from https://tex.stackexchange.com/questions/27327/how-to-convert-text-in-a-pdf-file-from-fonts-text-to-outlines : I called this script pdfsquash

#!/bin/sh

if [ "x$1" = "x" -o "x$2" = "x" ]; then
    echo Usage: `basename "$0"` "<input.pdf>" "<output.pdf>" >&2
    exit 1
fi
gs -sDEVICE=pswrite -dNOCACHE -sOutputFile=- -q \
   -dbatch -dNOPAUSE -dQUIET "$1" -c quit | ps2pdf - "$2"

I ran your code, then (outside of R, although you could also use system() ):

pdfsquash test1.pdf test1S.pdf

The original:

pdffonts test1.pdf
name                                 type              emb sub uni object ID
------------------------------------ ----------------- --- --- --- ---------
ZapfDingbats                         Type 1            no  no  no      10  0
Helvetica                            Type 1            no  no  no      11  0

New:

pdffonts test1S.pdf
name                                 type              emb sub uni object ID
------------------------------------ ----------------- --- --- --- ---------

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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