overlay two plots with different x scale

前端 未结 1 1662
名媛妹妹
名媛妹妹 2021-01-23 18:11

I would like to overlay two plots:

plot1

t1 <- c(0,1,2,3,4,5,6,7,8,9,10)
d1 <- c(0,2,4,6,8,10,12,14,16,18,20)

plot2



        
相关标签:
1条回答
  • 2021-01-23 19:01

    You can use lines for the second plot (instead of plot). Furthermore, we scale the x-axis values of the second plot (t2) with 2 (I(2 * t2)).

    plot(d1 ~ t1, col="black", type="l", xlim=c(0,10))
    lines(d2 ~ I(2 * t2), col="black", type="l", xlim=c(0,5))
    

    In this way, the x-range of the second plot is identical to the x-range of the first one.

    enter image description here

    0 讨论(0)
提交回复
热议问题