A user of one of my R-packages reported issues with Chinese characters in titles when creating graphs. The graphs in the package are generated using ggplot2. It seems titles with Chinese characters are not displayed in ggplot in macOS. The same issue even showed up in base-R graphs (see examples below). Any suggestion on how to address this type of issue?
iris_cn <- iris
names(iris_cn) <- c("萼片长Sepal.Length","萼片宽Sepal.Width","花瓣长Petal.Length","花瓣宽Petal.Width","品种Species")
library(ggplot2)
ggplot(data = iris_cn, aes(x = 萼片长Sepal.Length)) + geom_histogram()
Histogram in base-R:
hist(iris_cn$萼片长Sepal.Length)
The user actually posted a "fix" as well, although it required changing the font-family. See below:
library(ggplot2)
theme < -theme_get()
#using the Chinese fonts you have, check it with font book.
theme$text$family <- "STFangsong"
theme_set(theme)
iris_cn <- iris
names(iris_cn) <- c("萼片长Sepal.Length","萼片宽Sepal.Width","花瓣长Petal.Length","花瓣宽Petal.Width","品种Species")
library(ggplot2)
ggplot(data = iris_cn, aes(x = 萼片长Sepal.Length)) + geom_histogram()
