【发布时间】:2017-05-15 18:34:59
【问题描述】:
假设我有一个这样的数据集:
dat <- data.frame
text = c(
"It made me feel very positive to brand X",
"It was clear and easy to understand",
"I didn't like it al all"),
value=runif(3)
)
我可以使用 extrafonts 包中的 TradeGothic LT CondEighteen 字体在 ggplot 中绘制它:
library(ggplot2)
p <- ggplot(dat, aes(text, value)) +
geom_bar(stat="identity") +
coord_flip() +
labs(title=" Do you agree with the following statements?")+
theme_bw(16)+
theme(text=element_text(family="TradeGothic LT CondEighteen"))
ggsave('plot.pdf', plot = plot, path = "/Users/jacobdeecurtis/Desktop")
但是当我在情节上使用ggplot_gtable时:
gt <- ggplot_gtable(ggplot_build(plot))
gt$layout[which(gt$layout$name == "title"), c("l", "r")] <- c(1, max(gt$layout$r))
grid::grid.draw(plot)
ggsave('plot.pdf', plot = plot, path = "/Users/jacobdeecurtis/Desktop")
运行 grid.draw 函数后出现错误。错误是:
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 "TradeGothic LT CondEighteen"...
当我不使用 TradeGothic LT CondEighteen 字体时,我没有收到错误消息。
感谢您的帮助!
【问题讨论】:
-
试试
"TradeGothic LT CondEighteen" -
有趣。这不是我试过的吗?有什么不同?
-
你做了
extrafont::loadfonts()吗? -
是的,我做到了。而且,我的意思是,字体有效。只有当我尝试使用 grid.draw() 时它才会中断。