【问题标题】:Zoom in the subplot in the existing plot in R放大 R 中现有绘图中的子图
【发布时间】:2023-04-01 03:40:01
【问题描述】:

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

【问题讨论】:

  • Related 问题,答案,cmets..
  • @朱利叶斯。我见过这个问题,但这个功能只是放大点而不是线。

标签: r


【解决方案1】:

例如,您可以这样做:

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)

【讨论】:

  • 谢谢。这个子图没问题,但我怎样才能放大这个子图或让它变大?
【解决方案2】:

您可以使用绘图函数的 xlim 和 ylim 参数来更改绘图的限制。例如

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

【讨论】:

    猜你喜欢
    • 2013-07-15
    • 2021-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多