在ggplot2中添加多级x标签
我将如何在 ggplot 2 中的多行上放置 x 标签。我知道我将使用如下所示的 mtext 在基本图中执行此操作,但是在 ggplot2 中创建类似 x 轴标签的等效方法是什么?
最低工作示例:
# List containing the expressions for the x-axes
xaxeslist = list(bquote("Low" %<-% "Complexity" %->% "High"),
bquote("High" %<-% "Bias" %->% "Low"),
bquote("Low" %<-% "Variance" %->% "High"))
# In base R one would use mtext to plot the desired x-label values
# mtext(do.call(expression, xaxeslist), side = 1, line = 2:4)
# Dummy values for working example
xval = seq(0, 100, by = 0.001)
yval = seq(0, 100, by = 0.001)
data <- data.frame("x"=xval,"y"=yval)
# Plot the desired output
b<-ggplot(data) +
aes(x = x, y = y) +
geom_line(size = 1L) +
labs(
x = do.call(expression, xaxeslist),
y = "Y-value",
title = "Title"
) +
theme(axis.ticks.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.y = element_blank(),
axis.text.y = element_blank())
print(b)
我想操纵 x 标签,使其落在多行上,如上图,即xaxeslist成为 xlabel。