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 databaseAny 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
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 databaseLooks 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.-- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/
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@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@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]]
Hello And sorry for the brief highjacking. On 8/31/09, Charlie Sharpsteen <chuck at sharpsteen.net> wrote:> 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. >Is there any support for Sweave? What would be the preferred way to include TikZ graphics in an Sweave document? Thank you Liviu