I have an arranged plot (using ggpubr::ggarrange
) containing a LaTeX expression (math symbol for "times") in the title.
Consider the following code:
# install.packages("ggplot2)
# install.packages("latex2exp)
# install.packages("ggpubr)
data("midwest", package = "ggplot2")
# Scatterplot
gg <- ggplot(midwest, aes(x=area, y=poptotal)) +
geom_point(aes(col=state, size=popdensity)) +
geom_smooth(method="loess", se=F) +
xlim(c(0, 0.1)) +
ylim(c(0, 500000)) +
labs(subtitle="Area Vs Population",
y="Population",
x="Area",
title="Scatterplot",
caption = "Source: midwest") + ggtitle(TeX("A \u00D7 B")) + theme(plot.title = element_text(family = "LM Roman 10"))
arranged <- ggpubr::ggarrange(gg, gg)
ggsave("./test.pdf")
This throws the error Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, : invalid font type
(if I remove the Tex(...)
, it works fine.
Does anyone know how to achieve the symbol in the desired font in an arranged plot? Many thanks!