'垂直'多个三元图上的行标题

时间:2016-03-07 17:51:42

标签: r plot ggplot2 ggtern

我尝试使用ggternggplot2为多情节图的行和列绘制标题。我已尝试使用theme(),但无法找到能够正确标记行并移动文本的属性(在使用angle旋转之后)。理想情况下,我喜欢这些行有垂直文字说'侧标题:1'并且'标题2'。

此代码来自ggtern网站上的an example。在此先感谢您的帮助。

require(ggplot2)
require(ggtern)
data(Feldspar)

arrangement = list()

for(r in seq(1,2)){
    for(c in seq(1, 2)){

    title <- ""
    if (r == 1){title <- paste("Top title:", c)}

    ytitle <- ""
    if (c == 1){ ytitle <- paste("Side title:", r)}

      x = ggtern(data=Feldspar,aes(x = Ab,y = An,z = Or)) +
        geom_point() + 
        ggtitle(title)+
        labs(y = ytitle)

      arrangement[[length(arrangement) + 1]] = x
      }
}
grid.arrange(grobs = arrangement)

1 个答案:

答案 0 :(得分:0)

我认为你要实现的意义,应该通过facet_grid(...)使用分面来完成,例如以下简单的例子:

library(ggtern)
set.seed(1) #for reproducability
df = data.frame(A=runif(100),B=runif(100),C=runif(100),
                COLS=paste("Column",sample(1:2,100,replace=TRUE)),
                ROWS=paste("Row",   sample(1:2,100,replace=TRUE)))
ggtern(data=df,aes(A,B,C)) + 
  geom_point() + 
  facet_grid(ROWS~COLS)

产生以下内容:

example