SSブログ

R: ggplot2からpostscript出力 [統計]

わけあってggplot2からpostscript出力。ちょっと手間がかかる。

n <- 100
x <- rnorm(n, 0, 1)
y <- rnorm(n, 0, 1)
z <- sqrt(x^2 + y^2)

library(ggplot2)

postscript(family = "Japan1GothicBBB", onefile = FALSE,
           width = 12 / 2.54, height = 9 / 2.54,
           paper = "special", horizontal = FALSE)

df <- data.frame(x = x, y = y, z = z)
p <- ggplot(df) +
  geom_point(aes(x = x, y = y, colour = z), size = 3) +
  coord_fixed(ratio = 1) +
  scale_colour_gradient(name = "Zの値",
                        low = "grey90", high = "grey10") +
  xlab("Xの値") + ylab("Yの値") +
  theme_bw(base_family = "") %+replace%
  theme(legend.title = element_text(face = "plain"))
print(p)

dev.off()

themeのlegend.titleでfaceを"plain"にしておかないと、この部分がばける。 ghostscriptでは、GothicBBB-Medium-Bold-EUC-Hがみつからないというエラーになるが、Adobe DistillerではCourierに置換してくれる。

Rplot001.png


タグ:R
nice!(1)  コメント(0)  トラックバック(0) 
共通テーマ:日記・雑感

nice! 1

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

Facebook コメント

トラックバック 0