ggplot2问题:显示带有奇怪的unicode块的图形文本 [英] ggplot2 issue: graph text shown with weird unicode blocks

查看:40
本文介绍了ggplot2问题:显示带有奇怪的unicode块的图形文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了以下问题:当我用ggplot2绘制任何东西时

I have got the following problem: When I plot anything with ggplot2 like this

# Libraries
library(ggplot2)
        
# create data
xValue <- 1:10
yValue <- cumsum(rnorm(10))
data <- data.frame(xValue,yValue)

# Plot
ggplot(data, aes(x=xValue, y=yValue)) +
geom_line()

结果图如下所示,其中文字显示在堰式unicode块中:

The resulting graph looks like this where the text is shown in weir unicode blocks:

ggplot2图形出现文本问题

ggplot2 graph with text issue

这些unicode块看起来像带有以两个0开头的四个数字的框,例如:

These unicode blocks look like boxes with four numbers starting with two 0s like:

# Example block
----
|00|
|2C|
----

我已经尝试更新并重新安装tidyverse软件包,我重新打开R-Studio并仅调用库ggplot2以便没有冲突的软件包打开,我在互联网上找不到任何类似的问题.希望您能为我提供帮助,如果您需要我的更多信息,请不要犹豫.

I already tried to update and reinstall the tidyverse package, I reopened R-Studio and only called the library ggplot2 in order to have no conflicting packages open, I could not find any similar issue on the internet whatsoever. I hope you can help me out and please do not hesitate if you need further information from me.

R版本:3.6.1(2019-07-05)

R version: 3.6.1 (2019-07-05)

平台:linux mint x86_64

platform: linux mint x86_64

conda环境

对于任何有兴趣永久解决此问题的人来说这里.为了使ggplot再次正常工作,我必须升级到R版本4.0.3.

For anybody who is interested in solving this issue permanently look here. I had to upgrade to R Version 4.0.3 in order to make ggplot work properly again.

推荐答案

这看起来很像是字体问题.也许默认的 ggplot 字体未安装或未损坏?尝试查询已安装的字体(对于Linux):

This looks a lot like a font issue. Maybe the default ggplot font is not installed or damaged? Try querying installed fonts (for Linux):

system("fc-list")

输出应该是这样的条目列表:

Output should be a list of entries like this:

/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf: DejaVu Serif:style=Book

然后,您可以将字体设置为 ggplot 主题的默认字体(据我所知,ttf文件的名称是正确的命名方式):

Then you can set the font as a default for your ggplot theme (name of the ttf file is the correct way to name it as far as I can tell):

theme_set(theme_gray(base_family = "DejaVuSerif"))

如果返回的结果相同,请尝试另一个.

If this returns the same result, try another one.

这篇关于ggplot2问题:显示带有奇怪的unicode块的图形文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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