首页 > 解决方案 > Roboto Condensed 和 PDF 设备

问题描述

我一直在尝试使用pdf()R 中的 pdf 设备(即 )来导出我正在使用hrbrthemes包的绘图,但没有成功。我知道我可以cairo_pdf毫无问题地使用,但我对 pdf 支持的一些功能感兴趣,例如colormodelpaper. 我曾尝试删除并重新安装 extrafont 以及删除和重新安装 Roboto Condensed,但均未成功。我正在 Windows 系统中尝试此操作。

library(extrafont)
library(ggplot2)
library(hrbrthemes)

fonts()
fonts()[grep("Roboto", fonts())]
#[1] "Roboto"

import_roboto_condensed()
fonts()[grep("Roboto", fonts())]
# [1] "Roboto"           "Roboto Condensed"

ggplot(mtcars, aes(mpg, hp)) +
  geom_point() +
  theme_ipsum_rc() +
  labs(
    x = "Miles per gallon",
    y = "Horsepower",
    title = "Using so much gas",
    subtitle = "A bunch of cars"
  )

ggsave("mypdf.pdf")
# This create a pdf with no text and also gives the following error:
# Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y,  : 
#   invalid font type

ggsave("mypdf_cairo.pdf", device = cairo_pdf)
# This works but cairo does not seem to support some features like colormodel (i.e., cmyk) and paper.

loadfonts()
# More than one version of regular/bold/italic found for Roboto Condensed. Skipping setup for this font.

标签: rfonts

解决方案


推荐阅读