Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
8
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

グラフに日本語表示させるための設定

Mac OS X においてグラフに日本語を表示させるためには、フォントの設定を適切をする必要がある。

.Rprofile に下記設定を追記すると、いい感じで日本語を表示させることができる。

.Rprofile
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", "RStudioGD")
       macfontdevs=c("quartz","quartz_off_screen", "RStudioGD")
       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"))
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
8
Help us understand the problem. What are the problem?