在R的情节传说中有分段? [英] Having subsections in a legend of a plot in R?
本文介绍了在R的情节传说中有分段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
legend(
bottomleft
,legend = c (
表达式(Long:〜(w == 10 ^ 2〜;〜h == 10 ^ 5)))
,expression(q [c] == 0.00〜 ;〜beta == 0)
,expression(q [c] == 0.05〜;〜beta == 2)
,expression(q [c] == 0.10〜; 〜beta == 10)
,expression(q [c] == 0.20〜;〜beta == 10)
,expression(q [c] == 0.40〜;〜 beta == 10)
,expression(bold(Wide:〜(w == 10 ^ 3〜;〜h == 10 ^ 3)))
,expression(q [c表达式(q [c] == 0.05〜;〜beta == 2)
,expression(q [c] = = 0.10〜;〜beta == 10)
,expression(q [c] == 0.20〜;〜beta == 10)
,expression(q [c] == 0.40 〜;〜beta == 10)
)
,col = c(n,1,2,3,4,5,-1,1,2,3,4,5 )
,lty = c(F,1,1,1,1,1,1,2,2,2,2,2)
,cex = 0.65
)
这给了我:
有一个标题会更好,也跨越线+点样本区域: 在这里输入图片描述>
我怎么能意识到这一点? (我尝试了例如在lty-section中设置 n
或者 FALSE
,但那不起作用。 )。
我也没有对齐 qc
和 beta
- 值,但这是一个不同的故事.. 。
解决方案类似的方法,但使用
图例
标题,和之后添加矩形(box)之前创建两个传说(无框) plot(1)
#legend 1
l1 < - legend(
topleft
,legend = c(expression(q [c] == 0.00〜;〜beta == 0)
,表达式(q [c] == 0.05〜;〜beta == 2)
,expression(q [c] == 0.10〜;〜beta == 10)
,expression
表达式(q [c] == 0.40〜;〜beta == 10)),
title =表达式(bold(Long:〜(w == 10 ^ 2〜;〜h == 10 ^ 5))),
,col = c(1,2,3,4,5)
,lty = c(1,1,1,1)
,cex = .65,
bty ='n')
# ($ l $ rect,top -h),
legend = c(e表达式(q [c] == 0.00〜;〜beta == 0)
,expression(q [c] == 0.05〜;〜beta == 2)
,expression表达式(q [c] == 0.10〜;〜beta == 10)
表达式(q [c] == 0.20〜;〜beta == 10)
,expression(q [ c] == 0.40〜;〜beta == 10)),
title =表达式(bold(Wide:〜(w == 10 ^ 3〜;〜h == 10 ^ 3 ))),
col = c(1,2,3,4,5)
,lty = c(2,2,2,2,2)
,cex = 0.65 ,
bty ='n')
#在图例中添加矩形
rect(xleft = l1 $ rect $ left,ybottom = with(l2 $ rect,top - h),
xright = l1 $ rect $ left + max(l1 $ rect $ w,l1 $ rect $ w),ytop = l1 $ rect $ top)
I generate the following legend:
legend(
"bottomleft"
, legend=c(
expression(bold("Long:" ~ (w==10^2 ~ ";" ~ h==10^5)))
, expression(q[c] == 0.00 ~ ";" ~ beta == 0)
, expression(q[c] == 0.05 ~ ";" ~ beta == 2)
, expression(q[c] == 0.10 ~ ";" ~ beta == 10)
, expression(q[c] == 0.20 ~ ";" ~ beta == 10)
, expression(q[c] == 0.40 ~ ";" ~ beta == 10)
, expression(bold("Wide:" ~ (w==10^3 ~ ";" ~ h==10^3)))
, expression(q[c] == 0.00 ~ ";" ~ beta == 0)
, expression(q[c] == 0.05 ~ ";" ~ beta == 2)
, expression(q[c] == 0.10 ~ ";" ~ beta == 10)
, expression(q[c] == 0.20 ~ ";" ~ beta == 10)
, expression(q[c] == 0.40 ~ ";" ~ beta == 10)
)
, col=c("n", 1, 2, 3, 4, 5, -1, 1, 2, 3, 4, 5)
, lty=c(F, 1, 1, 1, 1, 1, -1, 2, 2, 2, 2, 2)
, cex=.65
)
which gives me:
It would be nicer to have a heading, that also spans the "line+point" sample region:
How can I realize this? (I tried for example to set n
or FALSE
in the lty-section, but that did not work,...).
I also failed with aligning the qc
and beta
-values, but thats a different story,...
解决方案
A similar approach, but using the legend
title, and creating two legends (without boxes) before adding the rectangle (box) afterwards
plot(1)
# legend 1
l1 <- legend(
"topleft"
, legend=c(expression(q[c] == 0.00 ~ ";" ~ beta == 0)
, expression(q[c] == 0.05 ~ ";" ~ beta == 2)
, expression(q[c] == 0.10 ~ ";" ~ beta == 10)
, expression(q[c] == 0.20 ~ ";" ~ beta == 10)
, expression(q[c] == 0.40 ~ ";" ~ beta == 10)),
title = expression(bold("Long:" ~ (w==10^2 ~ ";" ~ h==10^5))),
, col=c( 1, 2, 3, 4, 5)
, lty=c(1, 1, 1, 1, 1)
, cex=.65,
bty='n')
# legend 2, placed directly below legend 1
l2 <- legend(x = l1$rect$left, y = with(l1$rect, top - h),
legend =c(expression(q[c] == 0.00 ~ ";" ~ beta == 0)
, expression(q[c] == 0.05 ~ ";" ~ beta == 2)
, expression(q[c] == 0.10 ~ ";" ~ beta == 10)
, expression(q[c] == 0.20 ~ ";" ~ beta == 10)
, expression(q[c] == 0.40 ~ ";" ~ beta == 10)),
title = expression(bold("Wide:" ~ (w==10^3 ~ ";" ~ h==10^3))),
col=c( 1, 2, 3, 4, 5)
, lty=c( 2, 2, 2, 2, 2)
, cex=.65,
bty='n')
# add the rectangle around the legend
rect(xleft = l1$rect$left, ybottom = with(l2$rect, top - h),
xright = l1$rect$left + max(l1$rect$w, l1$rect$w), ytop = l1$rect$top)
这篇关于在R的情节传说中有分段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文