1

In the ggtern package in R, I am trying to label the points, however I cannot find a way to position the labels in a way that looks better, I've played around with the position argument in geom_text but no luck.

require(ggtern)    
x  <- data.frame(
    A = c( 0.33, 0.4 ),
    B = c( 0.33, 0.5),
    C = c(0.33,0.1)
)
ggtern(data=x,aes(A,B,C)) + 
    geom_path(color="green")+
    geom_point(type="l",shape=21,size=1) +
    geom_text(label=c("(1/3,1/3,1/3)","(2/5,1/2,1/10)"), color="red")+
    theme_classic()

enter image description here

I'm wondering if anyone has dealt with this issue before?

ROLO
  • 4,183
  • 25
  • 41
WeakLearner
  • 918
  • 14
  • 26

1 Answers1

2

You need the arguments hjust and vjust:

ggtern(data=x,aes(A,B,C)) + 
    geom_path(color="green")+
    geom_point(type="l",shape=21,size=1) +
    geom_text(label=c("(1/3,1/3,1/3)","(2/5,1/2,1/10)"), color="red", hjust=0, vjust=-1)+
    theme_classic()

Parameter position is adjustment to use for overlapping points on this layer, according to the help, so not what you need. For details on hjust and vjust, see this question.

enter image description here

ROLO
  • 4,183
  • 25
  • 41