[R] plot function creating bars instead of lines
la mer
melissarosenkranz at gmail.com
Mon Apr 23 17:25:12 CEST 2012
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.
More information about the R-help
mailing list