使用`xkcd`包找到`多边形边缘'

时间:2018-02-01 00:17:33

标签: r macos ggplot2 fonts installation

我正在尝试制作' 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

1 个答案:

答案 0 :(得分:0)

我做了

fonttable()

找出我保存的其他字体的位置。他们都被保存在/Library/Fonts。所以,我只是把我的xkcd.ttf移到那里

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

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

extrafont:::fonttable_file()

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