Subplot in existing R plot

给你一囗甜甜゛ 提交于 2019-12-10 21:57:21

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!