r语言 - “找不到多边形边缘”与“xkcd”包



我正在尝试使用包"xkcd"制作"xkcd"图。我按照vignette("xkcd-intro")安装了"xkcd"(字体和包(。我只需要添加一个路径font_import否则它会返回错误。

library(extrafont)
download.file("http://simonsoftware.se/other/xkcd.ttf",
  dest="xkcd.ttf", mode="wb")
system("mkdir ~/.fonts")
system("cp xkcd.ttf ~/.fonts")
font_import(path="~/", pattern = "[X/x]kcd", prompt=FALSE)
loadfonts()

我确保字体中列出了"xkcd">

'xkcd' %in% fonts()
TRUE

我安装并导入了软件包"xkcd">

install.packages('xkcd')
require(xkcd)

我尝试了一个简单的情节

ggplot(mtcars, aes(x=mpg,y=wt)) + geom_point() // works fine

ggplot(mtcars, aes(x=mpg,y=wt)) + geom_point() + theme_xkcd() // Return following error
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 "xkcd"
2: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "xkcd"
3: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "xkcd"
4: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "xkcd"
5: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "xkcd"

你能帮我吗?


我使用的是 Mac OS X

ProductVersion: 10.11.6
BuildVersion:   15G31

我做到了

fonttable()

找出我的其他字体保存在哪里。他们都在/Library/Fonts得救了。所以,我只是简单地移动了我的xkcd.ttf那里

mv ~/.fonts/xkcd.ttf /Library/Fonts/

我必须更正路径的保存位置。为了找出文件的位置,我做了

extrafont:::fonttable_file()

然后,我打开了这个文件并更改了xkcd的路径。它有效!

最新更新