[R] Italicized greek symbols in PDF plots
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Jun 30 07:17:13 CEST 2011
On Wed, 29 Jun 2011, Sam Albers wrote:
> I know that this has been asked before in other variations but I just can't
> seem to figure out my particular application from previous posts. My
> apologies if I have missed the answer to this question somewhere in the
> archives. I have indeed looked.
>
> I am running Ubuntu 11.04, with R 2.12.1 and ESS+Emacs.
>
> For journal formatting requirements, I need to italicize all the greek
> letters in any plot. This is reasonably straight forward to do and I
> accomplished this task like so:
>
> library(ggplot2)
>
> label_parseall <- function(variable, value) {
> plyr::llply(value, function(x) parse(text = paste(x)))
> }
>
> dat <- data.frame(x = runif(270, 0, 125), z = rep(LETTERS[1:3], each = 3),
> yy = 1:9, stringsAsFactors = TRUE)
> #unicode italicized delta
> dat$gltr =
> factor(c("italic(\u03b4)^14*N","italic(\u03b4)^15*N","italic(\u03b4)^13*C"))
>
> #So this is what I want my plot to look like:
> plt <- ggplot(data = dat, aes(x = yy, y = x)) +
> geom_point(aes(x= yy, y=x, shape=z, group=z), alpha=0.4,position =
> position_dodge(width = 0.8)) +
> facet_grid(gltr~.,labeller= label_parseall, scales="free_y")
> plt
>
> #So then I exported my plot as a PDF like so:
> pdf("Times_regular.pdf", family='Times')
> plt
> dev.off()
> #The problem with this was that the delta symbols turned into dots.
You forgot to set the encoding: see the ?pdf help file. Greek is most
likely not covered by the default encoding (and you also forgot the
'at a minimum' information required by the posting guide, so we don't
know what your defaults would be).
> #I solved this problem using Cairo
> library(Cairo)
> cairo_pdf("Cairo.pdf")
> plt
> dev.off()
>
>
> The problem that I face now is that I am unsure how to output a figure that
> maintains the greek symbols but outputs everything in the plot as TImes New
> Roman, another requirement of the journal. So I can produce a Times New
> Roman PDF plot and an italicize greek symbol unicode PDF plot but not both.
> Does anoyone have any idea how I might accomplish both of these things
> together in a single PDF?
I woud use cairo_pdf() in base R (and not package Cairo). Use grid
facilities to change font, or use the version in R-devel which has a
family= argument.
>
> Thanks so much in advance,
>
> Sam
>
> [[alternative HTML version deleted]]
> ______________________________________________
> 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
That does mean you!
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list