[R] Computer Modern Fonts in R graphic
Friedericksen Hope
friedericksen.hope at gmail.com
Mon Aug 31 08:11:06 CEST 2009
Dear Paul,
thank you very much for your answer. You are right, pdfFonts() solved
the "problem". :-) I also will try to install the fonts on my system.
Thank you!
Greetings,
basil
Paul Murrell wrote:
> Hi
>
>
> Friedericksen Hope 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
>
>
> Looks like you are trying to produce PDF output, but you've set up the
> fonts in the PostScript font database. Try using pdfFonts() instead.
>
>
>> 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.
>
>
> The cm-lgc package should have instructions for installing the fonts on
> your system
> (e.g., http://www.ctan.org/tex-archive/fonts/ps-type1/cm-lgc/INSTALL)
> but you would then need to adjust the paths that you specify in the call
> to Type1Font().
>
> You could then add the calls to Type1Font() and pdfFonts() to your
> .Rprofile so that this font is defined every time you start an R session
> (see ?Startup).
>
> Paul
>
>
>> 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.
>
More information about the R-help
mailing list