Dear all, I have a multiline plot with each line labeled with a different letter. But I'm not able to make the legend display the same kind of pattern '-a-', instead the letter is overwritten by the line. A simpler legend with only the letter is not very visible and the pt.bg does nothing with letters. Any idea? plot(1:10,10:1,lty=1,type='b', lwd=2,pch='a') legend("left", legend=c("ds1","ds2"), bty='n', col=1:2, lty=2,lwd=4,pch=letters) Thanks for your help! mario -- Ing. Mario Valle Data Analysis and Visualization Group | http://www.cscs.ch/~mvalle Swiss National Supercomputing Centre (CSCS) | Tel: +41 (91) 610.82.60 v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax: +41 (91) 610.82.82
On 26.04.2010 13:32, Mario Valle wrote:> Dear all, > I have a multiline plot with each line labeled with a different letter. > But I'm not able to make the legend display the same kind of pattern > '-a-', instead the letter is overwritten by the line. A simpler legend > with only the letter is not very visible and the pt.bg does nothing with > letters. Any idea? > > plot(1:10,10:1,lty=1,type='b', lwd=2,pch='a') > legend("left", legend=c("ds1","ds2"), bty='n', col=1:2, > lty=2,lwd=4,pch=letters)I'd fake it rather quickly using lty="14" Uwe Ligges> Thanks for your help! > mario
You can try this: plot(1:10,10:1,lty=1,type='b', lwd=2,pch='a') text(2, pretty(10:1)[2] - 0.3, paste("\u2013 a \u2013", "ds1", sep = " "), col = 'black', font = 2) text(2, pretty(10:1)[2] - 0.6, paste("\u2013 b \u2013", "ds2", sep = " "), col = 'red', font = 2) rect(0, 0, 3, 2) On Mon, Apr 26, 2010 at 8:32 AM, Mario Valle <mvalle@cscs.ch> wrote:> Dear all, > I have a multiline plot with each line labeled with a different letter. > But I'm not able to make the legend display the same kind of pattern '-a-', > instead the letter is overwritten by the line. A simpler legend with only > the letter is not very visible and the pt.bg does nothing with letters. > Any idea? > > plot(1:10,10:1,lty=1,type='b', lwd=2,pch='a') > legend("left", legend=c("ds1","ds2"), bty='n', col=1:2, > lty=2,lwd=4,pch=letters) > > Thanks for your help! > mario > -- > Ing. Mario Valle > Data Analysis and Visualization Group | > http://www.cscs.ch/~mvalle <http://www.cscs.ch/%7Emvalle> > Swiss National Supercomputing Centre (CSCS) | Tel: +41 (91) 610.82.60 > v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax: +41 (91) 610.82.82 > > ______________________________________________ > R-help@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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Try this kludge: legend("left", c("-a-", "-b-", "ds1 ", "ds2 "), ncol = 2, text.col = 1:2) On Mon, Apr 26, 2010 at 7:32 AM, Mario Valle <mvalle at cscs.ch> wrote:> Dear all, > I have a multiline plot with each line labeled with a different letter. > But I'm not able to make the legend display the same kind of pattern '-a-', > instead the letter is overwritten by the line. A simpler legend with only > the letter is not very visible and the pt.bg does nothing with letters. Any > idea? > > plot(1:10,10:1,lty=1,type='b', lwd=2,pch='a') > legend("left", legend=c("ds1","ds2"), bty='n', col=1:2, > lty=2,lwd=4,pch=letters) > > Thanks for your help! > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?mario > -- > Ing. Mario Valle > Data Analysis and Visualization Group ? ? ? ? ? ?| > http://www.cscs.ch/~mvalle > Swiss National Supercomputing Centre (CSCS) ? ? ?| Tel: ?+41 (91) 610.82.60 > v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax: ?+41 (91) 610.82.82 > > ______________________________________________ > 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. >
I suspect that you may have to construct the legend by hand (well, by explicit text commands anyway) Something like this seems to work and it should not be that difficult to write a function to handle the text commands. plot(1:10,10:1,lty=1,type='b', lwd=2,pch='a') text(1.4,6, label="-a- ", col="red") text(2.5,6, label="dg1") --- On Mon, 4/26/10, Mario Valle <mvalle at cscs.ch> wrote:> From: Mario Valle <mvalle at cscs.ch> > Subject: [R] How to make legend with line+ character > To: "r-help at r-project.org" <r-help at r-project.org> > Received: Monday, April 26, 2010, 7:32 AM > Dear all, > I have a multiline plot with each line labeled with a > different letter. > But I'm not able to make the legend display the same kind > of pattern '-a-', instead the letter is overwritten by the > line. A simpler legend with only the letter is not very > visible and the pt.bg does nothing with letters. Any idea? > > plot(1:10,10:1,lty=1,type='b', lwd=2,pch='a') > legend("left", legend=c("ds1","ds2"), bty='n', col=1:2, > lty=2,lwd=4,pch=letters) > > Thanks for your help! > ??? ??? ??? > ??? mario > -- Ing. Mario Valle > Data Analysis and Visualization Group? ? ? > ? ? ? | http://www.cscs.ch/~mvalle > Swiss National Supercomputing Centre (CSCS)? ? > ? | Tel:? +41 (91) 610.82.60 > v. Cantonale Galleria 2, 6928 Manno, Switzerland | > Fax:? +41 (91) 610.82.82 > > ______________________________________________ > 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. >
Mario Valle wrote: > Dear all, > I have a multiline plot with each line labeled with a different letter. > But I'm not able to make the legend display the same kind of pattern '-a-', > instead the letter is overwritten by the line. A simpler legend with only > the letter is not very visible and the pt.bg does nothing with letters. > Any idea? > > plot(1:10,10:1,lty=1,type='b', lwd=2,pch='a') > legend("left", legend=c("ds1","ds2"), bty='n', col=1:2, > lty=2,lwd=4,pch=letters) > Hi Mario, This is probably too late and superfluous, but your question made me wonder if the legendg function would to this: legendg(0.2,0.25,c("letter","number"), pch=list(c("-","A","-"),c("-","1","-")), col=list(rep(2,3),rep(3,3))) It does. Jim