情节标签中的表达和新行 [英] Expression and new line in plot labels
问题描述
表达式
,但它不能像新的行( \\\
)工作。我尝试使用粘贴
修复它,但它不起作用。以下是我的一些尝试:par(mfcol = c(1,3))
/ pre>
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)))
它产生:
在前两张照片中,第二行不太好,第三行上标失败。如何获取中心线和下标/上标?
解决方案您可以在表达式中引入换行符:
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 usingpaste
, 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 thanexpression
here – both work in this case.)Execute
demo(plotmath)
for more information and look at the documentation foratop
.
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屋!