R building an insert in one plot in a multi-line layout

I have a series of graphs that I want on one page. I first use the command layout to specify my plot layout:

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

For plot 1, I have something like:

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

Now I want to draw a nested plot on plot 1, but so far not go to plot 2. I tried to execute the code:

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))

But this does not work, as the team par(fig())overwrites my layout, and the insertion schedule appears in the lower corner of my common figure, and not just in the lower corner of schedule 1.

+5
source share
2 answers

Two options

Try and enable insertion in your command layout(if you must adhere tolayout

, , - . , , , .

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)

enter image description here

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)

enter image description here

+4

. 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")

+3

All Articles