R 绘制2条曲线;实线代替虚线

R 绘制2条曲线;实线代替虚线,r,plot,R,Plot,我想在一张图中画两个函数 r <- rnorm(20,0,1) z <- c(1,1,1,1,1,-1,-1,-1,1,-1,1,1,1,-1,1,1,-1,-1,1,-1) data <- as.data.frame(na.omit(cbind(z, r))) series1 <- ts(cumsum(c(1,data[,2]*data[,1]))) series2 <- ts(cumsum(c(1,data[,2]))) 给出了: 系列2的曲线现在是一条虚线

我想在一张图中画两个函数

r <- rnorm(20,0,1)
z <- c(1,1,1,1,1,-1,-1,-1,1,-1,1,1,1,-1,1,1,-1,-1,1,-1)
data <- as.data.frame(na.omit(cbind(z, r)))
series1 <- ts(cumsum(c(1,data[,2]*data[,1])))
series2 <- ts(cumsum(c(1,data[,2])))
给出了:

系列2的曲线现在是一条虚线

我有两个问题:

1) 如何将虚线改为实线

2) 两个图中均未显示轴的标题。我怎样才能解决这个问题


提前感谢。

作为
matplot
的替代方案,您可以将
plot
行结合使用:

plot(series1, xlab="Time", ylab="Value", xaxt="n")
lines(series2, col="red")
这使得:


附带说明:使用随机生成的值时,请始终使用
set.seed()
。你可以这样做:

set.seed(1)
r <- rnorm(20,0,1)
z <- c(1,1,1,1,1,-1,-1,-1,1,-1,1,1,1,-1,1,1,-1,-1,1,-1)
data <- as.data.frame(na.omit(cbind(z, r)))
series1 <- ts(cumsum(c(1,data[,2]*data[,1])))
series2 <- ts(cumsum(c(1,data[,2])))
set.seed(1)

r下面的代码应该会给出所需的结果:

matplot(cbind(series1, series2), xaxt = "n", xlab = "Time", 
        ylab = "Value", col = 1:3, ann = TRUE, type = 'l', 
        lty = 1)

主要的选择是:

  • ann=TRUE
  • type='l'

lty=1
也很重要,要有实线。注意:您也可以使用
lty=“solid”
lty=“domind”
。最后,我将添加
las=1
以具有水平轴标签,并添加
lwd=2
以具有稍厚的线条。
matplot(cbind(series1, series2), xaxt = "n", xlab = "Time", 
        ylab = "Value", col = 1:3, ann = TRUE, type = 'l', 
        lty = 1)