簡體   English   中英

在多行中繪制圖例標簽,包括數學表達式

[英]Plot legend label in multiple lines including mathematical expressions

如何創建包含多行文本的圖例標簽,然后在單獨的行上創建數學表達式,以避免下面列出的問題?

接受答案在這里不適合傳說工作,據我所知,涉及bquote備選答案不適合我的情況下工作,要么,如下圖所示。

可重現的代碼:

# 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 )

一種選擇是

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' ) )

要么

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' ) )

但是R真的不喜歡在?plotmath模式中使用?plotmath 如果你需要finder控制你的傳說,你最好在Adobe Illustrator或其他東西中導出為pdf和精細編輯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM