I am using R Markdown to create a pdf document. I would like to use the modelplot() function included in the modelsummary package to show the model estimates and standard errors in a figure, but if the legend of the figure contains Japanese characters, it will be garbled. The official documentation did not mention how to handle Japanese. What can I do to solve this problem? The figure and code below are reproduced using sample data.
model <-
list(
`モデル1` = lm(mpg ~ ., data = mtcars),
`モデル2` = lm(Sepal.Length ~ ., data = iris)
)
modelplot(model)
Here is the basic configuration of yaml that I have set up for the Japanese typesetting of the text.
output:
pdf_document:
dev: cairo_pdf
latex_engine: xelatex
documentclass: bxjsarticle
classoption: xelatex,ja=standard,a4paper,jafont=ms
header-includes: |
\usepackage{zxjatype}
Also, to output diagrams using ggplot2, the following settings are described. If you include this setting, figures using ggplot2 will be output without garbling, but only if you use modelplot().
library(fontregisterer)
library(systemfonts)
family_sans <- "MS Gothic"
family_serif <- "MS Mincho"
theme_set(
theme_classic() +
theme(
text = element_text(family = family_serif, face = "plain"),
title = element_text(face = "plain"),
axis.title = element_text(face = "plain"),
axis.title.x = element_text(face = "plain"),
axis.title.y = element_text(face = "plain")
)
)