[R] Using Unicode inside R's expression() command
David Winsemius
dwinsemius at comcast.net
Sun Nov 10 22:10:56 CET 2013
On Nov 9, 2013, at 11:01 AM, Sverre Stausland wrote:
> I'm using 'expression()' in R plots in order to get italicized text.
> But it appears as if I cannot use Unicode symbols inside 'expression'
> outside of ASCII characters. Is there some way I can work around this?
> My goal is to get the 'fi' ligature in various labels in my R barplots
> (together with italicized text). I think I could work around this if
> there was another way of italicizing selected characters in a string
> than using 'expression()'.
>
> I'm using R for Windows version 3.0.2.
>
> CairoPDF(file = "Ligature1.pdf")
> plot.new()
> text(x =.5, y = .5, labels = "fi", family = "Times New Roman")
> dev.off()
>
> CairoPDF(file = "Ligature2.pdf")
> plot.new()
> text(x =.5, y = .5, labels = expression(paste(italic(m), "u", "fi",
> italic(m), sep = "")), family = "Times New Roman")
> dev.off()
> <lig1.png><lig2.png>
To the list readers: I posted a comment to the identical SO question that changing the font with CairoFonts before the CairoPDF call might be more effective. (I used a font name of "TimesNewRoman" rather than "Times New Roman" but testing with
CairoFontMatch(fontpattern="Times New Roman",sort=FALSE,verbose=TRUE)
... proved that the spaces were not causing problems. I happen to have a copy of Times New Roman since I have purchased MS Office, but I do not know if everyone would have that font installed. )
This succeeded
CairoFonts(
regular="Roman-12:normal", italic="Roman-12:italic"
)
# The default family is Helvetica on my machine running OSX 10.7.5
--
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list