Plot ternary data in R with a color map

I am trying to produce a ternary plot in R with a color bar as a legend, similar to the one shown here. I am using the Ternary package, but I am getting an error when running my sample code: Error in values["z", ] : subscript out of bounds. Is there a better package or an alternate approach to produce this plot?

Yes, there is an alternate package called ggtern which can be used to produce ternary plots with a color bar as a legend. Here is some sample code to get you started:


# Create dummy data
df <- data.frame(x = c(0.1, 0.4, 0.5),
                 y = c(0.6, 0.2, 0.2),
                 z = c(0.3, 0.4, 0.3),
                 group = c("A", "B", "C"))

# Create the plot
ggtern(data = df, aes(x = x, y = y, z = z, fill = group)) +
  geom_point() +
  scale_fill_manual(values = c("red", "blue", "green")) +
  theme_bw() +
  theme(legend.position = "bottom")

This should produce a ternary plot with a color bar legend at the bottom.