5

1 ページに必要な一連のプロットがあります。最初にコマンド layout を使用してプロット レイアウトを指定します。

layout(matrix(c(1,1,2,2,1,1,2,2,3,4,5,6),3,4,byrow=TRUE))

プロット 1 の場合、次のようなものがあります。

plot(Easting,Northing, pch=16, col=grey(cex.size)) #The cex.size colours my dots according to some value

プロット 1 に挿入プロットを描画したいのですが、まだプロット 2 には移動しません。私はコードに従ってみました:

par(fig=c(0.75, 1, 0, 0.25), new = T)
plot(spp.tmp[,1:2], col=cols[spp.tmp[,3]+1], pch=16)
par(fig=c(0,1,0,1))

しかし、par(fig())コマンドがレイアウトを上書きし、挿入プロットがプロット 1 の下隅だけでなく、図全体の下隅に表示されるため、これは機能しません。

4

2 に答える 2

4

2つのオプション、

コマンド内にインセットを含めてみるlayoutことができます(あなたが固執する場合)layout

これは、最初のプロットが 2 つの行と列にまたがる場合で、2 番目のプロットは最初のプロットの右下隅の挿入図です。下の 3 番目のプロットは、最初のプロットと同じサイズですが、挿入図はありません。

layout( matrix(c(1,1,1,2,3,3,3,3), 4, 2, byrow = TRUE) )
## show the regions that have been allocated to each plot
layout.show(3)

ここに画像の説明を入力

代替手段はsubplot、TeachingDemos パッケージから使用することです

library(TeachingDemos)
layout(matrix(c(1,1,0,2),2,2,TRUE))
plot(1)
subplot(plot(1), x = c(1.2),y=0.8)
plot(2)

ここに画像の説明を入力

于 2013-03-21T03:29:11.973 に答える
3

これは、基本グラフィックを使用した私の手斧アプローチです。par() をいじっているので、マトリックスの順序を変更して、トリッキーなものを最後にプロットしないでください。このようにして、最初にトリッキーなものをプロットする場合、par 設定はレイアウト内のそれ以上のプロットに影響しません。この例では単純に見えますが、たくさんのプロットがあり、1 つだけに挿入したい場合はうまくいきます。

##generate some data
x<-rnorm(50)
y<-rnorm(50)
##set the layout
##so your first plot is plotted last
layout(matrix(c(2,2,0,1), 2,2, byrow=T))

#plot 1 is on the bottom right
plot(x,y, col="grey30", xlab="", ylab="")
#plot 2 is across the top
plot(x,y, col="grey30", xlab="", ylab="")
##set par to place the next plot in the existing plotting area
## and use fig to position it
par(fig=c(.65, .95, .55, .85), new = TRUE)

#inset 3rd plot int top plot, this effectively gives you a blank plot to populate
plot(x,y, col="white",  xlab="", ylab="")
#and make the background white
rect(par("usr")[1],par("usr")[3],par("usr")[2],par("usr")[4],col = "white")
##then just add your points afterwards
points(x,y,col="tomato")

于 2014-02-25T18:26:44.817 に答える