如何更改ggtern制作的三元图的标签? [英] How to change labels of a ternary plot made by ggtern?

查看:196
本文介绍了如何更改ggtern制作的三元图的标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用ggtern绘制三元图.看起来很漂亮.但它仅显示三角形边缘的百分比,例如100、90 ... 有没有一种方法可以更改以显示下划线数据的真实价值?谢谢. 我从这篇文章中引用了这个例子. 原始帖子

I am trying to make ternary plot with ggtern. It looks very beautiful. But it only shows the percentage along the edges of the triangle, for example 100, 90 ... Is there a way to change that to show the real value of the underlining data? Thanks. I toke the example from this post. The original Post

数据如下:

a <- c(0.1, 0.5,0.5, 0.6, 0.2, 0 , 0 , 0.004166667, 0.45) b <- c(0.75,0.5,0 , 0.1, 0.2, 0.951612903,0.918103448, 0.7875 , 0.45) c <- c(0.15,0 ,0.5, 0.3, 0.6, 0.048387097,0.081896552, 0.208333333, 0.10) d <- c(500,2324.90,2551.44,1244.50, 551.22,-644.20,-377.17,-100, 2493.04)

a <- c(0.1, 0.5,0.5, 0.6, 0.2, 0 , 0 , 0.004166667, 0.45) b <- c(0.75,0.5,0 , 0.1, 0.2, 0.951612903,0.918103448, 0.7875 , 0.45) c <- c(0.15,0 ,0.5, 0.3, 0.6, 0.048387097,0.081896552, 0.208333333, 0.10) d <- c(500,2324.90,2551.44,1244.50, 551.22,-644.20,-377.17,-100, 2493.04)

这里,a,b,c用作坐标.我想要的是让断裂像0.1、0.2(剪切值而不是像10,20 ...这样的百分比)成为可能.

Here a, b, c are used as coordinates. What I want is to lable the breaks like 0.1, 0.2 (the cut values not the percentages like 10,20 ...).

推荐答案

这周有人写信给我一个问题,我想你要的是什么,也许这就是你的意思?

Someone wrote to me this week with a question, which is what I think you are after, perhaps this is what you mean?

library(ggtern)
set.seed(1)
df = data.frame(x=runif(10),y=runif(10),z=runif(10))

#Normalise sum to unity
df.s = rowSums(df); for(x in c('x','y','z')) df[,x] = df[,x]/df.s

labFnc <- function(x,digits=2) format(round(unique(x),digits),digits=digits)

#Plot
ggtern(df,aes(x,y,z)) +
  scale_T_continuous(breaks=unique(df$y),labels=labFnc(df$y)) +
  scale_L_continuous(breaks=unique(df$x),labels=labFnc(df$x)) +
  scale_R_continuous(breaks=unique(df$z),labels=labFnc(df$y)) +
  theme_bw() +
  theme_nogrid_minor() + 
  geom_point() +
  labs(title="Example Use of Data Along Ternary Axes")

可以进一步使用ggtern 2.1.0提供的geom_Xmark()(X = T,L,R)新几何:

This can be taken further, with the use of the geom_Xmark() (X = T,L,R) new geometries available with ggtern 2.1.0:

#Plot
ggtern(df,aes(x,y,z)) +
  scale_T_continuous(breaks=unique(df$y),labels=labFnc(df$y)) +
  scale_L_continuous(breaks=unique(df$x),labels=labFnc(df$x)) +
  scale_R_continuous(breaks=unique(df$z),labels=labFnc(df$y)) +
  theme_rgbw() +
  theme_nogrid() +  
  geom_Lmark(colour='darkblue') + 
  geom_Tmark(colour='darkred') +
  geom_Rmark(colour='darkgreen') + 
  geom_point() +
  labs(title="Example Use of Data Along Ternary Axes")

这篇关于如何更改ggtern制作的三元图的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆