2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

R: plot fonts in Japanese

Posted at

png seems to work fine, even sometimes without the following addition.

png("/tmp/test.png")
par(family="HiraMaruProN-W4")
plot(iris, main = "アヤメのデータ")
dev.off()

Also, add the following chunk to the .Rprofile. This requires X.

setHook(packageEvent("grDevices", "onLoad"),
function(...){
if(.Platform$OS.type == "windows")
grDevices::windowsFonts(sans ="MS Gothic",
serif="MS Mincho",
mono ="FixedFont")
if(capabilities("aqua"))
grDevices::quartzFonts(
sans =grDevices::quartzFont(
c("Hiragino Kaku Gothic Pro W3",
"Hiragino Kaku Gothic Pro W6",
"Hiragino Kaku Gothic Pro W3",
"Hiragino Kaku Gothic Pro W6")),
serif=grDevices::quartzFont(
c("Hiragino Mincho Pro W3",
"Hiragino Mincho Pro W6",
"Hiragino Mincho Pro W3",
"Hiragino Mincho Pro W6")))
if(capabilities("X11"))
grDevices::X11.options(
fonts=c("-kochi-gothic-%s-%s---%d-------",
"-adobe-symbol-medium-r-
--%d-------"))
grDevices::pdf.options(family="Japan1GothicBBB")
grDevices::ps.options(family="Japan1GothicBBB")
}
)

attach(NULL, name = "JapanEnv")
assign("familyset_hook",
function() {
winfontdevs=c("windows","win.metafile",
"png","bmp","jpeg","tiff")
macfontdevs=c("quartz","quartz_off_screen")
devname=strsplit(names(dev.cur()),":")[[1L]][1]
if ((.Platform$OS.type == "windows") &&
(devname %in% winfontdevs))
par(family="sans")
if (capabilities("aqua") &&
devname %in% macfontdevs)
par(family="sans")
},
pos="JapanEnv")
setHook("plot.new", get("familyset_hook", pos="JapanEnv"))
setHook("persp", get("familyset_hook", pos="JapanEnv"))

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?