Skip to content

display math with subscripts from a sequence

2 messages · Ranjan Maitra, Duncan Murdoch

#
Dear friends,

I am trying to display a sequence of characters x_1, x_2, ... x_30 on a plot.

I know that I can use expression to  do this by expression("x"[1]), etc. But, how do I do this efficiently for an entire sequence without having to type the individual expressions one by one?

Many thanks,
Ranjan
#
On 18/04/2020 3:10 p.m., Ranjan Maitra wrote:
e <- expression()
for (i in 1:30) e <- c(e, eval(substitute(expression(x[i]), list(i = i))))
plot(1:30, 1:30, type="n")
text(1:30, 1:30, labels=e)

Duncan Murdoch