Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

r - ggplot2 issue: graph text shown with weird unicode blocks

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

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

ggplot2 graph with text issue

enter image description here These unicode blocks look like boxes with four numbers starting with two 0s like:

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

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 version: 3.6.1 (2019-07-05)

platform: linux mint x86_64

conda environment


EDIT: 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.

question from:https://stackoverflow.com/questions/65898007/ggplot2-issue-graph-text-shown-with-weird-unicode-blocks

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...