【问题标题】:How to plot the means using ggtern如何使用 ggtern 绘制均值
【发布时间】:2019-07-31 13:36:35
【问题描述】:

我想在 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)

【问题讨论】:

  • 看看我的回答:stackoverflow.com/questions/56502899/…,并不能完全回答你的问题,但应该能让你走得很远。
  • 确实,这不是我正在寻找的答案,但并不遥远。谢谢,

标签: r ggtern


【解决方案1】:

以下是帮助您入门的内容:

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

【讨论】:

  • 感谢您的回答!它非常有用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-28
  • 1970-01-01
  • 2017-08-30
  • 2022-08-19
  • 2018-04-04
  • 2021-07-07
  • 2015-07-22
相关资源
最近更新 更多