tikz
code renders properly when an Rmarkdown file is rendered in PDF format (which makes sense). In order to make it work in an HTML file, it is required to put the code in an R chunk with the additional option engine = "tikz"
for it to work.
I am trying to generate a plot using the pgfplots
package. Just like tikz
, it generates plots when the .Rmd file is rendered in PDF format, but there does not seem to be any engine option to make it work in HTML format as engine = "tikz"
produces an error.
Is there a way to produce pgfplots
visualizations in an Rmarkdown file knit as an HTML file?
My minimal reproducible example:
---
title: "Hello World"
author: "Me"
date: "February 17, 2015"
output: html_document
header-includes:
- \usepackage{tikz}
- \usepackage{pgfplots}
---
## TikZ picture
- Here is a TikZ picutre
\begin{tikzpicture}
\draw (0,0) circle (2cm);
\end{tikzpicture}
- Here is another TikZ picutre
\begin{tikzpicture}
\begin{axis}[xmax=9,ymax=9, samples=50]
\addplot[blue, ultra thick] (x,x*x);
\addplot[red, ultra thick] (x*x,x);
\end{axis}
\end{tikzpicture}