Hello, I am new to R and need some help with the legend. How can I add a legend for two variables (in two columns) each having multiple values to be explained in the legend. For example: Var 1 Var 2 <symbol> - Higher <symbol> - Higher <symbol> - Avg <symbol> - Avg <symbol> - Lower <symbol> - Lower I know we can use the "ncol" option but not sure how to put in the values of the variable. Can we use the legend function of this? If yes, how? Thank you. -- View this message in context: http://r.789695.n4.nabble.com/Help-needed-with-legend-tp2124457p2124457.html Sent from the R help mailing list archive at Nabble.com.
A small executable example would help here. We don't even know how you are graphing this. There are several packages including lattice and ggplot as well as the base graphs. If you are doing this in base graphics have a look at ?text --- On Mon, 5/3/10, Nish <nisha.muktewar at gmail.com> wrote:> From: Nish <nisha.muktewar at gmail.com> > Subject: [R] Help needed with legend > To: r-help at r-project.org > Received: Monday, May 3, 2010, 3:10 PM > > Hello, > > I am new to R and need some help with the legend. How can I > add a legend for > two variables (in two columns) each having multiple values > to be explained > in the legend. For example: > > Var 1? ? ? ? ? ? ? > ? ? ? ? ? ???Var 2 > <symbol> - Higher? ? ? > ???<symbol> - Higher > <symbol> - Avg? ? ? ? ? > ? <symbol> - Avg > <symbol> - Lower? ? ? > ???<symbol> - Lower > > I know we can use the "ncol" option but not sure how to put > in the values of > the variable. Can we use the legend function of this? If > yes, how? > > Thank you. > > > -- > View this message in context: http://r.789695.n4.nabble.com/Help-needed-with-legend-tp2124457p2124457.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >
Something like this? plot(0,0) legend.text<-c("VAR 1","Higher","Average","Lower","VAR 2","Higher","Average","Lower") legend.pch=1:8 legend.col=c(0,1,1,1,0,1,1,1) legend("bottomright",legend=legend.text,pch=legend.pch,col=legend.col,ncol=2) -tgs On Mon, May 3, 2010 at 3:10 PM, Nish <nisha.muktewar@gmail.com> wrote:> > Hello, > > I am new to R and need some help with the legend. How can I add a legend > for > two variables (in two columns) each having multiple values to be explained > in the legend. For example: > > Var 1 Var 2 > <symbol> - Higher <symbol> - Higher > <symbol> - Avg <symbol> - Avg > <symbol> - Lower <symbol> - Lower > > I know we can use the "ncol" option but not sure how to put in the values > of > the variable. Can we use the legend function of this? If yes, how? > > Thank you. > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Help-needed-with-legend-tp2124457p2124457.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >[[alternative HTML version deleted]]