appliedepi / epiRhandbook_jp

Other
7 stars 7 forks source link

Font with ggplot2 #2

Open babayoshihiko opened 2 years ago

babayoshihiko commented 2 years ago

On some system+setup, ggplot2 fails to producesJapanese (as well as Chinese and Korean) texts. Setting font solves this issues, but available fonts depend on the users OS.

A possible solution:

  1. Check the OS and set font if ncecessary:
  2. Add base_family to theme

The actual code for 1 is:

gis_jfontname <- "sans"
gis_sysinf <- Sys.info()
if (!is.null(gis_sysinf)) {
  if (gis_sysinf['sysname'] == "Darwin") {
    gis_jfontname <- "HiraginoSans-W3"
  }
}

The code for 2: theme_bw(base_family = gis_jfontname)+ # 背景を単純に、フォントは macOS では、"HiraginoSans-W3" など

The base_family is also applied for theme_classic.

In the case of tmap,

  tm_layout(title = "エボラ症例の分布",                    # 地図にタイトルを付ける
            title.fontfamily = gis_jfontname)              # フォントは macOS では、"HiraginoSans-W3" など
hitomik723 commented 2 years ago

Hi @babayoshihiko

Thank you for sharing the issue and presenting the solution! We definitely need to mention that in the Japanese version, but at this point, we would like to complete the translation first.

As our primary objective is to finish the translation as the book is written, it would be better not to translate/modify R code at this point, which means that we don't translate titles, label names or variable name for now since it requires to modify the datasets. After we complete the translation, we'll implement revisions including of localization of the data and code. (Maybe we can mention this font issue in the first chapter? We can discuss this later!)

Thanks again for your support!

Tagging @nsbatra for awareness