1

Is there a way to reproduce the following plot in R?

enter image description here

EDIT

This is what I could do with persp() in base R and plot_ly in plotly. Also a bit ugly.

x <- seq(0,1,0.01) 
y <- seq(0,1,0.01)
f <- function(x,y){ z <- -x - y + 1 }
z <- outer(x,y,f)
z <- ifelse(z<0,NA,z)
persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue")
plot_ly(x=x,y=y,z=z,type="surface") %>% layout(xaxis=list(range=c(0,1)), yaxis=list(range=c(0,1)), zaxis=list(range=c(0,1)))

BTW...the matplotlib plots were obtained here: http://blog.bogatron.net/blog/2014/02/02/visualizing-dirichlet-distributions/

Chris
  • 3,401
  • 5
  • 33
  • 42
  • rgl is good idea. Am struggling with "Error loading rgl package with Mac OS X" at the moment: http://stackoverflow.com/questions/9878693/error-in-loading-rgl-package-with-mac-os-x – Chris Mar 08 '16 at 12:21
  • try installing / updating XQuartz. Altrnatively try to do it in plottly with 3d surface. – Jav Mar 08 '16 at 12:55
  • should be doable with `?persp` and `?trans3d` ... – Ben Bolker Mar 08 '16 at 13:31
  • @BenBolker I played around with this but it [seems](https://stat.ethz.ch/pipermail/r-help/2007-July/137080.html) like getting greek symbols onto axis labels in `persp` is not possible – C8H10N4O2 Mar 08 '16 at 14:01
  • 2
    Unfortunately there is no R function turning equations of surfaces into nice 3d plots. But if you want to reproduce *this* plot looking nicely you don't need any 3d, there is not much about projection or other 3d functionality going on. It's just 6 lines, 4 dots, 6 labels and one transparent polygon, I really doubt there is a simpler presentation. TBH I don't think R is the ideal tool for this - but it certainly can do it. – bdecaf Mar 08 '16 at 15:08

2 Answers2

2

Using persp in base R I was able to get this far:

persp(0:1, 0:1, 
      matrix(c(1,0,0,NA), nrow=2), 
      col="green", theta=60, 
      xlab= "theta_1", 
      ylab = "theta_2", 
      zlab="theata_3")

But I could not figure out how to do a few things, including greek symbols on axes.

I am turning this into a wiki in case any persp experts out there want to finish the job.

C8H10N4O2
  • 18,312
  • 8
  • 98
  • 134
2

This is a little ugly/still incomplete but at least shows one way to get Greek labels in.

pp <- persp(0:1, 0:1, 
      matrix(c(2,0,0,NA), nrow=2), 
      col="green", theta=60, 
      xlab= "",
      ylab ="",
      zlab="",
      ticktype="detailed",
      nticks=1)

text(trans3d(0.5,-0.1,-0.1,pp),labels=expression(theta[1]))
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453