如何判断 R 图中的线是什么
How to tell what line is what in R plots
我目前有一些时间序列数据,我正在绘制它。
当我绘制它时,每条不同的线都以不同的颜色出现,这很好但是我不知道哪种颜色对应哪组数据。
下面是我的一些数据和显示的图表。
head(dbtw)
NSW1.Price Coal Gas Hydro PV Solar Wind
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(legend)
告诉我们 lty, lwd the line types and widths for lines appearing in the legend. One of these two must be specified for line drawing.
- 快速查看
addLegend
的源代码(RStudio
中的 View(addLegend)
)告诉我们它没有指定其中任何一个。
说来话长。这是一个代表:
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
我目前有一些时间序列数据,我正在绘制它。
当我绘制它时,每条不同的线都以不同的颜色出现,这很好但是我不知道哪种颜色对应哪组数据。
下面是我的一些数据和显示的图表。
head(dbtw)
NSW1.Price Coal Gas Hydro PV Solar Wind
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(legend)
告诉我们lty, lwd the line types and widths for lines appearing in the legend. One of these two must be specified for line drawing.
- 快速查看
addLegend
的源代码(RStudio
中的View(addLegend)
)告诉我们它没有指定其中任何一个。
说来话长。这是一个代表:
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