Search code examples
rplot3ddirichlet

Having trouble with Dirichlet 3d plot


I'm trying to create a 3D plot of a random draw from a Dirichlet distribution but it only seems to be plotting in 2 dimensions even though I have data for three variables.

draw <- rdirichlet(100, alpha = c(.3,.4,.3))
scatter3D(x ,y, z)
scatterplot3d(draw[,1:3])

As you can see, I tried in two ways, using two different packages. In the first, you can see in the image below that they y-values seem to be missing, but I'm not sure why. enter image description here

When I try using a different package, not only are the y-values missing, but the other two values are plotted as if they are on a 45 degree line, which is not correct. Any help is greatly appreciated! enter image description here


Solution

  • The y-values are not missing. In your case, a Dirichlet distribution of order 3 will have points that lie on a 2-dimensional simplex (i.e. a 2d plane), since the coordinates for each point must sum to 1. (The pdf plots on the Wikipedia page may be helpful to see this.)

    In your second plot, the points are not actually on a 45-degree line (they just look like it). The interactive 3d plot from the rgl package may be helpful to see this.

    draw <- gtools::rdirichlet(100, alpha = c(.3, .4, .3))
    rgl::plot3d(draw)
    

    A plot that looks like this:

    enter image description here

    actually has points on a 2d-simplex, which you can see if you rotate it:

    enter image description here