Dear Sir, I am using the following cos which creates a 3 panel figure on one image. However the legend function i am using only allows the legend to be placed within the axes of one of the graphs. The plots however do not allow for a logend to be places within the axes do to the location of points on the graph. I can add the legend later using imaging software such as paint but i lose resolution by doing this. Is it possible to place the legend out side of figure axes on the white area around all three panels? Any help would be greatly appreciated. Thank you Grant single<-read.table("C:\\Grant\\hatchfirstonly.txt",header=T) attach(single) names(single) par(mfrow=c(1,3)) maleage<- factor(maleage, labels = c("Old","Young")) colors <- c('gray', "navyblue") shapes <- c(17,19) proportion<-(eggs1-unhatch1)/eggs1 plot(proportion~maleage, xlab= "Age of Male ", ylab = "Proportion of Eggs Hatched") plot(proportion~femweight, pch=shapes[maleage], col=colors[maleage],bg="gray", xlab= "Female Weight (grams) ", ylab = " Proportion of Eggs Hatched") abline(lm(proportion~femweight)) plot(proportion~copdurationsecs, pch=shapes[maleage], col=colors[maleage],bg="gray", xlab= "Copulation Duration (minutes) ", ylab = " Proportion of Eggs Hatched") abline(lm(proportion~copdurationsecs)) legend(locator(1), as.character(levels(factor(maleage))),pch=shapes[maleage], col=colors[maleage])(levels(factor(maleage)))
On Oct 7, 2009, at 2:01 PM, McDonald, Grant wrote:> Dear Sir, > > I am using the following cos which creates a 3 panel figure on one > image. However the legend function i am using only allows the > legend to be placed within the axes of one of the graphs. > > The plots however do not allow for a logend to be places within the > axes do to the location of points on the graph. I can add the > legend later using imaging software such as paint but i lose > resolution by doing this. > > Is it possible to place the legend out side of figure axes on the > white area around all three panels? > Any help would be greatly appreciated.Doesn't mtext let you do what you want? perhaps: mtext("Desired Text", outer=TRUE)> single<-read.table("C:\\Grant\\hatchfirstonly.txt",header=T) > attach(single) > names(single) > par(mfrow=c(1,3)) > maleage<- factor(maleage, labels = c("Old","Young")) > colors <- c('gray', "navyblue") > shapes <- c(17,19) > proportion<-(eggs1-unhatch1)/eggs1 > plot(proportion~maleage, xlab= "Age of Male ", ylab = "Proportion of > Eggs Hatched") > plot(proportion~femweight, pch=shapes[maleage], > col=colors[maleage],bg="gray", xlab= "Female Weight (grams) ", ylab > = " Proportion of Eggs Hatched") > abline(lm(proportion~femweight)) > plot(proportion~copdurationsecs, pch=shapes[maleage], > col=colors[maleage],bg="gray", xlab= "Copulation Duration (minutes) > ", ylab = " Proportion of Eggs Hatched") > abline(lm(proportion~copdurationsecs)) > legend(locator(1), > as.character(levels(factor(maleage))),pch=shapes[maleage], > col=colors[maleage])(levels(factor(maleage)))David Winsemius, MD Heritage Laboratories West Hartford, CT
Hello, On Wed, Oct 7, 2009 at 2:01 PM, McDonald, Grant <grant.mcdonald08 at imperial.ac.uk> wrote:> > > > Dear Sir,Well, I'm not a "sir" but perhaps I can help anyway.> Is it possible to place the legend out side of figure axes on the white area around all three panels? > Any help would be greatly appreciated.Like this: plot(1:10, 1:10) par(xpd=NA) legend(locator(), "nothing", pch=1) Or instead of locator(), a function that lets you use a mouse click to select a point, you can use par("usr") to learn the current coordinate system, and select a value outside of that range. Sarah -- Sarah Goslee functionaldiversity.org
Here is another way of creating the legend using layout layout(cbind(1,2), width=c(7,1)) plot(1:10,1:10) # now create legend old.par <- par(mar=c(3, 0, 3, 0)) plot.new() legend('left', legend=c('line 1', 'line 2')) par(old.par) On Wed, Oct 7, 2009 at 2:01 PM, McDonald, Grant <grant.mcdonald08 at imperial.ac.uk> wrote:> > > > Dear Sir, > > I am using the following cos which creates a 3 panel figure on one image. ?However the legend function i am using only allows the legend to be placed within the axes of one of the graphs. > > The plots however do not allow for a logend to be places within the axes do to the location of points on the graph. ?I can add the legend later using imaging software such as paint but i lose resolution by doing this. > > Is it possible to place the legend out side of figure axes on the white area around all three panels? > Any help would be greatly appreciated. > > Thank you > Grant > > > > single<-read.table("C:\\Grant\\hatchfirstonly.txt",header=T) > attach(single) > names(single) > par(mfrow=c(1,3)) > maleage<- factor(maleage, labels = c("Old","Young")) > colors <- c('gray', "navyblue") > shapes <- c(17,19) > proportion<-(eggs1-unhatch1)/eggs1 > plot(proportion~maleage, xlab= "Age of Male ", ylab = "Proportion of Eggs Hatched") > plot(proportion~femweight, pch=shapes[maleage], col=colors[maleage],bg="gray", xlab= "Female Weight (grams) ", ylab = " Proportion of Eggs Hatched") > abline(lm(proportion~femweight)) > plot(proportion~copdurationsecs, pch=shapes[maleage], col=colors[maleage],bg="gray", xlab= "Copulation Duration (minutes) ", ylab = " Proportion of Eggs Hatched") > abline(lm(proportion~copdurationsecs)) > legend(locator(1), as.character(levels(factor(maleage))),pch=shapes[maleage], col=colors[maleage])(levels(factor(maleage))) > > ______________________________________________ > R-help at r-project.org mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide 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?