-1

I have successfully created a ternary plot with the following code:

data <- read.csv(file, header=TRUE)
ternaryplot(data[,3:5], scale = 100, 
    pch = 19, cex = 0.4, col = Category,
    dimnames = c("Al", "Mg", "Fe + Ti"),
    labels = c("outside"),
    main = "")

However, I am struggling to create a legend for it. As the package has assigned colours based on the category of the sample I cannot simply write out the entire legend by allocating colours manually. I have tried a few variations of the following but have encountered the error code:

grid_legend(0.8, 0.9, pch = 19, col = Category, rownames(Category), title = "Categories")

Error in grid_legend(0.8, 0.9, pch = 19, col = Category, rownames(Category),  : 
  pch and labels not the same length

This is the first time I have used the vcd package and would appreciate any help on the subject. Thanks, Holly

Holly Elliott
  • 103
  • 3
  • 10

1 Answers1

0

The error is explicit:

 pch and labels not the same length

So , you should give pch argument with the same length as labels one, replace pch by :

rep(19,nrow(Category))
agstudy
  • 119,832
  • 17
  • 199
  • 261