ggplot无法更改文本的字体

时间:2019-02-20 12:04:30

标签: r ggplot2 fonts

我正在创建图表,想要更改标题和副标题的字体。

我希望标题为Futura粗体,而副标题为Futura Plain。

# Get the mtcars dataset to create some example plots
data(mtcars)
df <- mtcars[, c("mpg", "cyl", "wt")]
# Convert cyl to a factor variable
df$cyl <- as.factor(df$cyl)
# Plot
ggplot(data = mtcars, aes(x = wt, y = mpg)) + 
  geom_point() +
  ggtitle('Basic Scatter Chart', subtitle = 'New ggplot theme') +
  theme(
    # Set title 
    plot.title = ggplot2::element_text(family='Futura',
                                       size=20,
                                       face='bold',
                                       color="#222222"),
    plot.subtitle = ggplot2::element_text(family= 'Futura',
                                          face='plain',
                                          size=16,
                                          margin=ggplot2::margin(9,0,9,0)))

这给了我以下错误:

Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  : 
  polygon edge not found
In addition: Warning messages:
1: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "Futura"
2: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "Futura" 

如果我将face参数从Plain更改为粗体,则该绘图有效,因此似乎R找不到Futura字体的Plain变体。当我查看字体书时,可以看到中等,中等斜体,粗体。

对于其他与正面兼容的字体(例如Helvetica),它们在字体簿中有一个常规变体。

如何纠正此问题以使Futura的普通变体正常工作?我不仅可以在R中将媒体分配给普通吗?

1 个答案:

答案 0 :(得分:0)

似乎您没有安装futura字体。可能您必须先安装并将其导入R。

也看看here

相关问题