r-地图在复杂布局中与绘图边界重叠

时间:2019-07-19 08:20:41

标签: r layout maps par

我将创建一个更复杂的图形,其中R在6个地图上显示变量的值(按2列和3行排序)。

但是,一旦执行下面所示的代码,第一张地图总是会超出其绘图边界,如所附图像所示。

require(maps)

layout(matrix(c(14,  1,  1,  1,  1,  2,  2,  2,  2,  3,  3,
                 4,  8,  8,  8,  8, 11, 11, 11, 11, 15, 15,
                 4,  8,  8,  8,  8, 11, 11, 11, 11, 15, 15,
                 4,  8,  8,  8,  8, 11, 11, 11, 11,  7, 17,
                 5,  9,  9,  9,  9, 12, 12, 12, 12,  7, 17,
                 5,  9,  9,  9,  9, 12, 12, 12, 12,  7, 17,
                 5,  9,  9,  9,  9, 12, 12, 12, 12,  7, 17,
                 6, 10, 10, 10, 10, 13, 13, 13, 13,  7, 17,
                 6, 10, 10, 10, 10, 13, 13, 13, 13, 16, 16,
                 6, 10, 10, 10, 10, 13, 13, 13, 13, 16, 16
), nrow=10, byrow=T))

par(mar=c(0.5,0.5,0.5,0.5))
plot.new()
text(0.5, 0.5, "observed", cex=2)

plot.new()
text(0.5, 0.5, "estimated", cex=2)

plot.new()
text(0.5, 0.5, paste(4478, "BP"), cex=2)

plot.new()
text(0.5, 0.5, "autosomal", cex=2, srt=90)

plot.new()
text(0.5, 0.5, "mitochondrial", cex=2, srt=90)

plot.new()
text(0.5, 0.5, "Y-chromosomal", cex=2, srt=90)

par(mar=c(0.5, 1, 0.5, 1))
Col = colorRampPalette(c("red", "blue"))
image(1, seq(0, 1, length=1000), matrix(1:1000, nrow=1), col=Col(1000), axes=F ,xlab="", ylab="")
box()
axis(4, at=c(0, 0.25, 0.5, 0.75, 1), las=2, cex.axis=1.3)

par(mar=c(0.5, 0.5, 0.5, 0.5))
map("world2",xlim=c(90,255),ylim=c(-50,35),fill=T)

map("world2",xlim=c(90,255),ylim=c(-50,35),fill=T)

map("world2",xlim=c(90,255),ylim=c(-50,35),fill=T)

map("world2",xlim=c(90,255),ylim=c(-50,35),fill=T)

map("world2",xlim=c(90,255),ylim=c(-50,35),fill=T)

map("world2",xlim=c(90,255),ylim=c(-50,35),fill=T)

par(mar=c(0, 0, 0, 0))
plot.new()

plot.new()

plot.new()

plot.new()
text(0.7, 0.5, "Asian ancestry", cex=2, srt=90)

enter image description here

如何防止第一张图像重叠其边界并正确显示(就像其他地图一样)?

1 个答案:

答案 0 :(得分:1)

maps::map似乎在内部覆盖了您定义的par(mar(.))。在每个map()的前面进行定义。

更改了代码的map部分:

par(mar=c(0.5, 0.5, 0.5, 0.5))
map("world2",xlim=c(90,255),ylim=c(-50,35),fill=T)

par(mar=c(0.5, 0.5, 0.5, 0.5))
map("world2",xlim=c(90,255),ylim=c(-50,35),fill=T)

par(mar=c(0.5, 0.5, 0.5, 0.5))
map("world2",xlim=c(90,255),ylim=c(-50,35),fill=T)

par(mar=c(0.5, 0.5, 0.5, 0.5))
map("world2",xlim=c(90,255),ylim=c(-50,35),fill=T)

par(mar=c(0.5, 0.5, 0.5, 0.5))
map("world2",xlim=c(90,255),ylim=c(-50,35),fill=T)

par(mar=c(0.5, 0.5, 0.5, 0.5))
map("world2",xlim=c(90,255),ylim=c(-50,35),fill=T)

产生:

enter image description here