R, how to use pch with time series plot

637 views Asked by At

I would like to plot a time series (meaning line graph with x axis as time) and specify a plotting character to use. None of the following has worked

a1 = as.xts(ts(c(5,3,7,2,4,8,3), start=c(1980,1), freq=4))


library('lattice')
xyplot(a1, col="red", pch=2)

xyplot(a1, col="red", par.settings = list(superpose.symbol = list(col = 1, pch = 2)),)

ts.plot(ts(a1), pch=2)
plot(a1, phc=2)

I would prefer a lattice solution, but would accept any solution if lattice can not do this.

1

There are 1 answers

0
Alex A. On BEST ANSWER

By default, time series plots in R use type = "l", which means that you get a line but no point characters. To get both, you can change your type to "b".

xyplot(a1, col = "red", pch = 2, type = "b")

This yields:

enter image description here

The same logic applies to the base plot function; simply add type = "b".