This will probably do what you need:
plot(1)
x <- 1:10 # numbers for the legend
blah <- LETTERS[1:5]
legendData <- character(5)
for (i in 1:5)
legendData[i] <- sprintf("Blah-%s %d %d", blah[i], x[2*i - 1],
x[2*i])
legend('topright', legend=legendData)
On Fri, Feb 6, 2009 at 6:57 PM, Vemuri, Aparna <avemuri at epri.com>
wrote:> I need to create a legend for a simple scatter plot in the following
> format.
>
> This is Blah1 number1 number2
> This is Blah2 number3 number4
> .
> .
> .
> This is Blah6 number11 number12
>
> I looked up these help pages and found the following solution.
> lStr<-c(Blah1, Blah2,....Blah6, number 1, number2, ...number12)
> legend(x="topright",lStr,ncol=3)
>
> So this creates the tabular format I am looking for. But the width of
> each column is matched to the width of the longest column. So the legend
> now looks like this:
>
> This is Blah1 number1 number2
> This is Blah2 number3 number4
> .
> .
> .
> This is Blah6 number11 number12
>
>
> And thus, I have the legend occupying most part of the top half of my
> plot. I was wondering if there is any way to fit in the legend compactly
> or even better to format the width of columns 2 and 3 in the legend and
> remove the blank spaces between them. I have tried rounding off the
> number values to 3 digits with no luck.
>
> I hope this is not too ambitious to ask.
>
> Thanks in advance!
> Aparna
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?