1

I'm relatively new to this so possibly a duplicate question but I am trying to use library tikzDevice to add a ggplot figure to a LaTeX document as per this guidance: http://iltabiai.github.io/tips/latex/2015/09/15/latex-tikzdevice-r.html

This is my code:

tikz('Figure_1.tex', width = 3.5, height=3)
Figure_1 <- ggplot(data=data, aes(x=Year, y=Numbers2, fill=Level, label = Numbers2)) + 
geom_col()
print(plot)
device.off()

But then when I look at the Figure_1.tex document, all it says is

% Created by tikzDevice version 0.12 on 2018-07-23 15:28:19
% !TEX encoding = UTF-8 Unicode

And there is no code there. How can I ensure that the outputted .tex file contains the aforementioned figure but in vectorized format?

3

Your code produces not only no usable output file, but also error messages. This should be a clear warning that something is wrong. Anyway, the following works:

library(tikzDevice)
library(ggplot2)
y <- exp(seq(1,10,.1))
x <- 1:length(y)
data <- data.frame(Year = x, Numbers2 = y, Level = 1)

tikz('Figure_1.tex', width = 3.5, height=3)
Figure_1 <- ggplot(data=data, aes(x=Year, y=Numbers2, fill=Level, label = Numbers2)) + 
  geom_col()
print(Figure_1) # you *have to* print the object you created
dev.off() # not device.off()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.