Say I have a dataset like this:
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)
)
I can plot it in ggplot using can the TradeGothic LT CondEighteen font from the extrafonts
package:
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")
But when I use ggplot_gtable
on the plot:
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")
I get an error once I run the grid.draw function. The error is:
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"...
I don't get the error when I don't use the TradeGothic LT CondEighteen font.
Thanks for your help!
"TradeGothic LT CondEighteen"
– Lemmieextrafont::loadfonts()
? – Lemmie