情节标签中的表达和新行 [英] Expression and new line in plot labels

查看:131
本文介绍了情节标签中的表达和新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在图表标签中添加一些下标和上标。我尝试表达式,但它不能像新的行( \\\
)工作。我尝试使用粘贴修复它,但它不起作用。以下是我的一些尝试:

  par(mfcol = c(1,3))
plot(1, 1,main = expression(first line \\\
second line x^ 2))
plot(1,1,main = expression(paste(first line \\\
line,x^ 2)))
plot(1,1,main = paste(first line \\\
second line,expression(x^ 2)))
/ pre>

它产生:





在前两张照片中,第二行不太好,第三行上标失败。如何获取中心线和下标/上标?

解决方案

您可以在表达式中引入换行符:

  bquote(atop(first line,
second line〜x ^ 2))

(我使用 bquote 而不是表达式这里 - 在这种情况下都可以。)



执行演示(plotmath)



boxplot 在标题中显然有一些解释表达的麻烦。一个简单的修复是分别绘制标题:

  boxplot(data,main ='')
title(bquote (atop(first line,second line〜x ^ 2)))


I want to add some subscripts and superscripts to my graph labels. I've try expression, but it doesn't work as I wish with new lines (\n). I've try to fix it using paste, but it doesn't work. Below are some of my tries:

par(mfcol=c(1,3))
plot(1,1,main=expression("first line \n second line x"^2))
plot(1,1,main=expression(paste("first line \n second line", "x"^2)))
plot(1,1,main=paste("first line \n second line", expression("x"^2)))

It produces:

In first two pictures the second line is not well centered, in the third one the superscript fails. How to get both centered line and subscripts/superscripts?

解决方案

You can introduce a line break inside an expression:

bquote(atop("first line",
            "second line" ~ x ^ 2))

(I’m using bquote rather than expression here – both work in this case.)

Execute demo(plotmath) for more information and look at the documentation for atop.

boxplot apparently has some trouble interpreting expressions in its title. A simple fix is to plot the title separately:

boxplot(data, main = '')
title(bquote(atop("first line", "second line" ~ x ^ 2)))

这篇关于情节标签中的表达和新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆