Китайские иероглифы не могут правильно отображаться после добавления theme_void () в ggplot2 - PullRequest
0 голосов
/ 16 июня 2020

Для набора тестовых данных следующим образом:

df <- data.frame(x = rep(c(1, 2), 3),
                 type = rep(c("甲级", "乙级"), 3),
                 country = rep(c("日本", "德国", "韩国"), each = 2),
                 count = c(19419, 1132, 8138, 947, 8349, 436))

Я нарисовал график полукругов с кодом ниже под Ma c OS system:

ggplot(df, aes(x=x, y=sqrt(count), fill=type)) + geom_col(width =1) +
  scale_x_continuous(expand = c(0, 0), limits = c(0.5, 2.5)) +
  scale_y_continuous(expand = c(0, 0)) +
  coord_polar(theta = "x", direction = -1) +
  facet_wrap(~country) +
  theme_grey(base_family = "STKaiti" )

Out:

enter image description here

Но после добавления theme_void(), чтобы сделать график более чистым, китайский иероглиф отображался некорректно.

ggplot(df, aes(x=x, y=sqrt(count), fill=type)) + geom_col(width =1) +
  scale_x_continuous(expand = c(0, 0), limits = c(0.5, 2.5)) +
  scale_y_continuous(expand = c(0, 0)) +
  coord_polar(theta = "x", direction = -1) +
  facet_wrap(~country) +
  theme_grey(base_family = "STKaiti" )+
  theme_void()

Out:

enter image description here

Кто-нибудь знает, почему это происходит и как решить эту проблему? Спасибо.

1 Ответ

2 голосов
/ 16 июня 2020

Добавьте шрифт в строку theme_void:

ggplot(df, aes(x=x, y=sqrt(count), fill=type)) + geom_col(width =1) +
  scale_x_continuous(expand = c(0, 0), limits = c(0.5, 2.5)) +
  scale_y_continuous(expand = c(0, 0)) +
  coord_polar(theta = "x", direction = -1) +
  facet_wrap(~country) +
  # theme_grey(base_family = "STKaiti" )+
  theme_void(base_family = "STKaiti")
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...