将R图输出为pdf + latex

时间:2013-10-28 14:50:11

标签: r graphics latex

我刚注意到在Inkscape中您可以将矢量图形导出为pdf + latex文件,它基本上将文本与图形分开。这真的很酷,因为它使图中的字体与文档的字体一致。

然后我查看了postscript(), pdf()等设备功能的文档,似乎没有等效的选项。这可能在R?


应@DWin的要求,我进一步解释了我要找的东西:一个可以输出两个文件的R函数:x.pdf和x.pdftex,第一个包含图形,第二个包含文本(分离可能不完美,但大多数情况下应该是这样)。以下是来自inkscape的示例:

x.pdf:

enter image description here

x.pdftex

%% Creator: Inkscape inkscape 0.48.4, www.inkscape.org
%% PDF/EPS/PS + LaTeX output extension by Johan Engelen, 2010
%% Accompanies image file 'drawing.pdf' (pdf, eps, ps)
%%
%% To include the image in your LaTeX document, write
%%   \input{<filename>.pdf_tex}
%%  instead of
%%   \includegraphics{<filename>.pdf}
%% To scale the image, write
%%   \def\svgwidth{<desired width>}
%%   \input{<filename>.pdf_tex}
%%  instead of
%%   \includegraphics[width=<desired width>]{<filename>.pdf}
%%
%% Images with a different path to the parent latex file can
%% be accessed with the `import' package (which may need to be
%% installed) using
%%   \usepackage{import}
%% in the preamble, and then including the image with
%%   \import{<path to file>}{<filename>.pdf_tex}
%% Alternatively, one can specify
%%   \graphicspath{{<path to file>/}}
%% 
%% For more information, please see info/svg-inkscape on CTAN:
%%   http://tug.ctan.org/tex-archive/info/svg-inkscape
%%
\begingroup%
  \makeatletter%
  \providecommand\color[2][]{%
    \errmessage{(Inkscape) Color is used for the text in Inkscape, but the package 'color.sty' is not loaded}%
    \renewcommand\color[2][]{}%
  }%
  \providecommand\transparent[1]{%
    \errmessage{(Inkscape) Transparency is used (non-zero) for the text in Inkscape, but the package 'transparent.sty' is not loaded}%
    \renewcommand\transparent[1]{}%
  }%
  \providecommand\rotatebox[2]{#2}%
  \ifx\svgwidth\undefined%
    \setlength{\unitlength}{86.275bp}%
    \ifx\svgscale\undefined%
      \relax%
    \else%
      \setlength{\unitlength}{\unitlength * \real{\svgscale}}%
    \fi%
  \else%
    \setlength{\unitlength}{\svgwidth}%
  \fi%
  \global\let\svgwidth\undefined%
  \global\let\svgscale\undefined%
  \makeatother%
  \begin{picture}(1,0.86757462)%
    \put(0,0){\includegraphics[width=\unitlength]{drawing.pdf}}%
    \put(0.15439887,0.382321){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{test}}}%
  \end{picture}%
\endgroup%

编译后你应该得到:

enter image description here

优点是您可以在主乳胶文档中指定字体,并且图中的文字字体将自动调整。

(Inkscape也支持ps + latex和eps + latex。)

1 个答案:

答案 0 :(得分:0)

R有三个主要的绘图框架。您可以使用postscriot() devicepsFonts()指定默认字体系列;您可以通过对设备的单独调用来指定字体和系列;您可以在使用text()grid.text()等注释函数时指定备用字体。您应该指定一个特定的用例,而不是将您的问题留在一个模糊的形式,而不是真正要求特定的密码解决方案