# [R] xtable without a loop alongside a ggplot

From: Justin Haynes <jtor14_at_gmail.com>
Date: Wed, 04 May 2011 08:57:53 -0700

I would like to create a table of my points and identify which 'quadrant' of a plot they are in with the 'origin' at the means. the kicker is i would like to display it right next to or below a ggplot of the data. Maybe xtable isnt the right thing to use, but its the only thing i can think of. Any help is appreciated!

set.seed(144)
x=rnorm(100,mean=5,sd=1)
test<-data.frame(x=x,y=x^2)
test\$right<-sapply(test\$x,function(x) {mean.x<-mean(test\$x);any(x>mean.x)}) test\$up<-sapply(test\$y,function(y) {mean.y<-mean(test\$y);any(y>mean.y)})

for(i in 1:length(test\$x)){
if(test\$right[i]==TRUE & test\$up[i]==TRUE) print(paste(rownames(test[i,]),'is in the upper right quadrant'))   if(test\$right[i]==FALSE & test\$up[i]==TRUE) print(paste(rownames(test[i,]),'is in the upper left quadrant'))   if(test\$right[i]==TRUE & test\$up[i]==FALSE) print(paste(rownames(test[i,]),'is in the lower right quadrant'))   if(test\$right[i]==FALSE & test\$up[i]==FALSE) print(paste(rownames(test[i,]),'is in the lower left quadrant')) }

I know theres a better way then using a for loop! and I haven't the foggiest how to use xtable. as i said, the ultimate goal is to create a plot with a table along side it showing outliers and where they appear using the inout function from the splancs package and a confidence ellipse from the ellipse package.

Thank you for your help as usual!

Justin

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. Received on Thu 05 May 2011 - 06:25:02 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 05 May 2011 - 07:00:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.