2
0

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.

Ubuntu環境でggsaveすると日本語が文字化けした

Posted at

問題

Rのggplot2を使って作ったプロットを出力しようとすると、以下のようなエラーが出て日本語の部分が...に文字化けすることがある。

> data %>% ggplot(aes(x=x, y=y)) + geom_bar(stat = "identity") +
  geom_text(label = text, check_overlap = T, angle=90) + theme_classic(base_size = 20)
> ggsave("./figures/correlation.pdf", family = "Japan1GothicBBB")
Saving 7 x 7 in image
50 件以上の警告がありました (最初の 50 個の警告を見るには warnings() を使って下さい) 

warnings()を実行してみるとpostscript() デバイス中にフォントファミリ 'Japan1GothicBBB' は含まれていません
とのことで、一見エラーを修正するにはフォントをインストールしなければいけないのかと思ってしまう。

解決法

しかしこの場合は、ggsave側でフォントを指定してやるだけでOK。

ggsave("./figures/correlation.eps", family = "Japan1")

みなさんは僕のようにこの程度の問題に貴重な時間を無駄にすることがありませんように。

2
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?