0

我正在尝试将一些点与三角形中的某些区域绘制成三角图此代码:

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)

我想在这个图中添加一些点,这些点取自文本文件,我正在读取它们的 x、y 和 z 坐标。我怎么能把这些点指向情节?

如果我尝试这样的事情,它会删除以前的情节:

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

这是我需要添加点的情节

训练图

4

1 回答 1

0

您可以像拥有普通 ggplot 对象一样添加点。

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")

在此处输入图像描述

于 2016-11-30T18:21:35.950 回答