0

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!

Ivo
  • 3,890
  • 5
  • 22
  • 53

1 Answers1

2

The correct way to write the cross product symbol is to use the \times command. You can see a browsable table of supported LaTeX here.

The call to TeX would look like:

... + TeX(r"(A \times B)") + ...

and the output looks like:

plot rendered using ivo's code