title: How do you create ternary heatmap plots in R?
body: <p>I want to make a triangle plot represents the response surface for all possible combinations of <code>X</code>, <code>Y</code> and <code>Z</code> factors and the gradient area inside the triangle expresses the response variable <code>Gi</code>. The dots represent the ten combinations of <code>X</code>, <code>Y</code> and <code>Z</code> in data frame <code>dt</code>. The correlation between <code>Gi</code> and (<code>X</code>, <code>Y</code>, <code>Z</code>) is defined as <code>mdl &lt;- lm (Gi ~ X*Y*Z)</code>. Here is the data and what I have tried:</p>
  <pre><code>X &lt;- rep(c(.45,.4,.55,.4,.43,.5,.43,.5,.43,.48), each = 3)
  Y &lt;- rep(c(.15, .12,.22,.14,.14,.19,.12, .17,.17,.12 ), each = 3)
  Z &lt;- rep(c(.15,.22,.12,.12,.19,.14,.14,.17,.12,.17), each = 3)
  Gi &lt;- c(353,381,320,312,335,265,394,350,374,320,299,316,300,304,295,360,331,395,351,280,342,299,303,279,374,364,419,306,290,315)
  
  dt &lt;- data.frame (X, Y, Z, Gi)
  ggtern(data = dt, aes(x = X, y = Y, z = Z, value = Gi)) +
    stat_interpolate_tern(geom=&quot;polygon&quot;,
                          formula = value ~ x+y, 
                          method = lm,
                          aes(fill = ..level..), expand = 1) +
    scale_fill_gradient(low=&quot;green&quot;, high=&quot;blue&quot;) +
    geom_point (fill = &quot;white&quot;, size = 3, shape = 21, color = &quot;white&quot;) +
    theme_gray () +
    theme ( tern.axis.arrow.show = T)
  </code></pre>
  <p>However, the output is not what I am looking for. I found an exciting example of a ternary plot heatmap using Python, which is like what I want. However, I am only familiar with R, and I'd like to make something similar. How could I do this in R?</p>
  <p>Please find the <a href="https://www.visitusers.org/index.php?title=Ternary_Plot" rel="nofollow noreferrer">link</a> for the Python code that inspired me.</p>
  <p><a href="https://i.stack.imgur.com/YqfgY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YqfgY.png" alt="enter image description here" /></a></p>