[R] plot function creating bars instead of lines

2012-04-23 Thread la mer
Hello,

I am having a problem where code that plots lines using a different data
frame plots bars with the current data frame (I am intended to plot lines).
The code specifies lines (see below), so I can't figure out why the results
are bars. I suspect that it may have something to do with the fact that in
the data frame where the code worked as intended, the both variables
specifying different lines were numeric, whereas in the current data frame
one of those variables (challenge) is a factor with 2 levels. Any
suggestions for getting this to plot as intended would be much appreciated.

Thank you!

 This is meant to plot a separate line for each subject for each
challenge*
for (subj in unique(lab.samples$subid)) {
#par(new=T)
plot.new()
par(mfrow=c(2,1))
par(mfg=c(1,1))
plot(data=lab.samples, subset=(subid==subj), cortisol ~ Sample, 
type='n', 
main=paste('Cortisol and Amylase for subject ', 
as.character(subj)))

for ( t in unique(subset(lab.samples,subid==subj)$challenge) ) {
par(mfg=c(1,1))
lines(data=lab.samples, subset=(subid==subj & challenge==t), 
cortisol ~ Sample, type='b', pch=as.character(t), 
col=rainbow(2)[t])
}
par(mfg=c(2,1))
plot(data=lab.samples, subset=(subid==subj), amylase ~ Sample, type='n')
for ( t in unique(subset(lab.samples,subid==subj)$challenge) ) {
par(mfg=c(2,1))
lines(data=lab.samples, subset=(subid==subj & challenge==t), 
amylase ~ Sample, type='b', pch=as.character(t), 
col=heat.colors(2)[t])
}
}   


--
View this message in context: 
http://r.789695.n4.nabble.com/plot-function-creating-bars-instead-of-lines-tp4580765p4580765.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] using "factor" to eliminate unused levels without dropping other variables

2012-04-21 Thread la mer
That did the trick! Thank you much, Richard Heiberger.

--
View this message in context: 
http://r.789695.n4.nabble.com/using-factor-to-eliminate-unused-levels-without-dropping-other-variables-tp4577123p4577206.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.