我想在一个设备上绘制两个相邻的图。我使用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 包来完成任务?
我只是想让两个图具有相同的大小,而不需要额外的白边距。