【问题标题】:Trouble with XKCD packageXKCD 包的问题
【发布时间】:2014-04-23 00:04:18
【问题描述】:

我正在尝试开始使用xkcd 包,并按照the vignette 中的说明进行操作。然而,当我到达第 2.2 节“保存图表”时,我得到了一个错误。

代码如下:

font.add("xkcd",  regular = "xkcd.ttf")
p <-  ggplot() + geom_point(aes(x=mpg, y=wt), data=mtcars) + 
  theme(text = element_text(size = 16, family = "xkcd"))
print(p)

这是错误:

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

我错过了什么??

【问题讨论】:

  • 您是否安装了第 2.1 节中描述的字体?
  • 是的!在lot of trouble之后。

标签: r


【解决方案1】:

我在全新安装 MacOS Sierra 时遇到了同样的问题。以下对我有用:

## Perform Once:
## install.packages("xkcd", dependencies=TRUE)
## install.packages("sysfonts")
## library(sysfonts)
## download.file("http://simonsoftware.se/other/xkcd.ttf", dest="xkcd.ttf", mode="wb")
## system("cp xkcd.ttf ~/Library/Fonts")

或者,获取xkcd.ttf 的副本并将其复制到您的本地字体目录(确保它来自您的系统)。如果出现问题并且你所有的 stackoverflow 帖子都只显示问号,那么你的字体就搞砸了。现在转到Font Book 和File --> Restore Standard Fonts。

## Example 1
library("xkcd")
library("ggplot2")
ggplot(data = mtcars, aes(x = mpg, y = wt)) + 
    geom_point() + 
    theme(text = element_text(size = 16, family = "xkcd")) 

【讨论】:

    【解决方案2】:

    经过多次试验和错误,我能够自己让它工作。本质上,您必须将下载的 xkcd.ttf 复制到 fon.paths() 中的所有文件夹中。

    for(dirs in font.paths()) {
    file.copy(file.path(dirs,"xkcd.ttf), "/Users/shambho/library/Fonts/")
    }
    

    它正在工作!

    【讨论】:

    • 从头开始。由于某种原因,我不得不进入 OSX Font Book 并修复字体,然后重新启动。
    猜你喜欢
    • 2010-09-13
    • 2021-12-15
    • 2018-07-11
    • 1970-01-01
    • 1970-01-01
    • 2012-09-23
    • 2014-06-07
    • 2013-11-08
    • 1970-01-01
    相关资源
    最近更新 更多