[R] legend/plotmath/substitute problem

Philipp Pagel philipp.pagel.lists at t-online.de
Thu Dec 14 23:05:50 CET 2006


	Dear R Experts,

I am trying to produce a legend for a series of plots which are
generated in a loop. The legend is supposed to look like this:

2000: gamma=1.8

where gamma is replaced by the greek letter and both the year and the
value of gamma are stored in variables.

Everything works fine as long as I have only one data series:

year = 2001
g = 1.9
plot(1)
legend('top', legend=substitute(paste(year, ': ', gamma, '=', g), list(year=year, g=g)) )


My problem starts, when I want to put more than one series of data in
the plot and accordingly need one legend row per data series:

year1 = 2001
year2 = 2005
g1 = 1.9
g2 = 1.7
plot(1)
legend('top', 
	legend=c(
		substitute(paste(year, ': ', gamma, '=', g), list(year=year1, g=g1)),
		substitute(paste(year, ': ', gamma, '=', g), list(year=year2, g=g2))
	)
)

This obviously does not produce the desired result. Apparently, I am not
generating a list of expressions, as intended. So I thought, maybe R uses a
variety of the recycling rule here and tried:

year = c(2001, 2005)
g = c(1.9, 1.7)
plot(1)
legend('top',
    legend=list(
        substitute(paste(year, ': ', gamma, '=', g), list(year=year, g=g)),
    )
)

No succes, either...

I have read and re-read the documentation for legend, expression, substitute
and plotmath but can't figure it out. Even drinking a cup of tea prepared from
fine-cut man page printouts didn't lead to satori.

I'm probably missing something simple. Any hints are highly appreciated.

Thanks
	Philipp

-- 
Dr. Philipp Pagel                            Tel.  +49-8161-71 2131
Dept. of Genome Oriented Bioinformatics      Fax.  +49-8161-71 2186
Technical University of Munich
85350 Freising, Germany
http://mips.gsf.de/staff/pagel



More information about the R-help mailing list