如何在R的split.screen模式下更改屏幕大小?

如何在R的split.screen模式下更改屏幕大小?,r,layout,plot,split,R,Layout,Plot,Split,我想在一台设备上画两个相邻的图。我使用split.screen,因为它很容易处理。但是,似乎split.screen()将屏幕平均分割 在我的例子中,我希望右栏稍微窄一点。这是因为我省略了轴标签,这使得右图比左图宽一些: #install.packages("TeachingDemos", dependencies=TRUE) library(package="TeachingDemos") # **************************************************

我想在一台设备上画两个相邻的图。我使用
split.screen
,因为它很容易处理。但是,似乎
split.screen()
将屏幕平均分割

在我的例子中,我希望右栏稍微窄一点。这是因为我省略了轴标签,这使得右图比左图宽一些:

#install.packages("TeachingDemos", dependencies=TRUE)
library(package="TeachingDemos")
# ***********************************************************
#source("subplot_new.R.txt")
# ***********************************************************
# data for all 4 plots
dx = c(1:10)
dy = c(10:1)


toPDF = T


if(toPDF) {
  pdf(file="test.pdf", width=10, height=5)
}
# split the screen into two columns
close.screen(all.screens=T)
split.screen(figs=c(1,2))

# go to screen 1
# ***********************************************************
screen(1)
par(mar=c(4,4,0.1,0.1), las=1)
plot(x = dx, y = dy)


# determine coordinates of subplot region:
x_left_right = grconvertX(c(0,0.5), from='npc')
y_bottom_top = grconvertY(c(0,0.5), from='npc')
# draw rectangle
rect(
  xleft     = x_left_right[1]
  , xright  = x_left_right[2]
  , ybottom = y_bottom_top[1]
  , ytop    = y_bottom_top[2]
  , col = "#efefef"
)
# add a subplot in green
subplot(
  fun={
    plot(x = dx, y = dy, ann = F)
  }
  , type = "fig"
  , x = x_left_right
  , y = y_bottom_top
  , pars = list(
    fg = "green"
    , mar = c(2,2,0,0)
    )
)

# go to screen 2
# ***********************************************************
screen(2)
par(mar=c(4,1,0.1,0.1), las=1)
plot(x = dx, y = dy, yaxt="n")
axis(side=2, labels=F)

# determine coordinates of subplot region:
x_left_right = grconvertX(c(0.6,1), from='npc')
y_bottom_top = grconvertY(c(0.6,1), from='npc')
# draw rectangle
rect(
  xleft     = x_left_right[1]
  , xright  = x_left_right[2]
  , ybottom = y_bottom_top[1]
  , ytop    = y_bottom_top[2]
  , col = "#efefef"
)
# add a subplot in blue
subplot(
  fun={
    plot(x = dx, y = dy, ann = F)
  }
  , type = "fig"
  , x = x_left_right
  , y = y_bottom_top
  , pars = list(fg = "blue", mar = c(2,2,0,0))
)

if(toPDF) {
  dev.off()
}
我认为
layout
可能有效,但在我的情况下可能不行,因为我需要使用TeachinDomes包中的subplot命令

是否有一个类似于split.screen的包,允许设置每列从整个屏幕中获得的比例?或者可以操纵split.screen包来完成任务吗


我只想让两个绘图具有相同的大小,而不需要额外的白边。

分割。屏幕实际上非常灵活,让您可以自由控制屏幕的大小和位置。您所需要做的就是为它提供一个N×4矩阵,其中每行指定左、右、上、下边缘的相对位置

有关更多详细信息,请参见
?拆分屏幕

split.screen(matrix(c(0,.7,  .7,1,  0,0,  1,1), ncol=4))
screen(1)
plot(1, 1)
split.screen(matrix(c(0,0,  1,1,  0,.7,  .4,1), ncol=4), screen=2)
screen(3)
plot(2,2)
screen(4)
plot(3,3)

你甚至可以像这样被绊倒

split.screen(matrix(c(0:2,  4:6,  0:2,  4:6)/6, ncol=4))
screen(1)
plot(1,1)
screen(2)
plot(2,2)
screen(3)
plot(3,3)

您有什么想法吗?我如何将左侧屏幕的宽度减少一条边距线,并在右侧屏幕上添加一条边距线?使用
par(“din”)/par(“csi”)
获取设备的宽度和高度,单位为兆欧单位(线)。在我的计算机上,默认大小是
c(35,35)
,因此通过将左右边缘表示为
x/35
(35-x)/35
,我可以移动任意数量的边框。