首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用“外挂字体”和“牛仔字体”:字体宽度未知的字符错误

使用“外挂字体”和“牛仔字体”:字体宽度未知的字符错误
EN

Stack Overflow用户
提问于 2020-08-23 15:17:43
回答 1查看 372关注 0票数 0

我试图在ggplot中使用一种只能通过extrafont包的字体。然后,当我想使用cowplot包组合多个绘图时,总是会出现大量的错误:

代码语言:javascript
复制
46: In grid.Call(C_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x65
47: In grid.Call(C_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x63
48: In grid.Call(C_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x69
49: In grid.Call(C_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x65
50: In grid.Call(C_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x73

,注意,,包实际上产生输出(也就是并排的情节),但是错误信息让我担心。

到目前为止我尝试过的是:

使用extrafont::font_install()

  • Loading安装字体的
  • 使用extrafont::loadfonts()

安装字体

我安装了extrafontextrafontdb以及cowplot

这里是我使用的一个例子:

代码语言:javascript
复制
library(tidyverse)
library(extrafont)
library(cowplot)
library(palmerpenguins)
data(penguins)


penguins %>% 
  select(year, flipper_length_mm,species) %>% 
  ggplot(aes(x=year,y=flipper_length_mm,fill=species)) +
  geom_col() + 
  labs(title = "First Plot") + 
  theme(text = element_text(family = "Georgia")) -> plot1


penguins %>% 
  select(year, bill_length_mm,species) %>% 
  ggplot(aes(x=year,y=bill_length_mm,fill=species)) +
  geom_col() + 
  labs(title = "Second Plot") + 
  theme(text = element_text(family = "Georgia")) -> plot2

cowplot::plot_grid(plot1,plot2)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-20 23:38:21

谢谢克劳斯·威尔克在评论中的回答:

设置空设备是必要的。您可能需要安装开发版本才能完全正常工作(对我来说确实很好!)

简短的答案是:

代码语言:javascript
复制
set_null_device(cairo_pdf)
cowplot::plot_grid(plot1,plot2)

错误信息就消失了。使用set_null_device("png")也对我有效,但考虑到我的目标是保存PDF,根据Claus的说法,这是更安全的选择。

全文:

代码语言:javascript
复制
library(tidyverse)
library(extrafont)
library(cowplot)
library(palmerpenguins)
data(penguins)


penguins %>% 
  select(year, flipper_length_mm,species) %>% 
  ggplot(aes(x=year,y=flipper_length_mm,fill=species)) +
  geom_col() + 
  labs(title = "First Plot") + 
  theme(text = element_text(family = "Georgia")) -> plot1


penguins %>% 
  select(year, bill_length_mm,species) %>% 
  ggplot(aes(x=year,y=bill_length_mm,fill=species)) +
  geom_col() + 
  labs(title = "Second Plot") + 
  theme(text = element_text(family = "Georgia")) -> plot2


set_null_device(cairo_pdf)
cowplot::plot_grid(plot1,plot2)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63548647

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档