ggplot2在docker的rstudio-server中无法正确显示汉字 [英] ggplot2 doesn't show Chinese character properly in rstudio-server in docker

查看:132
本文介绍了ggplot2在docker的rstudio-server中无法正确显示汉字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用ggplot2绘制带有中文标题的图表,但以正方形显示Unicode.

我尝试了以下一些命令

 石英(family ='STKaiti')par(family ='STKaiti')plot(1,xlab =你好",family =海蒂SC Light") 

并使用额外字体"字体将我的ubuntu字体加载到R中显示的字符图仍然是Unicode正方形.我想正确显示中文单词.

仍然,我不知道该如何称呼这种话."Unicode in a square"是我所能描述的最好的.

解决方案

尝试

I try to use ggplot2 to plot a chart with the Chinese title but shows Unicode in a square.

I've tried some following command

quartz(family='STKaiti')
par(family='STKaiti')
plot(1, xlab = "你好", family = "Heiti SC Light")

and use "extrafont" font to load my ubuntu fonts into R The characters plot shows are still Unicode in a square. I want to show the Chinese word properly.

Still, I have no idea how to call this kind of words. "Unicode in a square" is the best I can describe.

解决方案

Try the showtext package, which was designed for this.

Sample code:

library(ggplot2)
library(showtext)
showtext_auto()

p = ggplot(NULL, aes(x = 1, y = 1)) + ylim(0.8, 1.2) +
    annotate("text", 1, 1, size = 15, label = "你好,世界") +
    xlab("坐标轴") +
    theme_bw(base_family = "wqy-microhei", base_size = 24)

quartz()
print(p)

这篇关于ggplot2在docker的rstudio-server中无法正确显示汉字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆