Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: Greek letters in ylab of `plot.ts()`

plot.ts() provides a convenient way to visualize multivariate time series. Unfortunately, I can't figure out how to annotate the (repeated) horizontal axes with Greek letters. The familiar approach for inserting Greek letters seems not to work and nor do some less clever approaches I've tried:

testdata = matrix(rnorm(300), ncol = 3)
# doesn't work
plot.ts(testdata, ylab = expression(paste(pi[0], " = 0")))
# doesn't work
plot.ts(testdata, ylab = c(expression(paste(pi[0], " = 0")),
                           expression(paste(pi[0], " = 1")),
                           expression(paste(pi[0], " = 2"))))
# doesn't work
colnames(testdata) = c(expression(paste(pi[0], " = 0")),
                       expression(paste(pi[0], " = 1")),
                       expression(paste(pi[0], " = 2")))
plot.ts(testdata)
# doesn't work
plot.ts(testdata, ylab = parse(text = y))

I've run out of ideas ...

like image 913
Zoë Clark Avatar asked Nov 19 '25 07:11

Zoë Clark


1 Answers

There is a solution using library(zoo)

testdata = matrix(rnorm(300), ncol = 3)
plot(zoo::as.zoo(testdata),ylab=c(expression(mu),expression(sigma),expression(beta)),main="Win!")

enter image description here

adapted from http://r.789695.n4.nabble.com/How-to-change-the-label-in-plot-ts-td796114.html

like image 175
Timo Kvamme Avatar answered Nov 20 '25 20:11

Timo Kvamme



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!