I have to color the price plot differently based on the cluster given by the kmeans
function. Consider this code:
library(tseries)
####
nomiequity <- "^IXIC"
datastart <- "2019-09-18"
nsdq.prices <- get.hist.quote(instrument = nomiequity,
compression = "d",
start = datastart,
end = "2020-12-31",
retclass = "zoo",
quote = "AdjClose")
b<-kmeans(nsdq.prices,3)
c<-b$cluster
d<- merge(nsdq.prices, c)
e<-split(nsdq.prices, c)
plot(nsdq.prices, type="l", col="green", ylim=c(6000, 13000))
lines(e[["2"]], type = "l", col="red")
lines(e[["3"]], type = "l", col="blue")
The result is almost what I need to do, but I don't want to show those connection between same colors in diffent time.