Ubuntu16.04+R4.0.3使用corto包mraplot绘图报错求助
mraplot (corto Package) on Ubuntu 16.04 + R 4.0.3 Hey there, let's work through this font-related error you're hitting when trying to generate plots with mraplot. The issue boils down to R not being able to locate the Adobe Helvetica font the function is trying to use—this is super common on Ubuntu systems since Helvetica isn't installed by default. Here are actionable fixes to get your plot working:
1. Install System Font Packages
First, install the necessary font libraries and a Helvetica-compatible replacement (Liberation Sans, which R will automatically fall back to):
sudo apt-get update && sudo apt-get install fontconfig libfreetype6-dev fonts-liberation
This ensures your system has the fonts and underlying libraries R needs for rendering text in plots.
2. Configure R to Use Compatible Fonts
You can either set a global font for your R session or explicitly specify it for the plot:
Option A: Use extrafont to Manage Fonts
Install and load the extrafont package to import system fonts into R:
install.packages("extrafont") library(extrafont) # Import Liberation fonts (a drop-in replacement for Helvetica) font_import(pattern = "Liberation") loadfonts(device = "png") # Load fonts specifically for PNG output # Now run your plot code png("mra_datamatneg.png",w=2500,h=3000,res=300) mraplot(mra_datamatneg,mrs=5) dev.off()
Option B: Explicitly Set Font Family in Plot Parameters
If you don't want to use extrafont, set the font family directly before calling mraplot:
# Set the default plot font to Liberation Sans par(family = "Liberation Sans") # Generate your plot as usual png("mra_datamatneg.png",w=2500,h=3000,res=300) mraplot(mra_datamatneg,mrs=5) dev.off()
3. Update System Font Cache
Sometimes R can't pick up newly installed fonts until you refresh the system font cache. Run this in your terminal:
sudo fc-cache -fv
Then restart your R session and try the plot again.
4. Check if mraplot Supports Direct Font Arguments
Take a quick look at the mraplot documentation (?mraplot) to see if it has a family or font parameter. If it does, you can directly pass the compatible font there:
png("mra_datamatneg.png",w=2500,h=3000,res=300) mraplot(mra_datamatneg,mrs=5, family = "Liberation Sans") dev.off()
内容的提问来源于stack exchange,提问作者Juan Manuel Luque

