Here is a runable program. When I plot Day and Wgt, it graphs all the data points. All I need is daily.sub1 plotted. I also need each "Tanks" to have its own col or pch. When I run it with the line with pch, it gives me nothing. rm(list=ls()) Trial<-rep(c(1,2),each=12) Tanks=rep(c("a3","a4","c4","h4"),each=3,2) Day=rep(c(1:12),2) Wgt=c(1:24) daily<-cbind(Trial, Tanks, Day, Wgt) daily daily.sub<-subset(daily, subset=Trial==2 & Tanks=="a4"|Trial==2 & Tanks=="c4"|Trial==2 & Tanks=="h4") daily.sub1<-as.data.frame(daily.sub) attach(daily.sub1) daily.sub1 x11() plot(Day, Wgt) #plot(Day, Wgt, pch=c(2,19,21)[Tanks]) detach(daily.sub1) -- M. Keith Cox, Ph.D. Alaska NOAA Fisheries, National Marine Fisheries Service Auke Bay Laboratories 17109 Pt. Lena Loop Rd. Juneau, AK 99801 Keith.Cox@noaa.gov marlinkcox@gmail.com U.S. (907) 789-6603 [[alternative HTML version deleted]]
On 2/2/2010 2:51 PM, Marlin Keith Cox wrote:> Here is a runable program. When I plot Day and Wgt, it graphs all the data > points. All I need is daily.sub1 plotted. I also need each "Tanks" to have > its own col or pch. When I run it with the line with pch, it gives me > nothing.DF <- data.frame(Trial=rep(c(1,2),each=12), Tanks=rep(c("a3","a4","c4","h4"),each=3,2), Day=rep(c(1:12),2), Wgt=c(1:24)) with(subset(DF, Trial==2 & Tanks %in% c("a4",'c4','h4')), plot(Day, Wgt, pch=as.numeric(Tanks))) library(lattice) trellis.device(new=TRUE, color=FALSE) xyplot(Wgt ~ Day, groups=Tanks, data=subset(DF, Trial==2 & Tanks %in% c("a4",'c4','h4')), par.settings=list(superpose.symbol=list(pch=c(2,19,21))))> rm(list=ls()) > Trial<-rep(c(1,2),each=12) > Tanks=rep(c("a3","a4","c4","h4"),each=3,2) > Day=rep(c(1:12),2) > Wgt=c(1:24) > daily<-cbind(Trial, Tanks, Day, Wgt) > daily > daily.sub<-subset(daily, subset=Trial==2 & Tanks=="a4"|Trial==2 & > Tanks=="c4"|Trial==2 & Tanks=="h4") > daily.sub1<-as.data.frame(daily.sub) > attach(daily.sub1) > daily.sub1 > x11() > plot(Day, Wgt) > #plot(Day, Wgt, pch=c(2,19,21)[Tanks]) > detach(daily.sub1)-- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894
The problem is with attach. You should have seen an error that the objects are aliased. You have Tanks in your workspace and in the attached dataframe. It is using the one in your workspace which is not a factor variable. Try: c(2,19,21)[Tanks] with(daily.sub1,c(2,19,21)[Tanks]) Avoid attach and use with which is a temporary attach that won't be subject to that problem. --jeff On 2/2/2010 11:51 AM, Marlin Keith Cox wrote:> Here is a runable program. When I plot Day and Wgt, it graphs all the data > points. All I need is daily.sub1 plotted. I also need each "Tanks" to have > its own col or pch. When I run it with the line with pch, it gives me > nothing. > > rm(list=ls()) > Trial<-rep(c(1,2),each=12) > Tanks=rep(c("a3","a4","c4","h4"),each=3,2) > Day=rep(c(1:12),2) > Wgt=c(1:24) > daily<-cbind(Trial, Tanks, Day, Wgt) > daily > daily.sub<-subset(daily, subset=Trial==2& Tanks=="a4"|Trial==2& > Tanks=="c4"|Trial==2& Tanks=="h4") > daily.sub1<-as.data.frame(daily.sub) > attach(daily.sub1) > daily.sub1 > x11() > plot(Day, Wgt) > #plot(Day, Wgt, pch=c(2,19,21)[Tanks]) > detach(daily.sub1) > >