[R] TikzDevice and texi2dvi
Lorenzo Isella
lorenzo.isella at gmail.com
Tue Apr 27 10:29:30 CEST 2010
I think I solved my problems by resorting to the Ubuntu packages at
http://bit.ly/c8izKy
Cheers
Lorenzo
Dear All,
I am starting to use the tikzDevice package, but I am experiencing some
(minor problems).
If I try to run the script at the end of the email, I get the following
error
Error in tools::texi2dvi("normal.tex", pdf = T) :
Running 'texi2dvi' on 'normal.tex' failed.
Messages:
sh: /usr/bin/texi2dvi: not found
How do I install the missing texi2dvi?
I found some reference to it at
http://bit.ly/bSYbxk
but I have not understood well whether it is should already be part of
my R base installation or not.
I am running R 2.11 on Ubuntu 9.10.
Many thanks
Lorenzo
###############################################à
#Load the tikzDevice package, if you dont have it, install with:
# install.packages("tikzDevice", repos="http://R-Forge.R-project.org")
require(tikzDevice)
# The following wwill create normal.tex in the working
# directory the first time this is run it may take a long time because the
# process of calulating string widths for proper placement is
# computationally intensive, the results will get cached for the current R
# session or will get permenantly cached if you set
# options( tikzMetricsDictionary='/path/to/dictionary' ) which will be
# created if it does not exist. Also if the flag standAlone is not set to
# TRUE then a file is created which can be included with \include{}
tikz('normal.tex', standAlone = TRUE, width=5, height=5)
# Normal distribution curve
x <- seq(-4.5,4.5,length.out=100)
y <- dnorm(x)
# Integration points
xi <- seq(-2,2,length.out=30)
yi <- dnorm(xi)
# plot the curve
plot(x,y,type='l',col='blue',ylab='$p(x)$',xlab='$x$')
# plot the panels
lines(xi,yi,type='s')
lines(range(xi),c(0,0))
lines(xi,yi,type='h')
#Add some equations as labels
title(main="$p(x)=\\frac{1}{\\sqrt{2\\pi}}e^{-\\frac{x^2}{2}}$")
int <- integrate(dnorm,min(xi),max(xi),subdivisions=length(xi))
text(2.8, 0.3, paste("\\small$\\displaystyle\\int_{", min(xi),
"}^{", max(xi), "}p(x)dx\\approx", round(int[['value']],3),
'$', sep=''))
#Close the device
dev.off()
# Compile the tex file
tools::texi2dvi('normal.tex',pdf=T)
# optionally view it:
# system(paste(getOption('pdfviewer'),'normal.pdf'))
More information about the R-help
mailing list