R - Plotting two bivariate normals in 3d and their contours respectively

后端 未结 1 1598
清歌不尽
清歌不尽 2021-02-03 13:36

I have been playing around with the MASS package and can plot the two bivariate normal simply using image and par(new=TRUE) for example:

# lets first simulate a          


        
相关标签:
1条回答
  • 2021-02-03 14:24

    Perhaps you can use rgl library. It allows you to create interactive 3d plots.

    require(rgl)
    
    col1 <- rainbow(length(bivn.kde$z))[rank(bivn.kde$z)]
    col2 <- heat.colors(length(bivn.kde2$z))[rank(bivn.kde2$z)]
    persp3d(x=bivn.kde, col = col1)
    with(bivn.kde2, surface3d(x,y,z, color = col2))
    

    enter image description here

    If you want to plot difference between two surfaces then you can do something like below.

    res <- list(x = bivn.kde$x, y = bivn.kde$y, z = bivn.kde$z - bivn.kde2$z)
    col3 <- heat.colors(length(res$z))[rank(res$z)]
    persp3d(res, col = col3)
    

    enter image description here

    0 讨论(0)
提交回复
热议问题