1

I installed an older version of R (4.0.2) from source on my computer following the instruction on https://support.rstudio.com/hc/en-us/articles/215488098-Installing-multiple-versions-of-R-on-Linux and I work with rmarkdown and knitr packages in RStudio for my analyses. I also work with renv package in order to have a more reproducible environment and code.

My problem is that my plots, which are inline, lack the fonts. Here is an example:

I have a table with 2 columns, PT and M and my code is a simple ggplot:

library(ggplot2)

df <- data.frame( "A" = c(1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7),
"M" = c(0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2),
"n" = c(3, 29, 13,  7,  0,  3,  0, 22, 13,  4,  3,  1,  0,  1,  8,  3,  4,  1,  0,  0,  0))

ggplot(data = df, aes(x=A, y=M, size = n)) + 
   geom_point()

enter image description here

I really don't know where the problem comes from: missing package in Linux, problems with R, RStudio or rmarkdown ?

Does someone have an idea ?

SOLUTION

I installed Helvetica.ttf.gz on my ubuntu:

gunzip Helvetica.ttf.gz 
sudo mkdir /usr/share/fonts/truetype/myfonts
sudo mv Helvetica.ttf /usr/share/fonts/truetype/myfonts/.
sudo fc-cache -f -v /usr/share/fonts/truetype/myfonts/
Anoikis
  • 105
  • 1
  • 13
  • Are you from France? Have a Fr locale? Can you add your code to question? – manro Oct 19 '21 at 18:54
  • Yes I am from France and my locale is Fr_UTF8. I added my command line in the question. – Anoikis Oct 22 '21 at 20:16
  • Do you use Linux? – manro Oct 22 '21 at 21:23
  • Yes, Kubuntu 20.04 – Anoikis Oct 23 '21 at 16:52
  • I have a Windows, don't know. Whether could I help to you. Can you give to me a small reproducible example. This font is default or you want to use a custom one? – manro Oct 23 '21 at 17:02
  • The labels are supposed to be default labels, I didn't add custom labels and didn't touch any option regarding labels. I added a simple dataframe in the main question, you can reproduce the code. But, indeed, I think that my problem comes from my locale parameters and the way I installed R but I need this version. – Anoikis Oct 24 '21 at 17:13

1 Answers1

0

Let's try some things.

Test code:

ggplot(diamonds, aes(clarity, fill=cut)) + 
     geom_bar() +
     annotate("text", x = c(1,5,7), y=10000, label = c("un", "deux", "trois")) + 
     ggtitle("Je ne parle pas le français")

Find "Tools -> Global Options -> Appearance" and try to change your editor font to Ubuntu Mono (it is your native OS font).
https://askubuntu.com/questions/97469/what-is-the-default-debian-ubuntu-console-tty-font-called

And say after, what do you see.


Look also there:

R plots: Corrupted/missing characters for devices other than pdf

and there:

rstudio corrupted letter and number in plot

manro
  • 3,529
  • 2
  • 9
  • 22
  • The editor font was already to Ubuntu Mono. I still have the problem of missing fonts with this code. I have to add: I use `renv` to manage packages and try to have a more reproducible environment. I see this problem when using this rmarkdown and renv setup. – Anoikis Oct 25 '21 at 14:08
  • I am not sure. I added some links into the answer. – manro Oct 25 '21 at 14:19