【问题标题】:Plot curved line on R plot using a condition given two vectors使用给定两个向量的条件在 R 图上绘制曲线
【发布时间】:2021-12-28 03:50:08
【问题描述】:

给定以下空图:

plot(1, type="n", xlab="x1", ylab="x2", xlim=c(0, 10), ylim=c(0, 10), axes = F)
axis(1, seq(0,10,1), pos = 0)
axis(2, seq(0,10,1), pos = 0)
lines(x = c(0,10), y = c(10,10))
lines(x = c(10,10), y = c(0,10))

我想绘制一条平滑曲线,其中 x1*x2 = 38,假设 x1 和 x2 都在 0 和 10 之间。

我可以使用什么样的函数来完成这个?

【问题讨论】:

    标签: r plot


    【解决方案1】:

    使用curve

    curve(38/x, xlim=c(0, 10), ylim=c(0, 10), xlab='x1', ylab='x2')
    

    【讨论】:

      【解决方案2】:

      你可以试试

      plot(1, type="n", xlab="x1", ylab="x2", xlim=c(0, 10), ylim=c(0, 10), axes = F)
      axis(1, seq(0,10,1), pos = 0)
      axis(2, seq(0,10,1), pos = 0)
      lines(x = c(0,10), y = c(10,10))
      lines(x = c(10,10), y = c(0,10))
      t <- seq(from = 3.8, to = 10, by = .1)
      lines(x = t, y = 38/t)
      

      【讨论】:

      • 奇怪的创建轴的方式,要么不要使用axes=FALSE,要么使用box()
      猜你喜欢
      • 1970-01-01
      • 2020-01-25
      • 2021-08-16
      • 1970-01-01
      • 2015-06-16
      • 1970-01-01
      • 1970-01-01
      • 2021-07-29
      • 1970-01-01
      相关资源
      最近更新 更多