Hi R People: Here is a simple set of commands:>x1 <- 1:10 >x2 <- sqrt(x1) >plot(x1) >points(x2,col="red",pch=3) >legend(2,8,legend=c("First","Second"),col=c("black","red"),pch=c(1,3)) >Fine. Now, I would like to put the legend box on the outside of the plot itself, perhaps in the lower left hand corner. I've been messing with mtext, but to no avail. Any help would be much appreciated. R Version 1.9.1 Windows Thanks, Laura Holt mailto: lauraholt_983 at hotmail.com
Laura Holt <lauraholt_983 <at> hotmail.com> writes: : : Hi R People: : : Here is a simple set of commands: : : >x1 <- 1:10 : >x2 <- sqrt(x1) : >plot(x1) : >points(x2,col="red",pch=3) : >legend(2,8,legend=c("First","Second"),col=c("black","red"),pch=c(1,3)) : > : Fine. : Now, I would like to put the legend box on the outside of the plot itself, : perhaps in the lower : left hand corner. : : I've been messing with mtext, but to no avail. : : Any help would be much appreciated. Admittedly this is not what you have asked for but smartlegend in package gregmisc makes it very easy to position the legend in the plot area.
Laura Holt wrote:> Hi R People: > > Here is a simple set of commands: > >> x1 <- 1:10 >> x2 <- sqrt(x1) >> plot(x1) >> points(x2,col="red",pch=3) >> legend(2,8,legend=c("First","Second"),col=c("black","red"),pch=c(1,3)) >> > Fine. > Now, I would like to put the legend box on the outside of the plot > itself, perhaps in the lower > left hand corner.Set par(xpd=NA) before trying to place it there. See ?par for details. Uwe Ligges> I've been messing with mtext, but to no avail. > > Any help would be much appreciated. > > R Version 1.9.1 Windows > Thanks, > Laura Holt > mailto: lauraholt_983 at hotmail.com > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html
How about: par(omi = c(1, 1, 1, 1), xpd = NA) x1 <- 1:10 x2 <- sqrt(x1) plot(x1) points(x2,col="red",pch=3) legend(par("usr")[1],par("usr")[3] - 1.5,legend=c("First","Second"),col=c("black","red"),pch=c(1,3)) ? Note that you will have to play with the -1.5 to get it right in general. Partha "Laura Holt" <lauraholt_983 at hotmail.com> Sent by: r-help-bounces at stat.math.ethz.ch 08/19/2004 10:53 PM To: r-help at stat.math.ethz.ch cc: Subject: [R] legends on the outside of the "box" Hi R People: Here is a simple set of commands:>x1 <- 1:10 >x2 <- sqrt(x1) >plot(x1) >points(x2,col="red",pch=3) >legend(2,8,legend=c("First","Second"),col=c("black","red"),pch=c(1,3)) >Fine. Now, I would like to put the legend box on the outside of the plot itself, perhaps in the lower left hand corner. I've been messing with mtext, but to no avail. Any help would be much appreciated. R Version 1.9.1 Windows Thanks, Laura Holt mailto: lauraholt_983 at hotmail.com ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html