绘制两个不同长度的系列x = 61个数据实例,y = 46
x<-c(0.1800, 0.1000, -0.0560 -0.1400, -0.0420, 0.0060, -0.0460, -0.0060, 0.0190,
-0.0420, 0.0610, 0.0530, 0.0610, -0.0040, -0.0700, -0.0450, -0.0250, 0.3120,
-0.0540, 0.1400, 0.0730, 0.0840, -0.0170, -0.0530, -0.1340, 0.2440, 0.0380,
-0.0260, 0.1080, 0.0440, 0.0920, 0.0060, 0.1260, 0.2690, -0.0710, 0.1780,
0.1680, 0.0650, 0.0150, 0.0420, -0.0480, 0.2750, 0.0760, 0.0580, 0.0360,
-0.0290, 0.0772, -0.0896, -0.0831, -0.2352, 0.0239, -0.0571, 0.1050, 0.0694,
-0.0423, 0.0158, 0.0793, -0.0546, -0.0351, -0.0388, -0.0137)
y<-c(0.4973210021, 0.3171289371, 0.3524071954, 0.5445361214, 0.5045483757,
0.4791933558, 0.5961864772, 0.6655933714, 0.6616273005, 0.5633990851,
0.2486985634, 0.2624092943, 0.4624224429, 0.3630349240, 0.3613897096,
0.4500961318, 0.6074131070, 0.4924340721, 0.4887700647, 0.3886799286,
0.6301570294, 0.7013215936, 0.7296446438, 0.6717751410, 0.5550540756,
0.3225643827, 0.2157955431, -0.1095368716, 0.3128888137, 0.3291106325,
0.3341775845, 0.3872107617, 0.4021650438, 0.5742174861, 0.9327782888,
0.5588426942, 0.7909656688, 0.8510349467, 0.7665466023, 0.8021267456,
0.8162197984, 0.9820833976 , 0.8577352252, 0.6558680486, 0.6534645172,
0.6546571333)
想要将一个图表中的两个系列绘制在x的15个数据实例(两个系列同时结束)之后的y(较短的系列)中,而不会错过图表中x的前15个数据实例。 / p>
谢谢
贝尔纳贝
答案 0 :(得分:1)
您可以尝试类似的行:
plot(var1T ~ var1S, type="l",col="red", xlim=range(c(var1S,var2S)), ylim=range(c(var1T,var2T)))
par(new=T)
plot(var2T ~ var2S, type="l",col="green", xlim=range(c(var1S,var2S)), ylim=range(c(var1T,var2T)))
答案 1 :(得分:1)
从每个系列创建时间序列,然后绘制它们:
x.ts <- ts(x)
y.ts <- ts(y, start = 15)
ts.plot(x.ts, y.ts, col = 1:2, lty = 1:2)
legend("topleft", c("x", "y"), col = 1:2, lty = 1:2) # optional
答案 2 :(得分:0)
您可以使用ggplot执行此操作:
z <- seq_len(60) # length of x
mydf <- data.frame(cbind(z, c(numeric(14), y), x)) # bind together in df
# for ggplot
colnames(mydf) <- c("ob", "y", "x")
ggplot() + geom_line(data=mydf, aes(x=ob, y=x, color="red")) +
geom_line(data=mydf[15:60,], aes(x=ob, y=y, color="black")) +
scale_colour_manual(name="Series", values=c("red"="red", "black"="black"), labels=c("y", "x"))