ggplot2 问题:图形文本显示有奇怪的 unicode 块

ggplot2 issue: graph text shown with weird unicode blocks

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

# 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()

生成的图形如下所示,其中文本以 weir unicode 块显示:

ggplot2 图表有文本问题

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

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

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

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

平台:linux薄荷x86_64

康达环境


编辑:For anybody who is interested in solving this issue permanently look here。我必须升级到 R 版本 4.0.3 才能使 ggplot 再次正常工作。

尝试通过更改文本大小以及文本的颜色和主题来解决问题?也许这会奏效……像这样:

ggplot(data, aes(x=xValue, y=yValue)) +
geom_line() + theme(text = element_text(size=20))

这看起来很像字体问题。也许默认的 ggplot 字体没有安装或损坏?尝试查询已安装的字体(Linux):

system("fc-list")

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

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

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

theme_set(theme_gray(base_family = "DejaVuSerif"))

如果这个returns结果一样,再试一个。