1

I have the following plot in R. I would like to have a subplot in the existing plot form x =[0, 2] and y=[0, 2], also I want to zoom into that subplot. How can I do this in R?

 lin <- data.frame(x = c(0:6), y = c(0.3, 0.1, 0.9, 3.1, 5, 4.9, 6.2))
 linm <- lm(y ~ x, data = lin, subset = 2:4)
 plot(y ~ x, data = lin)
 abline(linm)
rose
  • 1,971
  • 7
  • 26
  • 32
  • [Related](http://stackoverflow.com/questions/13714724/how-to-draw-a-zoom-in-effect-in-r/13728281) question, answers, comments.. – Julius Vainora Aug 04 '13 at 00:39
  • @Julius. I have seen that question, but that fuction just zoom in the point not the line. – rose Aug 04 '13 at 00:44

2 Answers2

4

You can do this for example:

lin <- data.frame(x = c(0:6), y = c(0.3, 0.1, 0.9, 3.1, 5, 4.9, 6.2))
linm <- lm(y ~ x, data = lin, subset = 2:4)
plot(y ~ x, data = lin)
abline(linm)
## to overlap the 2 plots
par(new=TRUE, oma=c(3,1,1,2))
## create a layout to plot the subplot in the right bottom corner
layout(matrix(1:4,2))
## use xlim and ylim to zoom the subplot
plot(y ~ x, data = lin,xlim=c(0,2), ylim=c(0,2))
abline(linm)

enter image description here

agstudy
  • 119,832
  • 17
  • 199
  • 261
  • Thanks. This subplot is ok , but how can i zoom in to this subplot or make it bigger ? – rose Aug 04 '13 at 00:39
2

You can change the limits of a plot using the xlim and ylim arguments to the plot function. For example

plot(y~x, data = lin, xlim=c(0,2), ylim=c(0,2))