我正在尝试设置 R postscript () 设备来显示汉字但没有成功。
我正在使用带有以下 RsessionInfo()
信息的 Macbook Pro Mountain Lion 10.8.3:
R version 3.0.0 (2013-04-03)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] tools_3.0.0
以下是我的主要代码
postscript("圖9-35plotmath.ps", horizontal = FALSE, height = 6)
plot(c(-pi, -pi/2, 0, pi/2, pi), 1:5, type = "n", xaxt = "n", main = expression(paste(plain(sin) * phi, "與", plain(cos) * phi)), ylab = expression("sin" * phi), xlab = expression(paste("Phase Angle", phi)))
axis(side = 1, at = c(-pi, -pi/2, 0, pi/2, pi), labels = expression(-pi, -pi/2, 0, pi/2, pi))
for(i in 1:5)
{
text(-2.5, i, substitute(list(xi, eta) == group("(", list(x, y), ")"), list(x = i, y = i+1)))
}
text(-1.7, 5, expression("一階微分"== {f * minute}(x)), adj = 0)
text(-1.7, 4, expression("二階微分"== {f * second}(x)), adj = 0)
text(-1.7, 3, pos = 4, expression(hat(beta) == (X^t * X)^{-1} * X^t *y))
text(-1.7, 2, pos = 4, expression(bar(x) == sum(frac(x[i], n), i == 1, n)))
text(-1.7, 1.2, pos = 4, expression(paste(frac(1, sigma*sqrt(2*pi)), " ", plain(e)^{frac(-(x-mu)^2, 2*sigma^2)})), cex = 1.2)
text(0.5, 4.6, pos = 4, expression(prod(plain(P)(X == k), k = 1, n)))
text(0.5, 4, pos = 4, expression(integral(f(x)*dx, a,b)))
text(0.5, 3, pos = 4, expression(union(A[i], i == 1, n)))
text(0.5, 2, pos = 4, expression(intersect(A[i], i == 1, n)))
text(0.5, 1, pos = 4, expression(lim(f(x), x %->% 0)))
text(2, 4.5, pos = 4, expression(min(f(x), x > 0)))
text(1, 3.5, pos = 4, expression(Y == beta[0] + list(beta[1]*X[1], ..., beta[p-1]*X[p-1])))
text(1.5, 2.5, pos = 4, expression(S^2 == sqrt(frac(sum((X[i]=bar(x))^2), n-1))))
dev.off()
上述内容不起作用,生成的后记文件为所有这些汉字提供 [...]。然后,我尝试了以下方法:
在 postscript() 中使用现有的 GB1 字体。它给了我一个无法被 Mac Preview、Ghostscript 和 Photoshop 打开的 .ps 文件。
postscript("圖9-35plotmath.ps", horizontal = FALSE, height = 6, fonts=c("GB1"))
plot(c(-pi, -pi/2, 0, pi/2, pi), 1:5, type = "n", xaxt = "n", family = "GB1", main = expression(paste(plain(sin) * phi, "與", plain(cos) * phi)), ylab = expression("sin" * phi), xlab = expression(paste("Phase Angle", phi)))
...............(omitted)
text(-1.7, 5, family = "GB1", expression("一階微分"== {f * minute}(x)), adj = 0)
text(-1.7, 4, family = "GB1", expression("二階微分"== {f * second}(x)), adj = 0)
..............(omitted)
我也尝试使用 CIDFont() 添加一些字体,但它仍然提供了一个根本无法打开的 .ps 文件。
song = CIDFont("SimSun", "GBK-EUC-H", "GBK", "")
postscriptFonts(song = song)
postscript("圖9-35plotmath.ps", horizontal = FALSE, height = 6, family="song")
plot(c(-pi, -pi/2, 0, pi/2, pi), 1:5, type = "n", xaxt = "n", family = "song", main = expression(paste(plain(sin) * phi, "與", plain(cos) * phi)), ylab = expression("sin" * phi), xlab = expression(paste("Phase Angle", phi)))
..............(omitted)
text(-1.7, 5, family = "song", expression("一階微分"== {f * minute}(x)), adj = 0)
text(-1.7, 4, family = "song", expression("二階微分"== {f * second}(x)), adj = 0)
.............(omitted)
两种方法都没有警告,但 .ps 文件无法打开。
我发现很难理解 postscript() 中的字体和系列定义,其中 par(family = "SimSun") 在 pdf() 和 png() 设备中显示和保存以下内容完全没有问题。
我需要为高质量打印制作一个 postscript 文件。
再次感谢。
党卫军