Skip to content

Instantly share code, notes, and snippets.

@kylebutts
Last active January 24, 2024 16:17
Show Gist options
  • Save kylebutts/9c39de090839eda7fc36b70ee1e0b139 to your computer and use it in GitHub Desktop.
Save kylebutts/9c39de090839eda7fc36b70ee1e0b139 to your computer and use it in GitHub Desktop.
Example of `kfbmisc::tikzsave`
library(ggplot2)
library(kfbmisc)

x = seq(-pi, pi, 0.02)
df = data.frame(x = x, y = sin(x))
p = ggplot(df) + 
  geom_line(aes(x = x, y = y), linewidth = 1.5) + 
  labs(x = "$x$", y = "$\\sin(x)$") + 
  scale_x_continuous(
    breaks = c(-pi, -2, 0, 2, pi),
    labels = c("$-\\pi$", -2, 0, 2, "$\\pi$")
  ) + 
  theme_kyle(base_size = 12)

ggplot -> tikzpicture -> pdf

kfbmisc::tikzsave(
  "sin.tex",
  plot = p, width = 6, height = 4
)

The output looks like: sin

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