【问题标题】:How to plot several curve segments on the same graph?如何在同一张图上绘制多个曲线段?
【发布时间】:2014-02-17 22:00:12
【问题描述】:
seg1 <- function(t) 0.01000000+0.01021486*t+0.00915602*t^2-0.01485179*t^3
curve(seg1, 0, 2/12)

seg2 <- function(t) 0.01145666+0.00758914*t+0.01521279*t^2+0.09378380*t^3
curve(seg2, 2/12, 5/12)

seg3 <- function(t) 0.00000000+0.02320514*t+0.00490835*t^2-0.08080547*t^3
curve(seg3, 5/12, 11/12)

seg4 <- function(t) 0.02215231-0.02425796*t-0.00962054*t^2+0.02154812*t^3
curve(seg4, 11/12, 15/12)

使用相同的比例将 4 个段连接到同一张图中,区间为 0 到 1.25


我的原始输入不正确。 使用正确的输入,我得到了一条平滑的曲线

seg1

seg2

seg3

seg4

【问题讨论】:

    标签: r plot


    【解决方案1】:

    您想使用add=TRUE 参数。并且您需要在初始curve 中指定xlimylim 值。

    seg1 <- function(t) 0.01000000+0.01021486*t+0.00915602*t^2-0.01485179*t^3
    curve(seg1, 0, 2/12, xlim=c(0,1.25), ylim=c(-.1,.1))
    
    seg2 <- function(t) 0.01145666+0.00758914*t+0.01521279*t^2+0.09378380*t^3
    curve(seg2, 2/12, 5/12, add=TRUE)
    
    seg3 <- function(t) 0.00000000+0.02320514*t+0.00490835*t^2-0.08080547*t^3
    curve(seg3, 5/12, 11/12, add=TRUE)
    
    seg4 <- function(t) 0.02215231-0.02425796*t-0.00962054*t^2+0.02154812*t^3
    curve(seg4, 11/12, 15/12, add=TRUE)
    

    结果:

    【讨论】:

    • 我可以绘制相应的 seg(x) 点和 x=(0, 2/12, 5/12, 11/12, 15/12) 的值吗?
    • 听起来您要么想将points 添加到绘图中,要么在所有curve 函数中传递type='p'(点)或type='b'(点和线)参数,但我并不完全清楚。
    • 谢谢。我现在想出了如何很好地绘制它们。点(xy.coords(2/12, seg1(2/12)), add=TRUE) 点(xy.coords(5/12, seg2(5/12)), add=TRUE) 点(xy.coords( 11/12, seg3(11/12)), add=TRUE) points(xy.coords(15/12, seg4(15/12)), add=TRUE) text(2/12, seg1(2/12) , seg1(2/12), cex=0.5, pos=1, col="black") text(5/12, seg2(5/12), seg2(5/12), cex=0.5, pos=1, col="black") text(11/12, seg3(11/12), seg3(11/12), cex=0.5, pos=1, col="black") text(15/12, seg4(15/ 12), seg4(15/12), cex=0.5, pos=1, col="black")
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-30
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多