Re: [R] Automatically placing a legend in an area with the most white space...

2009-06-29 Thread Frank E Harrell Jr
Also check out the Hmisc package's largest.empty and putKeyEmpty and 
related functions.


Frank


Jason Rupert wrote:
That fixed it.  I thought I was getting the hang of R, but I guess I still have a long way to go.  

One last question regarding the dynamic placement of the legend in the location on a plot with the largest empty space, is there a way to assure that the legend doesn't go off the plot or is partially clipped by the boarder of the plot? 


I posted the example to nabble:
http://n2.nabble.com/With-%22emptyspace%22-is-there-anyway-to-guarantee-legend-won%27t-be-off-the-plot--td3178773.html

Thanks for any feedback. 

Jason 





--- On Sun, 6/28/09, Stavros Macrakis  wrote:


From: Stavros Macrakis 
Subject: Re: [R] Automatically placing a legend in an area with the most white  
space...
To: "Jason Rupert" 
Cc: "Jim Lemon" , R-help@r-project.org
Date: Sunday, June 28, 2009, 3:16 PM

install.packages('plotrix')

On Sun, Jun 28, 2009 at 3:51 PM,
Jason Rupert 
wrote:

...

Error in legend(emptyspace(rep(x_vals_1, 3), c(y1_vals,
y2_vals, y3_vals)),  :

  could not find function "emptyspace"



I've searched via RSeek, but I have not been able to
find anything on this function.



Is emptyspace part of a package that I need to install?




--
Frank E Harrell Jr   Professor and Chair   School of Medicine
 Department of Biostatistics   Vanderbilt University

__
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.


Re: [R] Automatically placing a legend in an area with the most white space...

2009-06-29 Thread Jason Rupert

That fixed it.  I thought I was getting the hang of R, but I guess I still have 
a long way to go.  

One last question regarding the dynamic placement of the legend in the location 
on a plot with the largest empty space, is there a way to assure that the 
legend doesn't go off the plot or is partially clipped by the boarder of the 
plot? 

I posted the example to nabble:
http://n2.nabble.com/With-%22emptyspace%22-is-there-anyway-to-guarantee-legend-won%27t-be-off-the-plot--td3178773.html

Thanks for any feedback. 

Jason 




--- On Sun, 6/28/09, Stavros Macrakis  wrote:

> From: Stavros Macrakis 
> Subject: Re: [R] Automatically placing a legend in an area with the most 
> white  space...
> To: "Jason Rupert" 
> Cc: "Jim Lemon" , R-help@r-project.org
> Date: Sunday, June 28, 2009, 3:16 PM
> 
> install.packages('plotrix')
> 
> On Sun, Jun 28, 2009 at 3:51 PM,
> Jason Rupert 
> wrote:
> 
> ...
> 
> Error in legend(emptyspace(rep(x_vals_1, 3), c(y1_vals,
> y2_vals, y3_vals)),  :
> 
>   could not find function "emptyspace"
> 
> 
> 
> I've searched via RSeek, but I have not been able to
> find anything on this function.
> 
> 
> 
> Is emptyspace part of a package that I need to install?
> 
> 
> 
> 




__
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.


Re: [R] Automatically placing a legend in an area with the most white space...

2009-06-28 Thread Stavros Macrakis
install.packages('plotrix')

On Sun, Jun 28, 2009 at 3:51 PM, Jason Rupert wrote:

> ...
> Error in legend(emptyspace(rep(x_vals_1, 3), c(y1_vals, y2_vals, y3_vals)),
>  :
>  could not find function "emptyspace"
>
> I've searched via RSeek, but I have not been able to find anything on this
> function.
>
> Is emptyspace part of a package that I need to install?
>

[[alternative HTML version deleted]]

__
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.


Re: [R] Automatically placing a legend in an area with the most white space...

2009-06-28 Thread Jason Rupert

Jim, 

Thank you very much for your feedback.   It is very much appreciated to know 
this is possible.  

I tried to reproduce your post, but I ran into a problem:
> legend(emptyspace(rep(x_vals_1,3),c(y1_vals,y2_vals,y3_vals)), c("Best Guess 
> 1" , "Best Guess 2", "Best Guess 3"), xjust=0.5, yjust=0.5, 
> lty=1,col=c(2,4,3))

Error in legend(emptyspace(rep(x_vals_1, 3), c(y1_vals, y2_vals, y3_vals)),  : 
  could not find function "emptyspace"

I've searched via RSeek, but I have not been able to find anything on this 
function. 

Is emptyspace part of a package that I need to install? 

Thanks for any feedback. 


--- On Sun, 6/28/09, Jim Lemon  wrote:

> From: Jim Lemon 
> Subject: Re: [R] Automatically placing a legend in an area with the most 
> white space...
> To: "Jason Rupert" 
> Cc: R-help@r-project.org
> Date: Sunday, June 28, 2009, 4:04 AM
> Jason Rupert wrote:
> > 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:")
> > 
> >   
> Hi Jason,
> The good news is that the emptyspace function found the
> largest empty space in the plot. The bad news is that there
> was not nearly enough space to fit the legend:
> 
> legend(emptyspace(rep(x_vals,3),c(y1_vals,y2_vals,y3_vals)),
>  c("Best Guess 1" , "Best Guess 2", "Best Guess
> 3"),xjust=0.5,yjust=0.5,
> lty=1,col=c(2,4,3))
> 
> Note that I had to change the name of the first vector to
> "x_vals" to get the plot to work.
> 
> Jim
> 
> 




__
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.


Re: [R] Automatically placing a legend in an area with the most white space...

2009-06-28 Thread Jim Lemon

Jason Rupert wrote:
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:")

  

Hi Jason,
The good news is that the emptyspace function found the largest empty 
space in the plot. The bad news is that there was not nearly enough 
space to fit the legend:


legend(emptyspace(rep(x_vals,3),c(y1_vals,y2_vals,y3_vals)),
 c("Best Guess 1" , "Best Guess 2", "Best Guess 3"),xjust=0.5,yjust=0.5,
lty=1,col=c(2,4,3))

Note that I had to change the name of the first vector to "x_vals" to 
get the plot to work.


Jim

__
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.


[R] Automatically placing a legend in an area with the most white space...

2009-06-26 Thread Jason Rupert


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:")

__
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.