【问题标题】:ggplot2 legend title not respecting bold for Google Fontggplot2 图例标题不尊重 Google 字体的粗体
【发布时间】:2020-09-27 23:09:20
【问题描述】:

不知道为什么,但是当我使用 showtext::font_add_google 导入“Montserrat”字体时,图例标题不会是粗体:/

require(showtext);require(ggplot2)

font_add_google(name="Montserrat")
ggplot(mpg,aes(cty,hwy,fill=manufacturer))+geom_point()+
theme(text=element_text(family="Montserrat"),legend.title=element_text(face="bold"))

我认为这(部分)有效(尽管没有加粗),因为我在本地安装了蒙特塞拉特。如果我尝试使用尚未安装的字体,即:font_add_google(name="Yesteryear")

我得到这个错误并且没有情节:

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

【问题讨论】:

  • 在我的机器上没有弹出错误。但是我得到了相同的警告,可以通过添加showtext_auto() options("device" = "windows") win.graph(10,10,12) 来解决。见stackoverflow.com/questions/53219980/…
  • 嗯...我是 Mac 用户。我试过使用quartz(),结果不一致。有时它会按预期呈现字体。大多数情况下它什么都不渲染。但我从来没有按照需要将图例标题加粗。

标签: r ggplot2 fonts showtext


【解决方案1】:

正如 Stefan 所指出的,在绘制作品之前添加 showtext_auto()。它在 R Studio 中(在 Mac OS Catalina 下)无法正确渲染,但在 ggsave() 上输出粗体图例

【讨论】:

    猜你喜欢
    • 2013-02-21
    • 2021-03-19
    • 1970-01-01
    • 2020-04-24
    • 1970-01-01
    • 2018-06-22
    • 1970-01-01
    • 2022-01-25
    • 2021-12-10
    相关资源
    最近更新 更多