我在R中有以下图。我想在现有的绘图形式x =[0, 2]
和y=[0, 2]
中有一个子图,我想要放大该子图。我怎么能在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)
答案 0 :(得分:4)
您可以这样做:
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)
答案 1 :(得分:2)
您可以使用绘图函数的xlim和ylim参数更改绘图的限制。例如
plot(y~x, data = lin, xlim=c(0,2), ylim=c(0,2))