如何判断R图中的哪条线是什么

如何判断R图中的哪条线是什么,r,plot,graph,time-series,xts,R,Plot,Graph,Time Series,Xts,我目前有一些时间序列数据,我正在绘制它 当我绘制它时,每一条不同的线以不同的颜色出现,这很好,但是我不知道哪种颜色对应于哪组数据 下面是我的一些数据和显示的图表 head(dbtw) NSW1.煤气水电光伏太阳能风电价格 2018-01-01 10:30:00 71.34571 71.07403 89.78488 80.62076 75.73009 76.06731 71.07516 2018-01-08 10:30:00 69.84917 75.57009 90.70968 85.53

我目前有一些时间序列数据,我正在绘制它

当我绘制它时,每一条不同的线以不同的颜色出现,这很好,但是我不知道哪种颜色对应于哪组数据

下面是我的一些数据和显示的图表

head(dbtw)
NSW1.煤气水电光伏太阳能风电价格
2018-01-01 10:30:00   71.34571 71.07403 89.78488 80.62076 75.73009 76.06731 71.07516
2018-01-08 10:30:00   69.84917 75.57009 90.70968 85.53869 81.16248 81.35853 74.72455
2018-01-15 10:30:00   73.28426 71.11159 84.50934 79.76321 73.85233 73.46695 67.40529
2018-01-22 10:30:00   73.53699 83.50025 93.42689 95.70735 93.25567 93.78646 80.18604
2018-01-29 10:30:00   85.63705 81.84558 92.62425 92.18889 92.76306 92.07045 78.42529
2018-02-05 10:30:00 72.72682 72.26647 86.09123 81.15528 75.74744 76.10385 68.83338

当我键入
plot(dbtw)
时,会出现以下情况:


您可以使用
addLegend
,但诀窍是您需要指定
lty
lwd
。这是因为:

  • addLegend
    本质上是
    legend
  • help(图例)
    告诉我们
    lty,lwd是图例中出现的线条的类型和宽度。必须为线条绘制指定这两个选项中的一个。
  • 快速浏览
    addLegend
    RStudio
    中的
    View(addLegend)
    )的源代码,我们会发现它没有指定这两个选项
总而言之。这是一个reprex:

library(xts)
data("anscombe", package = "datasets")
ans6 <- xts(anscombe[, 1:6], order.by = as.Date("2008-01-01") + 1:nrow(anscombe))

## Will NOT have the line colors
plot(ans6)
addLegend()

## Will have the line colors
plot(ans6)
addLegend(lty = 1)
## addLegend(lwd = 1) # this would also work