2

我想在 ggtern 图上绘制数据集的均值。

我从 ade4 库中找到了 triangle.plot,但我想使用 ggtern 做同样的事情(修改所有设置会更容易)。我看到 geom_crosshair_tern() 但无法适应它。

library(ade4)
data(euro123)
tot <- rbind.data.frame(euro123$in78, euro123$in86, euro123$in97)
row.names(tot) <- paste(row.names(euro123$in78), rep(c(1, 2, 3), rep(12, 3)), sep = "")
triangle.plot(tot, addmean=TRUE,show.position = FALSE)

参见三角形图上的平均值图像

4

1 回答 1

2

这里有一些让你开始的东西:

library(ggtern)
library(plyr)
df.tot = tot
df.mu = as.data.frame(t(colMeans(tot)))
ggtern(data=df.tot,aes(pri,ter,sec)) + 
  geom_point() +
  geom_crosshair_tern(data=df.mu) +
  geom_point(data=df.mu,color='red') + 
  geom_label(data=100*df.mu,
             aes(
               y = ter - 5,
               label=sprintf("P=%.1f, S=%.1f, T=%.1f",pri,sec,ter)
             ),
             size=3,
             color='red'
             ) + 
  theme_bw() +
  theme_showarrows() + 
  limit_tern(0.8,0.5,0.7) +
  labs(
    x = 'Pri',xarrow='Primary',
    y = 'Ter',yarrow='Tertiary',
    z = 'Sec',zarrow='Secondary'
  )

例子

于 2019-07-31T14:43:40.977 回答