在R中,ts.plot(gpars col = c(“ red”,“ blue”)仅返回一个彩色图)

时间:2019-02-22 19:09:50

标签: r ggplot2 plot

我在ts.plot中无法获得红色和黑色两种颜色     要求(图形)

ts.plot(window(CPI_ts,
           start=c(2012, 1),
           end=c(2019, 12)),
    window(IIP_ts,
          start=c(2012, 1),
          end=c(2019, 12)),

    gpars=list(xlab="Year",
               ylab="Index",
               col=c("red", "blue"),
               lwd=2))
  legend("topleft", bty="n", lty=c(1,1), col=c("red","blue"),
   legend=c(" IIP ", "CPI "))[CPI IIP index of india][1]

1 个答案:

答案 0 :(得分:1)

直接将参数提供给函数。这应该起作用。

ts.plot(ts(rnorm(100), start = c(2001,1)),
        ts(rnorm(100), start = c(2001,1)), 
    col = c("red", "blue"), 
    xlab = "Year", 
    ylab = "Index", 
    lwd = 2)

legend("topleft", bty="n", lty=c(1,1), col=c("red","blue"),
       legend=c(" IIP ", "CPI "))

enter image description here