Elizabeth Buckwalter
Elizabeth Buckwalter

Reputation: 968

What words go in the id_just flag of ternaryplot from the vcd package

The id_flag help section only says c("center", "center"). I'm trying to figure out how to get the label above the dots representing the data points. As it is currently, they is below and overlap the outside labels rendering it unreadable.

feldspars <- data.frame(or=c(41, 94), Al=c(53, 4.6), An=c(4.3,0.7))
ternaryplot( feldspars, 
         scale = 100, 
          pch = 19, 
         cex = 0.4, 
        dimnames = c("Orthoclase", "Albite", "Anorthite"),
        labels = c("outside"),
        main = "Feldspars: Samples 24b and 41",
        id = c("MS-13-24b", "MS-14-41"),
        id_just = c("right", "center")
      )

Any ideas? I've tried right, left, up, down, top, bottom, these words all failed. I've googled for the manual, and I even tried finding the code.

Thanks in Advance.

Upvotes: 1

Views: 89

Answers (2)

IRTFM
IRTFM

Reputation: 263451

Points to Henrik who did the hard work:

 ?grid::grid.text

"The justification of the text relative to its (x, y) location. If there are two values, the first value specifies horizontal justification and the second value specifies vertical justification. Possible string values are: "left", "right", "centre", "center", "bottom", and "top". For numeric values, 0 means left alignment and 1 means right alignment."

Upvotes: 0

Henrik
Henrik

Reputation: 67818

The basic position of the id:s (i.e. under the points) seems hard-coded. If you type ternaryplot in the R console you see the code:
function (x, scale = 1, dimnames = NULL, dimnames_position = c("corner",

...lots of code...

In the last grid.text section, you find that id_just is used as values for the just argument:

if (!is.null(id)) grid.text(x = xp, y = unit(yp + 0.015, "snpc") - 0.5 * size, label = as.character(id), just = id_just, gp = gpar(col = id_color, cex = cex))

For a better description than in ?ternaryplot of possible values of id_just, see ?grid.text.

If you change the "-" in y = unit(yp - 0.015, "snpc") to a "+", save the edited function and set id_just to c("left", "bottom") the labels looks like this: enter image description here

Upvotes: 1

Related Questions