2

我在三元图中有长轴标题名称,编码为ggtern. 我无法让 R 和 L(基线)标题移入(从它们被切断的地方)。顶部标题看起来不错,但其他两个则不然。

我曾尝试使用axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0))和更改定位变量,但这似乎不起作用。所以我不知道该怎么做。

#library(tidyverse)
#library(ggtern)

confidencebreaks <- c(0.95)
x  <- runif(1000,min = 0, max = 1)
y  <- runif(1000,min = 0, max = 1)
z  <- runif(1000,min = 0, max = 1)
df <- tibble(x,y,z)

tern1 <- 
  ggtern(data = df,
         mapping = aes(x = z, y = y, z = z)
  ) +
  labs(title = "A title", 
       subtitle = "A subtitle",
       x = expression(paste(atop("Title 2", 
                                 "A long line 2 that goes on and on"))), 
       y = expression(paste(atop("Title 0", 
                                 "A long line 2 that goes on and on"))),
       z = expression(paste(atop("Title 1", 
                                 "A long line 2 that goes on and on")))
  ) + 
  theme(axis.title = element_text(size=10)) 
print(tern1)

上面的代码重现了截断和长轴标题的问题。我希望能够将“Title 2”和“Title 1”的长轴标题向内移动,但没有成功。

4

2 回答 2

2

因此,要调整 ggtern 上的标签,您应该使用 tern.axis.title 并指定哪一侧是 R 代表右侧,L 代表左侧,T 代表顶部。在您的问题中,您可以按如下方式调整标签

    library(tidyverse)
    library(ggtern)

    confidencebreaks <- c(0.95)
    x  <- runif(1000,min = 0, max = 1)
    y  <- runif(1000,min = 0, max = 1)
    z  <- runif(1000,min = 0, max = 1)
    df <- tibble(x,y,z)

    df

    ggtern(data = df,
             mapping = aes(x = z, y = y, z = z)
      ) +
      labs(title = "A title", 
           subtitle = "A subtitle")+
           xlab("Title 2 \n A long line 2 that goes on and on")+ 
           ylab("Title 0 \n A long line 2 that goes on and on")+
           zlab("Title 1 \n A long line 2 that goes on and on")+ 
      theme(tern.axis.title.L = element_text(hjust = 0),
            tern.axis.title.R = element_text(hjust = 1))

这将导致这样的情节 在此处输入图像描述

于 2019-08-01T18:00:41.507 回答
1

除了 Sebastian 提供的解决方案之外,以下是替代方案,具体取决于您的特定用户案例:

library(ggtern)
x  <- runif(1000,min = 0, max = 1)
y  <- runif(1000,min = 0, max = 1)
z  <- runif(1000,min = 0, max = 1)
df = data.frame(x,y,z)
ggtern(data = df, 
       mapping = aes(x = z, y = y, z = z)) +
  labs(title = "A title",  
       subtitle = "A subtitle",
       x = "Title 2", xarrow="A long line 2 that goes on and on",
       y = "Title 0", yarrow="A long line 0 that goes on and on",
       z = "Title 1", zarrow="A long line 1 that goes on and on"
  ) + 
  theme_showarrows()

结果

于 2019-08-03T04:41:34.553 回答