Skip to content
Back to formatted view

Raw Message

Message-ID: <CAM+rpY=eQScf8OKZRfJ8b186dS9FwgNiC0QhmVv54h3PR1FUmg@mail.gmail.com>
Date: 2018-05-01T20:17:18Z
From: Christopher W. Ryan
Subject: How would I color points conditional on their value in a plot of a time series

How would I color points conditional on their value in a plot of a time
series.  Something like this:

## demonstration data
ttt <- ts(rpois(12, lambda = 8), start = c(2000, 1), freq = 4)
ttt
plot(ttt, type = "p")

## doesn't work--all points the same color
plot(ttt, type = "p", col = ifelse(ttt < 8, "black", "red"))

## also doesn't work--all points the same color
q <- as.numeric(ttt)
q
plot(ttt, type = "p", col = ifelse(q < 8, "black", "red"))


## works OK with a simple, non-time-series scatterplot, as in

sss <- data.frame(x = rpois(12, lambda = 8), y = rnorm(12, mean = 100, sd =
25))
with(sss, plot(y ~ x, col = ifelse(y > 100, "black", "red")))

## but I am missing something about time series.

Thanks.

--Chris Ryan
Broome County Health Department
and Binghamton University
Binghamton, NY

	[[alternative HTML version deleted]]