问题
I have a plot as shown below. To this plot i would like to add a similar kind of line plot somewhere within the plot (bottomright or bottomleft). The command for the subplot i am using is
plot( 1:121, sample(1:121),type='l' )
It plots right on the top of the first one. I need it as a small plot either at the bottomleft or bottomright. COuld someone help to do this in R?

回答1:
op <- par(no.readonly = TRUE)
set.seed(42)
plot(rnorm(100), runif(100))
par(new=TRUE, oma=c(3,1,1,2))
layout(matrix(1:4,2))
plot(rnorm(100), runif(100), col="blue", xlab="", ylab="")
par(op)

回答2:
If you set the parameter new
to TRUE
, the canvas will not be cleaned before the next plotting command:
par( new= TRUE )
I leave it to your ingenuity to create a suitable white background and position the new plot :-) Hint: take a look at the omd
parameter in the manual for par
.
来源:https://stackoverflow.com/questions/17695932/subplot-in-existing-r-plot