# Minimizing gaps around graphs when using tikzDevice in R

I am using `tikzDevice`

in R to write code `tikz`

for placing graphs in LaTeX documents. I found that there is a gap around the plots i.e. The margin is usually excessive.

Below is a minimal example of exporting an R chart as tikz code:

```
x <- seq(30, 70)
probs <- dbinom(x, size=100, prob=0.5)
library(tikzDevice)
tikz('binomial.tex', standAlone = T, width=3, height=2.5)
barplot(names.arg=x, probs, cex.names=0.6, cex.axis=0.6)
dev.off()
```

Running `pdflatex binomial.tex`

it gives a small pdf file, where, as you can see, there are a lot of spaces in the margins. Ideally, I would like there to be no spaces at all under the x-axis point labels, or to the left of the y-axis point labels, etc.

By the way, when pasting into a LaTeX document, I will always use `standAlone=F`

in the command `tikz`

above and then use `\input{binomial}`

in the document. There is no difference in space, which is easy to check with `\framebox{\input{binomial}}`

. It also `par(xaxs='i')`

doesn't matter.

Does anyone still know where I can remove all the spaces from the fields of these parcels?

source to share