nicholasehamilton / ggtern

Extension to ggplot2 for plotting ternary diagrams
www.ggtern.com
55 stars 14 forks source link

Possible bug in interpolation? #47

Open ugroempi opened 3 years ago

ugroempi commented 3 years ago

Hi Nick, thanks for providing ggtern. I have tried to use it for visualizing a 3D Dirichlet density with the code below. The behavior of the function should be completely symmetric with respect to the three variables. However, the code produces a non-symmetric picture. (Swapping variable names x1 and x3 leaves the anomality between x1 and x2, so it must be the interpolation that does this.) To me, this looks like a bug in the interpolation behavior. Or am I doing something wrong? Best, Ulrike

`require(gtools) require(ggplot2) require(ggtern)

x1 <- c(0.0001, seq(0.01,0.99,0.01), 0.9998) x2 <- c(0.0001, seq(0.01,0.99,0.01), 0.9998) x3 <- c(0.0001, seq(0.01,0.99,0.01), 0.9998)

mat <- as.matrix(expand.grid(x1,x2,x3)) colnames(mat) <- c("x1","x2","x3") mat <- mat[rowSums(mat)==1,] dichte <- gtools::ddirichlet(x=mat, rep(0.5,3)) mat <- as.data.frame(cbind(100*mat, dichte=dichte)) ggtern(data=as.data.frame(mat), aes(x=x1,y=x2,z=x3, value=dichte)) + stat_interpolate_tern(method = "loess", bins=2000) `