tikz - Designing multivariate density plot in R -
i saw appealing multivariate density plot using tikz , wondering if there way replicate plot own data within r. not familiar tikz, found reference seems imply may able use feature within r. http://www.texample.net/tikz/examples/tikzdevice-demo/
in short, best way produce plot similar (different distribution of course) 1 shown below using 2 data samples provided?
here sample data can used create distribution plot.
# sample data var1 <- exp(rlnorm(100000, meanlog=0.03, sdlog=0.15))/100 var2 <- 1-(var1 + rnorm(100000, 0, 0.01))
here reference page found original chart
https://tex.stackexchange.com/questions/31708/draw-a-bivariate-normal-distribution-in-tikz
you start persp
function draw 3 dimensional plot (if data rather formula need use form of density estimation first, example plot looks smooth enough based on formula rather estimated data). use return value persp
project additional plotting info.
there may option using rgl package, seem remember has way project plot onto axes planes.
edit
here sample code started. uses parametric distribution, adapted use kde2d
mass or other ways of estimating density data:
x <- seq( -3, 3, length=25 ) y <- seq( -3, 3, length=25 ) z <- outer( x, y, function(x,y) dnorm(x,0,0.5)*dnorm(y,0,1) ) zl <- c(0,4*max(z)) ## persp plot trmat <- persp(x,y,z, theta=120, zlim=zl, box=false, shade=0.5) ## x grid for( in seq(-3,3, by=0.5 ) ) { lines( trans3d( c(i,i), c(-3,-3), zl, trmat ), col='grey' ) } for( in seq(0,zl[2], length=7) ) { lines( trans3d( c(-3,3), c(-3,-3), c(i,i), trmat ), col='grey' ) } ## marginal x lines( trans3d( seq(-3,3,length=100), -3, dnorm(seq(-3,3,length=100),0,.5), trmat), lwd=2, col='blue' ) ## y grid for( in seq(-3,3, by=0.5 ) ) { lines( trans3d( c(-3,-3), c(i,i), zl, trmat ), col='grey' ) } for( in seq(0,zl[2], length=7) ) { lines( trans3d( c(-3,-3), c(-3,3), c(i,i), trmat ), col='grey' ) } ## marginal y lines( trans3d( -3, seq(-3,3,length=100), dnorm(seq(-3,3,length=100),0,1), trmat), lwd=2, col='blue' )
Comments
Post a Comment