Jason Rupert
2009-Jun-27 03:48 UTC
[R] How to automatically placing a legend in empty space
(Sorry if this goes up to the site twice. I guess I am still learning how to post to R-Help) At one point I believe I heard of an R package that would automatically find the most empty space in a plot, and then that answer could then be used to intelligently place a legend. I would like to try to apply that R package to the contrived example shown below, so thank you for any hints or tips that can be provided. x = seq(0, 1000, by = 1) y1_vals<-rnorm(1000, mean = 0, sd = 50) y2_vals<-rnorm(1000, mean = 25, sd = 40) y3_vals<-rnorm(1000, mean = 115, sd = 40) plot(x_vals, y1_vals, pch=22, col="dark red", bg = "dark red", cex =0.3) points(x_vals, y2_vals, pch=22, col="dark blue", bg = "dark blue", cex =0.3) points(x_vals, y3_vals, pch=22, col="dark green", bg = "dark green", cex =0.3) abline(h=0, col="dark red", lwd=1.5, lty=6) abline(h=25, col="dark blue", lwd=1.5, lty=6) abline(h=115, col="dark green", lwd=1.5, lty=6) legend("topright", c("Best Guess 1" , "Best Guess 2", "Best Guess 3"), bg="white", lwd = 2, title = "Randomness:")
Dieter Menne
2009-Jun-27 10:37 UTC
[R] How to automatically placing a legend in empty space
Jason Rupert <jasonkrupert <at> yahoo.com> writes:> At one point I believe I heard of an R package that would automatically findthe most empty space in a plot, and> then that answer could then be used to intelligently place a legend. >Have a look a some of the plotting function in package Hmisc. Dieter
Jason Rupert
2009-Jun-28 04:10 UTC
[R] How to automatically placing a legend in empty space
I really apprecaite the suggestion. I just downloaded the Hmisc.pdf document and looked through it. Do you have any further thoughts about a specific function within the Hmisc package? I looked at largest.empty, but not sure how that is applicable to my data points. x = seq(0, 1000, by = 1) y1_vals<-rnorm(1000, mean = 0, sd = 50) y2_vals<-rnorm(1000, mean = 25, sd = 40) y3_vals<-rnorm(1000, mean = 115, sd = 40) plot(x_vals, y1_vals, pch=22, col="dark red", bg = "dark red", cex =0.3) points(x_vals, y2_vals, pch=22, col="dark blue", bg = "dark blue", cex =0.3) points(x_vals, y3_vals, pch=22, col="dark green", bg = "dark green", cex =0.3) abline(h=0, col="dark red", lwd=1.5, lty=6) abline(h=25, col="dark blue", lwd=1.5, lty=6) abline(h=115, col="dark green", lwd=1.5, lty=6) legend("topright", c("Best Guess 1" , "Best Guess 2", "Best Guess 3"), bg="white", lwd = 2, title = "Randomness:") Is there any chance you can provide a suggestion? Thanks again. --- On Sat, 6/27/09, Dieter Menne <dieter.menne at menne-biomed.de> wrote:> From: Dieter Menne <dieter.menne at menne-biomed.de> > Subject: Re: [R] How to automatically placing a legend in empty space > To: r-help at stat.math.ethz.ch > Date: Saturday, June 27, 2009, 5:37 AM > Jason Rupert <jasonkrupert > <at> yahoo.com> writes: > > > At one point I believe I heard of an R package that > would automatically find > the most empty space in a plot, and > > then that answer could then be used to intelligently > place a legend. > > > > Have a look a some of the plotting function in package > Hmisc. > > Dieter > > ______________________________________________ > 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. >