简体   繁体   English

更改轴标签中多行之间的距离

[英]Change the distance between multiple lines in axis label

I need to plot two lines for x-axis label. 我需要为x轴标签绘制两条线。 Because I need to use special font I choose to use "expression" with "atop". 因为我需要使用特殊字体,所以我选择使用“表达式”和“atop”。 The problem is that the distance between the two lines is much bigger than that if I just use "\\n". 问题是,如果我只使用“\\ n”,两条线之间的距离要大得多。 Like the following: 如下:

xlabs <- c('change in log2\nsample A', 
            expression(atop('change in'~log['2'], 'sample B')))

I got something like this: 我有这样的事情:

在此输入图像描述

Anyone knows how to solve the problem? 谁知道如何解决问题?

You can use the graphical parameter lheight together with mtext to adjust the line spacing to anything you want 您可以将图形参数lheightmtext一起使用,以将行间距调整为您想要的任何内容

plot(1:100, xlab = '')
par(lheight = 1.1)
mtext(xlabs[1], side = 1, line = 2)

在此输入图像描述

I think using an expression vector is what was requested: 我认为使用表达式向量是我们所要求的:

exl <- list(quote(line~1), quote(line~2))
plot(0:1,0:1,type="n",xlab="")
mtext(side=1, do.call(expression,exl),line=1:2)

These also succeeds (and might point the way to a more flexible approach to using an expression vector: 这些也取得了成功(并且可能指向更灵活的方法来使用表达式向量:

plot(0:1,0:1,type="n",xlab="")
mtext(side=1, expression(line*1, line*2), line=1:2)

plot(0:1,0:1,type="n",xlab="")
mtext(side=1, c(bquote(line==.(round(exp(1),2))), expression(line*2)), line=1:2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM