如何更改ggtern中长轴标题的位置?
How to change the position of long axis titles in ggtern?
我在 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" 的长轴标题向内移动,但未能成功。
因此,要调整 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))
这将导致这样的情节
除了 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()
我在 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" 的长轴标题向内移动,但未能成功。
因此,要调整 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))
这将导致这样的情节
除了 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()