Hi,
A useful package if you want to make drawings in R using the tikzDevice package. Another great tool from Yihui.
Here I show step by step the installation and how to run some simple code in R to create some pdf's with the help of Miktex, tikz and knitr.
Useful document I refered to for minimal tikz commands http://cremeronline.com/LaTeX/minimaltikz.pdf
Requirements:
1. Install Miktex. I go for the 64 bit installer. If you choose the portable one then remember to add the paths to your windows paths.
2. Install Rtools
3. Of course install R and RStudio!!
Installation:
1. Fire up an R Script in RStudio.
2. Run the following code
5. Lets draw the arrow. Refer to tikz documentation by Till Tantau on how to write this
7. Lets clean up and print the pdf out
A useful package if you want to make drawings in R using the tikzDevice package. Another great tool from Yihui.
Here I show step by step the installation and how to run some simple code in R to create some pdf's with the help of Miktex, tikz and knitr.
Useful document I refered to for minimal tikz commands http://cremeronline.com/LaTeX/minimaltikz.pdf
Requirements:
1. Install Miktex. I go for the 64 bit installer. If you choose the portable one then remember to add the paths to your windows paths.
2. Install Rtools
3. Of course install R and RStudio!!
Installation:
1. Fire up an R Script in RStudio.
2. Run the following code
library(knitr)3. Lets plot something first
devtools::install_github( 'yihui/tikzDevice' ) # This is part is required as cran version has a problem when referencing the paths to the Miktex installation
require(tikzDevice)
tikz('normal.tex', standAlone = TRUE, width=5, height=5) # This is a barbone standalone pdf document which will be compiled into normal.pdf. height and width variables control the height and width of the output figure.
plot(cars, main = "Cars data plot")4. Now lets make an arrow pointing to one of the data points in the plot
tikzCoord(10,60, 'beginArrow')x0, y0 coordinate is (10,60). x1,y1 coordinate is (14,60). The 2 coordinates are given a name beginArrow and endArrow so that we can reference it in the Annotation function.
tikzCoord(14,60, 'endArrow')
5. Lets draw the arrow. Refer to tikz documentation by Till Tantau on how to write this
tikzAnnotate(c('\\draw [->] (beginArrow) --(endArrow);'))6. Now how about putting a label on that arrow telling us which coordinate it is
tikzAnnotate(c('\\draw [->] (beginArrow) --(endArrow)',
'node[above left] at (beginArrow) {Coordinate(14,60)};'))
#Close the device
dev.off()
# Compile the tex file
tools::texi2dvi('normal.tex',pdf=T)
# optionally view it:
system(paste(getOption('pdfviewer'),'normal.pdf'))
Comments
Post a Comment