[R] how to compare different types of graphics in R

2012-06-09 Thread wcheckle
Dear R users:

I have a continuous outcome variable and four predictors, two continuous and
two dichotomous. i would like to use the lattice plot to create scatter
plots for the continuous predictors and boxplots for the dichotomous
predictors.

with 4 continuous variables, this is what i have been doing:

trial = rbind ( 
cbind ( cimt$ant.mean, cimt$age, 1 ),
cbind ( cimt$ant.mean, cimt$sbp, 2 ),
cbind ( cimt$ant.mean, cimt$ldl, 3 ),
cbind ( cimt$ant.mean, cimt$hdl, 4 ))

trial = as.data.frame(trial)
names(trial) = c("cimt","x","group")

trial$group.f =
factor(trial$group,label=c("Age(years)","SBP(mmHg)","LDL(mg/dL)","HDL(mg/dL)"))
x11(height=6,width=14)
xyplot (cimt~x|group.f, data=trial,
scale=list(x=list(relation="free")),as.table=T,col="dark grey",
strip=strip.custom(which.given=1, bg="transparent"),ylab="Mean CIMT
(mm)",layout=c(4,1),aspect=1:1,xlab="",pch=16)


Any recommendations how to use the lattice package in include 2 dichotomous
variables with two continuous variables?

thank you,

William


--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-compare-different-types-of-graphics-in-R-tp4632906.html
Sent from the R help mailing list archive at Nabble.com.

__
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] combining different types of graphics (scatterplots, boxplots) using lattice

2012-06-09 Thread wcheckle
Dear R users:

I have a continuous outcome variable and four predictors, two continuous and
two dichotomous. i would like to use the lattice plot to create scatter
plots for the continuous predictors and boxplots for the dichotomous
predictors.

with 4 continuous variables, this is what i have been doing:

trial = rbind (
cbind ( cimt$ant.mean, cimt$age, 1 ),
cbind ( cimt$ant.mean, cimt$sbp, 2 ),
cbind ( cimt$ant.mean, cimt$ldl, 3 ),
cbind ( cimt$ant.mean, cimt$hdl, 4 ))

trial = as.data.frame(trial)
names(trial) = c("cimt","x","group")

trial$group.f =
factor(trial$group,label=c("Age(years)","SBP(mmHg)","LDL(mg/dL)","HDL(mg/dL)"))
x11(height=6,width=14)
xyplot (cimt~x|group.f, data=trial,
scale=list(x=list(relation="free")),as.table=T,col="dark grey",
strip=strip.custom(which.given=1, bg="transparent"),ylab="Mean CIMT
(mm)",layout=c(4,1),aspect=1:1,xlab="",pch=16)


Any recommendations how to use the lattice package in include 2 dichotomous
variables with two continuous variables?

thank you,

William 

--
View this message in context: 
http://r.789695.n4.nabble.com/combining-different-types-of-graphics-scatterplots-boxplots-using-lattice-tp4632907.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Drawing a line in xyplot

2012-04-06 Thread wcheckle
i am trying to replicate the following graph using xyplot :

attach(x)
plot ( jitter(type), mortality, pch=16,  xlim = c(0.25, 3.75))
lines ( c(1-0.375,1.375) , c ( median(mortality[type==1]),
median(mortality[type==1])), lwd=5,col=2)
lines ( c(2-0.375,2.375) , c ( median(mortality[type==2]),
median(mortality[type==2])), lwd=5,col=2)
lines ( c(3-0.375,3.375) , c ( median(mortality[type==3]),
median(mortality[type==3])), lwd=5,col=2)
detach(x)

in the above graph, i draw a median line for "mortality" (range from 5 to
35) by "type" (1,2 or 3).  i now have an additional variable "attend" (0 or
1). within each panel (three panel, one for each "type"), i would like to
draw the median "mortality" for each instance of "attend".  i have been able
to get as far as plotting everything but the median lines:

x11(height=8,width=11)
xyplot ( mortality ~ attend|type, 
panel=function(x,y,subscripts){panel.grid(lty=5);
panel.xyplot(x,y,pch=16,jitter.x=TRUE,col=1)},
strip=strip.custom(which.given=1, bg="orange"),data
=x,aspect=2:1,layout=c(3,1))

any suggestions on how to add the median lines of "mortality" for each
instance of "attend" within each panel of "type"?

thank you



--
View this message in context: 
http://r.789695.n4.nabble.com/Drawing-a-line-in-xyplot-tp4538689p4538689.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Drawing a line in xyplot

2012-04-07 Thread wcheckle
here is the data (fyi this is made-up data)

x = as.data.frame (
cbind(c(5,8,7,5,8,10,11,6,4,5,20,25,27,30,35,32,28,21,20,34,11,15,18,12,15,12,10,15,19,20),
c(1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3),c(1,0,1,1,1,1,0,0,0,1,0,1,0,0,0,0,1,0,0,0,1,1,1,0,1,0,1,0,0,0)))
names(x)=c("mortality","type","attend")

here is the image:
http://r.789695.n4.nabble.com/file/n4539596/x.jpg 

revised code with image:

x11(height=8,width=11)
xyplot ( mortality ~ factor(attend)|type,
panel=function(x,y){panel.grid(lty=5);
panel.xyplot(x,y,pch=16,jitter.x=TRUE,col=1)},
strip=strip.custom(which.given=1, bg="orange"),data
=x,aspect=2:1,layout=c(3,1)) 

http://r.789695.n4.nabble.com/file/n4539596/x1.jpg 

i am trying to replicate the "red" mean lines on the xyplot graph

abline won't do it.  llines may be able to do it, but i don't know how to
use/implement

thanks



--
View this message in context: 
http://r.789695.n4.nabble.com/Drawing-a-line-in-xyplot-tp4538689p4539596.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Drawing a line in xyplot

2012-04-07 Thread wcheckle
Thank you David, the bwplot option does what I need:

x11(height=8,width=11)
bwplot ( mortality~ attend|type,
 pch=95,cex=5,col=2,
 par.settings=list(
  box.rectangle = list(col = "transparent"),
  box.umbrella = list(col = "transparent"),
  plot.symbol = list(col = "transparent")
 ),
 panel=function(x,y,...){
  panel.grid(lty=5)
  panel.xyplot(x,y,pch=16,jitter.x=TRUE,col=1)
  panel.bwplot(x,y,...)
 },
data = x,aspect=2:1,layout=c(3,1))


However, I am interested in also learning how to do it in xyplot as well.  I
wasn’t able to follow the last two set of instructions (condition on
packet.number and loop over segments), wondering if I can ask for your help
for the correct code (my attempt resulted in all three mean lines within
each panel):

x11(height=8,width=11)
xyplot ( mortality ~ attend|type, 
panel=function(x,y)
{
panel.grid(lty=5)
panel.xyplot(x,y,pch=16,jitter.x=TRUE,col=1)
for(i in 1:3)
{
panel.segments(x0=c(0.7, 1.7),
x1=c(1.3, 2.3),
y0=c(tapply(x$mortality[x$type==i], x$attend[x$type==i], median)), 
y1=c(tapply(x$mortality[x$type==i], x$attend[x$type==i],
median)),col="red",lwd=4)
}   
},
data = x,aspect=2:1,layout=c(3,1))

thank you again. I also found your info on data.frame useful.



--
View this message in context: 
http://r.789695.n4.nabble.com/Drawing-a-line-in-xyplot-tp4538689p4540389.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Drawing a line in xyplot

2012-04-08 Thread wcheckle
i appreciate all the interest in my question, and thank you Elai for both of
your suggestions, which work very well.
Elai, your last code was particularly simple and helpful to generate the
figure i was looking for.

x11(height=8,width=11)
par(lend=2)
xdat = data.frame(mortality =c(5,
8,7,5,8,10,11,6,4,5,20,25,27,30,35,32,28,21,20,34,11,15,18,12,15,12,10,15,19,20),
type=
c(1, 1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3), attend =
c(1, 0,1,1,1,1,0,0,0,1,0,1,0,0,0,0,1,0,0,0,1,1,1,0,1,0,1,0,0,0))
xyplot ( mortality ~ factor(attend)|type,
panel=function(x,y)
{
panel.grid(lty=5)
panel.xyplot(x,y,pch=16,jitter.x=TRUE,col=1)
yy<- tapply(y,x,median)
panel.segments(x0=c(0.7,1.7), x1=c(1.3,2.3), y0= yy , y1= yy ,
col="red",lwd=5)
},
data = xdat, aspect=2:1,layout=c(3,1))

http://r.789695.n4.nabble.com/file/n4541912/trial.jpg 

as a side note, the par(lend=2) function did not square the ends of the
lines for panel.segments in xyplot (i was trying to get square ends instead
of round ends).

John: thank you for your information regarding latticeExtra and the layer
function, which will be helpful for future figures.


--
View this message in context: 
http://r.789695.n4.nabble.com/Drawing-a-line-in-xyplot-tp4538689p4541912.html
Sent from the R help mailing list archive at Nabble.com.

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