使用split.screen()表示不平衡的数字。整体头衔在正确的位置,但修剪

时间:2014-11-23 21:39:34

标签: r plot

动机: 有一个有两列的数字,左列有3个图,右列有4个图,有一个整体标题。 我能够使用split.screen()生成图形,并获得整体标题。但目前的问题是整体冠军没有足够的空间,其中一些被截断 - 如图所示。我尝试使用边距的大小和.png的大小,但没有成功。谢谢。

enter image description here

此玩具示例使用的代码:

##  Open a new default device.
get( getOption( "device" ) )()
png("Figure1.png",width = 1200,height = 1200)

par(oma = c( 0, 0, 3, 0 ) )
##  Split the screen into two rows and one column, defining screens 1 and 2.
split.screen( figs = c( 1, 2 ) )

##  Split screen 1 into one row and three columns, defining screens 3:5.
split.screen( figs = c( 3, 1 ), screen = 1 )

##  Split screen 2 into four rows and one column, defining screens 6:9.
split.screen( figs = c( 4, 1 ), screen = 2 )

screen( 3 )
plot( rnorm( n = 10 ), col = "red", main = "plot 1" )

screen( 4 )
plot( runif( n = 10 ), col = "blue", main = "plot 2" )

screen( 5 )
plot( rt( n = 10, df = 8 ), col = "springgreen4", main = "plot 3" )

screen( 6 )
plot( rpois( n = 10, lambda = 2 ), col = "black", main = "plot 4" )

screen( 7 )
plot( rf( n = 10, df1 = 4, df2 = 8 ), col = "gray30", main = "plot 5" )

screen( 8 )
plot( rf( n = 10, df1 = 4, df2 = 8 ), col = "gray30", main = "plot 6" )

screen( 9 )
plot( rf( n = 10, df1 = 4, df2 = 8 ), col = "gray30", main = "plot 7" )

##  Close all screens.
title( "Sanity Models", outer = TRUE )
close.screen( all = TRUE )
dev.off()

2 个答案:

答案 0 :(得分:1)

一种选择是使用它而不是当前的标题调用:

title( "Sanity Models", outer = TRUE , line=-1)

它将标题放在一行宽。

答案 1 :(得分:1)

这里的问题是你需要在调用split.screen()之后调用par()

E.g。

split.screen( figs = c( 1, 2 ) )
par(oma = c( 0, 0, 3, 0 ) )