【问题标题】:How to change labels of a ternary plot made by ggtern?如何更改 ggtern 制作的三元图的标签?
【发布时间】:2016-03-19 08:29:44
【问题描述】:

我正在尝试用 ggtern 制作三元情节。它看起来非常漂亮。但它只显示三角形边缘的百分比,例如 100、90 ... 有没有办法改变它以显示下划线数据的真正价值?谢谢。 我从这篇文章中举了一个例子。 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、b、c作为坐标。我想要的是将中断标记为 0.1、0.2(切割值不是百分比,如 10,20 ...)。

【问题讨论】:

  • 你有最低工作示例吗?

标签: r ggplot2


【解决方案1】:

本周有人写信给我一个问题,我认为你在追求什么,也许这就是你的意思?

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) 新几何:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多