LoginSignup
26
25

More than 5 years have passed since last update.

ggplot2 でプロット領域が文字化け(豆腐化)する(Mac)

Last updated at Posted at 2016-08-04

ggplot2 で日本語を使う場合は、基本的にコマンドの最後に theme_gray(base_family = "HiraKakuPro-W3") を加えれば良いが、プロット領域に日本語を表示しようとすると化けることがある。

soy <- read.csv
  ("http://web.ias.tokushima-u.ac.jp/linguistik/Book1.csv", fileEncod = "CP932")

library ("ggplot2")
ggplot (soy, aes (x = soy, y = source)) +  
   geom_text(aes(label = city)) +
   xlab("醤油") + ylab ("ソース") +
   ggtitle ("醤油とソースの消費量") + 
   geom_smooth(method = "lm") +
   theme_gray (base_family = "HiraKakuPro-W3")

soy1.png

これは geom_text() に明示的にfamilyを指定しないといけないようである。多分。

ggplot (soy, aes (x = soy, y = source)) +  geom_text(aes(label = city), size = 6, family = "HiraKakuPro-W3") +
  xlab("醤油") + ylab ("ソース") + 
  ggtitle ("醤油とソースの消費量") + 
  geom_smooth(method = "lm") + 
  theme_gray (base_family = "HiraKakuPro-W3")

soy2.png

徳島と岡山って、ソースを何に使っているのよ?

26
25
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
26
25