[R] Computer Modern Fonts in R graphic

Friedericksen Hope friedericksen.hope at gmail.com
Mon Aug 31 08:00:13 CEST 2009


Dear Charlie,

thank you very much for your response. The tikzDevice is a very nice 
developing thing. I already tried to create my graphic with this device, 
but unfortunately the created *.tex file exceeded the main memory size 
of my tex processor. Therefore I tried the "classic" way of implementing 
the CMF.

Greetings,
Friedricksen



Charlie Sharpsteen wrote:
> If you are trying to use Computer Modern fonts because the R graphics will
> be included in a LaTeX report, you could try the TikZ Device Cameron Bracken
> and I wrote:
> http://r-forge.r-project.org/projects/tikzdevice
> 
> The tikzDevice translates R graphics instructions into a LaTeX-friendly
> format that can be included directly into documents where the font used in
> the figure will match that used in the rest of the text.
> 
> <http://r-forge.r-project.org/projects/tikzdevice>It can be installed from R
> with the following command:
> 
> install.packages( 'tikzDevice', repos='http://r-forge.r-project.org')
> 
> The package is still in beta but we have had very good results so far- tests
> we have run with the persp function look great.
> 
> For your case, you would replace the call to pdf() with:
> 
> pdf("snxsm.tex")
> 
> And inside your tex document the figure code stored in snxsm.tex is included
> using the \input{} command:
> 
> \documentclass{whatever}
> 
> ...
> \usepackage{tikz}
> 
> ...
> \begin{document}
> 
> \begin{figure}
> 
>   \input{snxsm}
> 
> \end{figure}
> 
> ...
> \end{document}
> 
> Note you will need the TikZ package installed in your LaTeX distribution.
> Installation of LaTeX packages is covered in Part 2 of the tikzDevice
> vignette:
> 
> vignette( 'tikzDevice' )
> 
> Hope this helps!
> 
> -Charlie
> 
> 
> On Sun, Aug 30, 2009 at 1:14 PM, Friedericksen Hope <
> friedericksen.hope at gmail.com> wrote:
> 
>> Hello all,
>>
>> I am trying to use computer modern fonts in my r grahics. I tried to do, as
>> described here: http://www.stat.auckland.ac.nz/~paul/R/CM/CMR.html but
>> unfortunately, it does not work.
>>
>> First of all I downloaded the cm-lgc package and the AFM and PFB-files from
>> the page and put them in my R working directory, so far, so good.
>>
>> Then I tried to run the following code:
>>
>>  sn <- seq(1,7,length=100)
>>> sm <- seq(0,4,length=100)
>>> f <- function(x,y) {5.64080973 + 0.12271038*x - 0.27725481 * y +
>>> 0.29281216*x*y}
>>> z <- outer(sn,sm,f)
>>>
>>> nrz <- nrow(z)
>>> ncz <- ncol(z)
>>> jet.colors <- colorRampPalette( c("yellow", "red") ) nbcol <- 100
>>> color <- jet.colors(nbcol)
>>> zfacet <- z[-1, -1] + z[-1, -ncz] + z[-nrz, -1] + z[-nrz, -ncz]
>>> facetcol <- cut(zfacet, nbcol)
>>>
>>> CM <- Type1Font("CM",
>>>                     c("cm-lgc/fonts/afm/public/cm-lgc/fcmr8a.afm",
>>>                       "cm-lgc/fonts/afm/public/cm-lgc/fcmb8a.afm",
>>>                       "cm-lgc/fonts/afm/public/cm-lgc/fcmri8a.afm",
>>>                       "cm-lgc/fonts/afm/public/cm-lgc/fcmbi8a.afm",
>>>                       "cmsyase.afm")) postscriptFonts(CM=CM)
>>> pdf("snxsm.pdf")
>>> par(family="CM")
>>> persp(sn,sm,z,xlab="SN",
>>> ylab="SM",zlab="VI",theta=-20,phi=20,r=5,shade=0.01,col=color[facetcol])
>>> dev.off()
>>>
>> It works fine, until the persp() function, there I get:
>>
>>  persp(sn,sm,z,xlab="SN",
>>> ylab="SM",zlab="VI",theta=-20,phi=20,r=5,shade=0.01,col=color[facetcol])
>>> Error in persp.default(sn, sm, z, xlab = "SN", ylab = "SM", zlab = "VI",
>>>  :  Invalid font type
>>> In addition: Warning messages:
>>> 1: In persp.default(sn, sm, z, xlab = "SN", ylab = "SM", zlab = "VI",  :
>>>  font family not found in PostScript font database
>>> 2: In persp.default(sn, sm, z, xlab = "SN", ylab = "SM", zlab = "VI",  :
>>>  font family not found in PostScript font database
>>> 3: In persp.default(sn, sm, z, xlab = "SN", ylab = "SM", zlab = "VI",  :
>>>  font family not found in PostScript font database
>>> 4: In persp.default(sn, sm, z, xlab = "SN", ylab = "SM", zlab = "VI",  :
>>>  font family not found in PostScript font database
>>> 5: In persp.default(sn, sm, z, xlab = "SN", ylab = "SM", zlab = "VI",  :
>>>  font family not found in PostScript font database
>>>
>> Any help is appreciated! Also a hint/link how to install the CM fonts under
>> R for general use, so that I don't have to have it in my wd all the time.
>>
>> Thank you very much!
>>
>> Greetings,
>> Friedericksen
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
> 
> 	[[alternative HTML version deleted]]
>




More information about the R-help mailing list