3
votes

Is there anyway of connecting observations in ggtern by a straight line between each consecutive point? My code is:

require(ggtern)    

x  <- data.frame(
      A = c( 0, 0, 1, 0.1, 0.6, 0.2,0.8,0.33 ),
      B = c( 0, 1, 0, 0.3, 0.2, 0.8, 0.1,0.33),
      C = c( 1, 0, 0, 0.6, 0.2, 0.0, 0.1,0.33)
    )


    ggtern(data=x,aes(A,B,C)) + 
        geom_point(fill="blue",type="l",shape=21,size=2) 
          theme_classic() )
1
you can play with the geom_segment() function. I have no idea how your data is ordered but this will include lines between arbitrary points. aa <- ggtern(data=x,aes(A,B,C)) + geom_point(fill="blue",type="l",shape=21,size=2)+ theme_classic() aa + geom_segment(aes(x=x[1:4,1],xend=x[5:8,1],y = x[1:4,2],yend=x[5:8,2],z=x[1:4,3], zend=x[5:8,3]),col=2) Roman
@Jimbou is there a way to keep them in order?connexing x[1:3,1] to x[1:3,2], and then x[1:3,2] to x[1:3,3] and so on without having to specify each line?WeakLearner
I'm not sure I understood the problem. But when you want to connect point 1 (x=x[1,1],y= x[1,2],z=x[1,3]) with point 2 (x=x[2,1],y= x[2,2],z=x[2,3]) and then to point 3 (x=x[3,1],y= x[3,2],z=x[3,3]) and so on, you can use i=seq(1,7,2) ; aa + geom_segment(aes(x=x[i,1],xend=x[(i+1),1],y = x[i,2],yend=x[(i+1),2],z=x[i,3], zend=x[(i+1),3]),col=2)Roman
Have you tried geom_path(...)jlhoward

1 Answers

4
votes

geom_path(...) connects the points in order.

ggtern(data=x,aes(A,B,C)) + 
  geom_path(color="green")+
  geom_point(type="l",shape=21,size=8) +
  geom_text(label=seq(nrow(x)), color="red")+
  theme_classic() 

I changed the size and shape of the points and added labels just to show that they are connected in order.