假设我有一个这样的数据集:
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)
)
我可以使用包中的TradeGothic LT CondEighteen字体在 ggplot 中绘制它extrafonts
:
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字体时,我没有收到错误消息。
谢谢你的帮助!