Frage

I wish to include a unicode character in the PNG output of xyplot on Windows 7 with R 3.0.1. E.g. (note the µ in the expression in ylab)

## output to windows() works fine
xyplot(CD4 ~ obstime, groups=aids$patient, data=aids, type="b", ylab=expression(sqrt("CD4/µl")))

## output to PNG does not
png(file="AIDS.png", width=5, height=5, units="in", type="cairo", res=800)
xyplot(CD4 ~ obstime, groups=aids$patient, data=aids, type="b", ylab=expression(sqrt("CD4/µl")))
dev.off()

I get the error "Metric information not available for this device".

I think this might be a general issue with unicode and png(), as using plot(1, main="µ") prints µ for windows() output, but not for png() output (where the µ is silently omitted). However, using CairoPNG does not resolve this issue: it prints µ for plot(), but the error with xyplot() remains (xyplot also seems to ignore the pointsize= for Cairo).

War es hilfreich?

Lösung

Try this (using plotmath expression interpretation):

png(file="AIDS.png", width=5, height=5, units="in", type="cairo", res=800)
xyplot(1 ~ 1,  type="b", ylab=expression(sqrt(CD4/µ*l)))
dev.off()

Or:

png(file="AIDS.png", width=5, height=5, units="in", type="cairo", res=800)
xyplot(1 ~ 1,  type="b", ylab=expression(sqrt(CD4/mu*l)))
dev.off()

(Either of these was much faster on my device than getting png() to do whatever it did with the character version.)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top