rgl does not find font family - r

I face a strange issue with R and package rgl on my Desktop Ubuntu 14.04. While on my laptop with Ubuntu 12.04
title3d(xlab="Mean Market 1", pos=c(1,0,0), col="black",adj=c(0.8,0.8),
family="Times", cex=1.1)
works perfectly, I get a warning message
font family "Times" not found, using "bitmap"
on my desktop pc. Plotting works, but titles are pretty small. If I check
names(X11Fonts())
# [1] "serif" "sans" "mono" "Times" "Helvetica"
# [6] "CyrTimes" "CyrHelvetica" "Arial" "Mincho"`
but none works. I installed freetype2 package, reinstalled rgl package but the warning is still there. I tried sans font etc., as well.

Carsten Oppitz,
I experienced the same issues that you mention above in my computer with Ubuntu 14.04. After searching for fixing them for a long time and nothing worked, the instructions below, copied from http://www.smnd.sk/kotanyi/index.php?page=rgl, did work perfectly:
a) Terminal, check that you have GNU version >= 3.80:
make -v
b) Download FreeType from: https://sourceforge.net/projects/freetype/files/ e.g. latest version.
c) Extract the downloaded file, enter in the directory where it is saved and type in:
./configure
make
sudo make install
d) Still need to rebuild rgl in R: download its source code from the link appearing in the first link above; without extracting the file, type in:
R CMD INSTALL name_of_archive.tar.gz
e) Enjoy any text size (that R supports) in plot3d objects.

You can only really count on "serif", "sans", "mono" and "symbol", unless you've used rglFonts to install additional Freetype font files. So "Times" should be "serif".

Related

how do I fix plot problem with R in Jupyter notebook? [duplicate]

My R was installed in a conda environment on Ubuntu 20.04.1 VM.
I was searching for this problem when i found this thread. I too am using RStudio from Anaconda, on Debian 10.0 (buster).
Try
par(family = "Arial")
or whichever font name before calling plot(). It worked for me.
Update > I still had problems with ggplot2 plots not displaying labels, like above. I tried the workaround of using showtext() instead of regular text rendering.
install.packages("showtext")
After it was installed,
library(showtext)
to load the library. Then simply call
showtext_auto()
followed by the ggplot(.....) + ... + etc. function and text was rendered alright within the plot. I did not load specific fonts using font_add(). Maybe because previously 'Arial' was loaded with par()

GhostScript was not found with extrafont

I'm using an M1, Big Sur Macbook. I need to embed the fonts of a number of pdfs that include plots from ggplot2.
However, when I run the embed_fonts() function, it returns the following error message: GhostScript was not found
With Homebrew, I installed Ghostscript. I have also reinstalled extrafont and extrafontdb, restarted RStudio, and then run font_import() and loadfonts() again. None of this solves the error message.
Have you experienced this problem? I wonder if it's because of the change to the M1's Apple Silicon?
I have also switched from using bash to zsh in my terminal. Could that have affected this?
A reprex:
library(ggplot2)
library(extrafont)
(plot <- ggplot(cars, aes(x = speed, y = dist)) +
geom_point())
ggsave("test_plot.pdf", plot)
embed_fonts(file = "test_plot.pdf", outfile = "test_plot_embedded.pdf")
I found the following two answers that seem related, but I'm unsure how to implement them:
How to fix "Unable to find GhostScript executable to run checks on size reduction" error upon package check in R?
R does not recognize GhostScript to embed eps plots
My issue was solved when I installed Ghostscript directly https://pages.uoregon.edu/koch/ (Ghostscript 9.54.0)
It appears there was, at least on my end, an issue using homebrew install ghostscript. When I ran that in Terminal, everything appeared to be fine. No error messages.

Why do Greek letters fail to render in R's (v4) PDF output?

I am trying to export a simple plot to PDF from R, with a Greek letter, like this:
cairo_pdf("test.pdf")
barplot(1, main = "\u03C1")
dev.off()
I am on an OpenSUSE LEAP 15.1 system with R 3.5 preinstalled - this works fine. So the necessary fonts must be installed.
However, in R 4.0.3 (which I compiled myself), the same command yields a box instead of the Greek letter:
(Interestingly, copy-and-pasting this box inserts the correct Greek letter.)
Is this a fundamental difference between R v3 and v4 (if so, which one?), or can I influence this during compilation? I do not have the same problem on Windows, but this is a release version which I did not compile myself and which has ICU capabilities.
Looking at the PDF files, the v3 file uses Cantarell-Regular and SourceCodePro-Bold. The v4 one uses Cantarell-Regular and Cantarell-Bold. All fonts are subset-embedded. So somehow, R v4 seems to fail switching to that SourceCodePro font, although it is installed:
> fc-list | grep SourceCodePro
/usr/share/fonts/truetype/SourceCodePro-Medium.otf: Source Code Pro,Source Code Pro Medium:style=Medium,Regular
/usr/share/fonts/truetype/SourceCodePro-Regular.otf: Source Code Pro:style=Regular
/usr/share/fonts/truetype/SourceCodePro-Bold.otf: Source Code Pro:style=Bold
/usr/share/fonts/truetype/SourceCodePro-Black.otf: Source Code Pro,Source Code Pro Black:style=Black,Regular
/usr/share/fonts/truetype/SourceCodePro-BoldIt.otf: Source Code Pro:style=Bold Italic
/usr/share/fonts/truetype/SourceCodePro-Semibold.otf: Source Code Pro,Source Code Pro Semibold:style=Semibold,Regular
/usr/share/fonts/truetype/SourceCodePro-ExtraLightIt.otf: Source Code Pro,Source Code Pro ExtraLight:style=ExtraLight Italic,Italic
/usr/share/fonts/truetype/SourceCodePro-BlackIt.otf: Source Code Pro,Source Code Pro Black:style=Black Italic,Italic
/usr/share/fonts/truetype/SourceCodePro-LightIt.otf: Source Code Pro,Source Code Pro Light:style=Light Italic,Italic
/usr/share/fonts/truetype/SourceCodePro-MediumIt.otf: Source Code Pro,Source Code Pro Medium:style=Medium Italic,Italic
/usr/share/fonts/truetype/SourceCodePro-It.otf: Source Code Pro:style=Italic
/usr/share/fonts/truetype/SourceCodePro-SemiboldIt.otf: Source Code Pro,Source Code Pro Semibold:style=Semibold Italic,Italic
/usr/share/fonts/truetype/SourceCodePro-Light.otf: Source Code Pro,Source Code Pro Light:style=Light,Regular
/usr/share/fonts/truetype/SourceCodePro-ExtraLight.otf: Source Code Pro,Source Code Pro ExtraLight:style=ExtraLight,Regular
In the R configure command, I see
Capabilities skipped: ICU
where ICU = International Components for Unicode. Also:
checking whether pkg-config knows about cairo and pango... no
checking whether pkg-config knows about cairo... yes
Could one of these two be related?
Edit: I have found and read Changes to Symbol Fonts for Cairo Graphics Devices, yet
cairo_pdf("test.pdf", symbolfamily = cairoSymbolFont("Courier", usePUA = FALSE))
barplot(1, main = "\u03C1")
dev.off()
as well as
cairo_pdf("test.pdf", symbolfamily = cairoSymbolFont("Courier", usePUA = TRUE))
barplot(1, main = "\u03C1")
dev.off()
produce the same output as above, although
cairo_pdf("test.pdf", family = "Courier")
barplot(1, main = "\u03C1")
dev.off()
successfully changes the standard font, indicating that Courier is installed and usable.
Recompiling with ICU support did not fix this - recompiling with cairo and pango did.
To achieve both, there was lot of trial-and-error installing packages. In summary, I did
zypper in libicu-devel freetype-devel freetype pango-devel pango-tools libpango-1_0-0 harfbuzz-devel fribidi-devel fribidi. Much of that may already have been installed, but in the process, I noticed that the installation of libharfbuzz0 and libharfbuzz-icu0 was broken and fixed that.
Then reconfigured and recompiled R, and the problem was gone.

Text does not show properly in R plot

My R was installed in a conda environment on Ubuntu 20.04.1 VM.
I was searching for this problem when i found this thread. I too am using RStudio from Anaconda, on Debian 10.0 (buster).
Try
par(family = "Arial")
or whichever font name before calling plot(). It worked for me.
Update > I still had problems with ggplot2 plots not displaying labels, like above. I tried the workaround of using showtext() instead of regular text rendering.
install.packages("showtext")
After it was installed,
library(showtext)
to load the library. Then simply call
showtext_auto()
followed by the ggplot(.....) + ... + etc. function and text was rendered alright within the plot. I did not load specific fonts using font_add(). Maybe because previously 'Arial' was loaded with par()

R ggplot2 fonts issue

I'm trying to get the xkcd fonts working in R with ggplot2. However I'm running into some issues.
Here is what I have done so far.
1) Installed the "Humor Sans" font from the xkcd site in the directory ~/.fonts
2) Installed the "extrafont" package. This installation worked smoothly.
3) Load the library
library(extrafont)
However when I try to import the font I get the following error.
> font_import(pattern="Humor Sans")
Importing fonts may take a few minutes, depending on the number of fonts and the speed of the system.
Continue? [y/n] y
Scanning ttf files in /usr/share/fonts/, ~/.fonts/ ...
Extracting .afm files from .ttf files...
Error in data.frame(fontfile = ttfiles, FontName = "", stringsAsFactors = FALSE) :
arguments imply differing number of rows: 0, 1
Any suggestions on what I could be doing wrong or what else I should be doing?
Thanks much in advance
edit: Running ubuntu 12.04
Have you tried:
font_import(paths = "~/.fonts", pattern="Humor Sans")
It does not appear to me that "~/.fonts" is the default font folder for a Mac, so if that is (or is not) your OS, you should include more details when you edit your original question.

Resources