Skip to content

Instantly share code, notes, and snippets.

@jonocarroll
Created October 12, 2018 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonocarroll/2b45ac5695bb2777239566a8df759cbf to your computer and use it in GitHub Desktop.
Save jonocarroll/2b45ac5695bb2777239566a8df759cbf to your computer and use it in GitHub Desktop.
tikz image As x-axis
## flags borrowed from
## http://flagpedia.net/
## use LaTeX tikzDevice to render images as x-axis labels
## based on baptiste: https://gist.github.com/baptiste/9505ff4f54b31d1d7149e435faf295f9
library(tikzDevice)
library(ggplot2)
options(tikzLatexPackages = c(getOption("tikzLatexPackages"), "\\usepackage{graphicx}\n"))
d <- data.frame(x = 1:10, y = 1:10)
p <- qplot(x, y, data = d) +
theme_bw() +
labs(x = "") +
theme(axis.text.x = element_text(size = 12 * 0.8,
lineheight = 0.9,
vjust = -5)) +
scale_x_continuous(breaks = c(2, 5, 8),
labels = c("\\includegraphics[scale=0.1]{us.png}",
"\\includegraphics[scale=0.1]{fr.png}",
"\\includegraphics[scale=0.1]{au.png}"))
tikz("xaxis.tex", standAlone = TRUE, width = 4, height = 4)
print(p)
dev.off()
tools::texi2dvi("xaxis.tex", pdf = TRUE)
@jonocarroll
Copy link
Author

screen shot 2018-10-12 at 3 45 31 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment