Dear helpers, I'm using a R script on several different datasets, which makes that axis scales may vary quite a lot from dataset to dataset. So what I'm looking for now, is how to automagically find out how to position the legend (horizontal) in the space below the x-axis title, and how to make sure that the legend is within the limits of the lower inner or outer margin? I'm aware of plot, device and figure regions, and of the "din, fin, pin, usr, mai, mar, omi, oma and xpd" parameters, of inner and outer margins. I cannot simply position my legend on "minus something", as that depends on "usr" coordinates, and those depend on the scale of the y-axis. I tried finding the ideal spot by taking the figure height and subtracting the upper margin, the height of the plot region, and half of the lower margin. This is quite tedious and doesn't help me, as I get a spot in inches, which doesn't to correspond to the "usr" coordinates. I also tried to convert between inches and "usr" coordinates using "xy.coords", but the result did not correspond to the position returned by "locator". I'm also aware of "mtext" and its fabulous arguments "side" and "line", but there I loose the functionality of displaying the legend symbols. Finally, I found a hint about using "layout", but there I admit I would need more than a hint - a small tutorial or graphical example with code would be very helpful. So, the question is, if there is per chance a way to pass "side" and "line" arguments to "legend", and if not, what is the best way to do what I try to do? BTW, the plot types involved are mostly line plots and barplots. Thanks a lot for your help, Anne-Marie
The inset= argument to legend does not depend on usr coordinates. On Wed, Jul 2, 2008 at 5:41 AM, Anne-Marie Ternes <amternes at gmail.com> wrote:> Dear helpers, > > I'm using a R script on several different datasets, which makes that > axis scales may vary quite a lot from dataset to dataset. So what I'm > looking for now, is how to automagically find out how to position the > legend (horizontal) in the space below the x-axis title, and how to > make sure that the legend is within the limits of the lower inner or > outer margin? > > I'm aware of plot, device and figure regions, and of the "din, fin, > pin, usr, mai, mar, omi, oma and xpd" parameters, of inner and outer > margins. > > I cannot simply position my legend on "minus something", as that > depends on "usr" coordinates, and those depend on the scale of the > y-axis. > > I tried finding the ideal spot by taking the figure height and > subtracting the upper margin, the height of the plot region, and half > of the lower margin. This is quite tedious and doesn't help me, as I > get a spot in inches, which doesn't to correspond to the "usr" > coordinates. > > I also tried to convert between inches and "usr" coordinates using > "xy.coords", but the result did not correspond to the position > returned by "locator". > > I'm also aware of "mtext" and its fabulous arguments "side" and > "line", but there I loose the functionality of displaying the legend > symbols. > > Finally, I found a hint about using "layout", but there I admit I > would need more than a hint - a small tutorial or graphical example > with code would be very helpful. > > So, the question is, if there is per chance a way to pass "side" and > "line" arguments to "legend", and if not, what is the best way to do > what I try to do? BTW, the plot types involved are mostly line plots > and barplots. > > Thanks a lot for your help, > > Anne-Marie > > ______________________________________________ > 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. >
Look at ?grconvertY, you can use this to convert from 'ndc' (normalized device coordinates) where 0 is the bottom of the device (window/page/...) to user coordinates that can be used in legend or other functions. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org (801) 408-8111> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Anne-Marie Ternes > Sent: Wednesday, July 02, 2008 3:42 AM > To: r-help at r-project.org > Subject: [R] position legend below x-axis title > > Dear helpers, > > I'm using a R script on several different datasets, which > makes that axis scales may vary quite a lot from dataset to > dataset. So what I'm looking for now, is how to automagically > find out how to position the legend (horizontal) in the space > below the x-axis title, and how to make sure that the legend > is within the limits of the lower inner or outer margin? > > I'm aware of plot, device and figure regions, and of the > "din, fin, pin, usr, mai, mar, omi, oma and xpd" parameters, > of inner and outer margins. > > I cannot simply position my legend on "minus something", as > that depends on "usr" coordinates, and those depend on the > scale of the y-axis. > > I tried finding the ideal spot by taking the figure height > and subtracting the upper margin, the height of the plot > region, and half of the lower margin. This is quite tedious > and doesn't help me, as I get a spot in inches, which doesn't > to correspond to the "usr" > coordinates. > > I also tried to convert between inches and "usr" coordinates > using "xy.coords", but the result did not correspond to the > position returned by "locator". > > I'm also aware of "mtext" and its fabulous arguments "side" > and "line", but there I loose the functionality of displaying > the legend symbols. > > Finally, I found a hint about using "layout", but there I > admit I would need more than a hint - a small tutorial or > graphical example with code would be very helpful. > > So, the question is, if there is per chance a way to pass > "side" and "line" arguments to "legend", and if not, what is > the best way to do what I try to do? BTW, the plot types > involved are mostly line plots and barplots. > > Thanks a lot for your help, > > Anne-Marie > > ______________________________________________ > 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. >