[英]Plot legend label in multiple lines including mathematical expressions
How can I create legend labels containing multiple lines of text followed by a mathematical expression on a separate line, avoiding the problems listed below? 如何创建包含多行文本的图例标签,然后在单独的行上创建数学表达式,以避免下面列出的问题?
The accepted answer here doesn't work for legends, and as far as I can tell, the alternate answer involving bquote doesn't work for my case either, as illustrated below. 接受答案在这里不适合传说工作,据我所知,涉及bquote备选答案不适合我的情况下工作,要么,如下图所示。
Reproducible code: 可重现的代码:
# multiple lines in first legend label are not horizontally aligned
# also, entire legend label is not vertically aligned with box
plot( runif(10), runif(10) )
legend( x='top', fill=grey.colors(2), bty='n', ncol=2, inset=.1,
legend=c( expression( "Hello world\nGoodbye world\n" ~ 64 %/% 8 %/% 8 ),
'something else' ) )
# both above problems fixed, but math expression doesn't display right
plot( runif(10), runif(10) )
legend( x='top', fill=grey.colors(2), bty='n', ncol=2, inset=.1,
legend=c( paste( "Hello world\nGoodbye world\n", expression( 64 %/% 8 %/% 8 ) ),
'something else' ) )
# nested atops within bquote almost works in title, but font size is not uniform
# does not work at all in legend, anyway
plot( runif(10), runif(10) )
label1 = bquote( atop( atop( "Hello world", "Goodbye world" ), 64 %/% 8 %/% 8 ) )
labels = c( label1, 'something else' )
title( label1 )
legend( x='top', fill=grey.colors(2), bty='n', ncol=2, inset=.1, legend=labels )
One option is 一种选择是
plot( runif(10), runif(10) )
legend( x='top', fill=grey.colors(2), bty='n', ncol=2, inset=.1,
legend=c( expression( atop("Hello world\nGoodbye world",64 %/% 8 %/% 8) ),
'something else' ) )
or 要么
plot( runif(10), runif(10) )
legend( x='top', fill=grey.colors(2), bty='n', ncol=2, inset=.1,
legend=c( expression( atop(atop("Hello world","Goodbye world"),64 %/% 8 %/% 8) ),
'something else' ) )
But really R doesn't like to use new-lines in ?plotmath
mode. 但是R真的不喜欢在?plotmath
模式中使用?plotmath
。 If you need finder control over your legends, you are better off exporting as pdf and fine editing in Adobe Illustrator or something. 如果你需要finder控制你的传说,你最好在Adobe Illustrator或其他东西中导出为pdf和精细编辑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.