0

I am trying to triplot some points with some regions in triangular plot this code:

library(ggtern)
g <- data.frame(x=c(1,.6,.6), y=c(0,.4,0), z=c(0,0,.4), Series="Green")
r <- data.frame(x=c(0,0.4,0), y=c(0,0,0.4), z=c(1,0.6,0.6),     Series="Red")
p <- data.frame(x=c(0,0.4,0), y=c(1,0.6,0.6), z=c(0,0,0.4),  Series="Purple")
DATA = rbind(g,r,p)

plot <- ggtern(data=DATA,aes(x,y,z)) +
  geom_polygon(aes(fill=Series),alpha=.5,color="black",size=0.25) +
  scale_fill_manual(values=as.character(unique(DATA$Series))) +
  theme(legend.position=c(0,1),legend.justification=c(0,1)) +
  labs(fill="Region",title="Sample Filled Regions")

print(plot)

I want to add some points to this plot that are taken from text file and I am reading their x,y and z coordinates. How I can these points to the plot?

if I try something like this it delete the previous plot:

plot <- ggtern(data = data.frame(x = cordnate_x, y = cordnate_y, z = cordnate_z),aes(x, y, z)) + geom_point() +theme_rgbg()
print(plot)

This is the plot that I need to add points to it

traingular plot

dww
  • 30,425
  • 5
  • 68
  • 111
user4544869
  • 53
  • 1
  • 5

1 Answers1

0

You can add points as if you have normal ggplot object.

g <- data.frame(x=c(1,.6,.6), y=c(0,.4,0), z=c(0,0,.4), Series="Green")
r <- data.frame(x=c(0,0.4,0), y=c(0,0,0.4), z=c(1,0.6,0.6), Series="Red")
p <- data.frame(x=c(0,0.4,0), y=c(1,0.6,0.6), z=c(0,0,0.4), Series="Purple")
DATA = rbind(g,r,p)    

temp <- data.frame(x=c(0.4), y=c(0.6), z=c(0.4))
plot<- ggtern(data=DATA,aes(x,y,z)) +
    geom_polygon(aes(fill=Series),alpha=.5,color="black",size=0.25) +
    scale_fill_manual(values=as.character(unique(DATA$Series))) +
    theme(legend.position=c(0,1),legend.justification=c(0,1)) +
    labs(fill="Region",title="Sample Filled Regions") +
    geom_point(data = temp, colour = "red") +
    annotate("text", x = 0.3, y = 0.6, z = 0.4, label = "Some text")

enter image description here

P. Denelle
  • 790
  • 10
  • 24
Kipras Kančys
  • 1,617
  • 1
  • 15
  • 20