我不知道怎么做,因为我是R的新手,代码似乎令人困惑.我在网站上看到了以下代码,并试图将它们应用到我自己的工作中.
#Load the data
df <- read.table(file = "~/Desktop/PPS-data.txt", header = T)
#Create the plot and store
plot <- ggtern(data = df, aes(x = Xyp, y = XO, z = XY)) +
geom_point(aes(fill = Root),
size = 4,
shape = 21,
color = "black") +
ggtitle("PPS 3-State Model") +
labs(fill = "Root States") +
theme_tern_rgbw() +
theme(legend.position = c(0,1),
legend.justification = c(0, 1))
Run Code Online (Sandbox Code Playgroud)
他们使用的数据文件不可用,所以我无法查看它是如何安排的.
这是我的数据:
GRAVEL SAND MUD
0.95 93.55 5.49
8.06 44.38 47.55
1.76 79.35 18.89
10.11 87.37 2.53
1.35 90.03 8.62
6.07 75.00 18.93
4.07 95.93 0.00
5.12 94.83 0.05
4.31 75.01 20.68
1.97 71.94 26.10
4.47 77.36 18.17
1.64 78.70 19.66
2.01 70.74 27.25
7.64 82.50 9.86
12.35 82.86 4.79
4.38 79.94 15.68
11.48 84.61 3.91
0.82 91.65 7.53
36.79 63.21 0.00
6.01 41.29 52.70
17.26 23.22 59.52
8.41 41.29 50.30
5.45 39.20 55.34
2.22 19.71 78.07
0.73 14.79 84.48
7.43 51.54 41.03
4.78 48.75 46.47
6.73 48.52 44.75
10.89 45.73 43.38
1.62 22.22 76.16
1.90 19.73 78.37
3.00 25.31 71.69
1.75 17.00 81.25
1.81 21.60 76.59
2.61 30.07 67.32
2.27 31.28 66.44
1.09 26.82 72.08
1.04 17.31 81.65
0.99 12.39 86.62
0.96 17.23 81.81
Run Code Online (Sandbox Code Playgroud)
我开始了
library(ggtern)
ggtern(df,aes(GRAVEL,SAND,MUD))+geom_point()
Run Code Online (Sandbox Code Playgroud)

fill=Root在aes()函数和shape=21外部添加将根据某些其他变量的值在点中着色,但如果您的数据集中有一个可以确定颜色的单独变量,则最有意义的是为点着色 - 上面的示例只提供三个变量(你可以随机给它们着色,但这看起来有点傻).