Created
June 27, 2014 12:38
-
-
Save felixlindemann/83722fa4bcaf92b85056 to your computer and use it in GitHub Desktop.
Demo of TIKZDevice (Plot R to Latex)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(tikzDevice) #require this package | |
set.seed(1) # Output will always be the same | |
inch<- 0.3937008 # give units | |
h <- 10 # define height of tikz in cm | |
w <- 10 # define width of tikz in cm | |
td <- getwd() | |
tf<- file.path(td, 'tikz.tex') #set file | |
# tikz(tf,standAlone=TRUE) # if single doc | |
tikz(tf,standAlone=FALSE, height=h*inch , width=w*inch ) # if grapics should be used in an existing document | |
mu <- 0 | |
sd <- 1 | |
r <- rnorm(1000, mu, sd) #create random numbers | |
x<-seq(-3,3,by=0.01) # create sequence | |
hist(r, freq=FALSE, xlab="", | |
main=paste("Histogram of\n1000 random numbers N(",mu,",",sd,")", sep="") | |
) | |
rug(r) | |
lines(density(r), col=2) # draw Kernel-Density | |
lines(x, dnorm(x,mu,sd), col=3, lty=2) #draw density | |
dev.off() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment