[R] Subset and point plot

Peter Ehlers ehlers at ucalgary.ca
Tue Feb 2 19:56:43 CET 2010

I tried your code and a funny thing happened: I got an

  object 'Foodin' not found

Hmmm; could you try to post something _reproducible_
(and minimal, please)?

But here are some suggestions:
1. investigate '%in%'
2. put a comma after Wgt in your plot call
3. see what you get from


4. assuming that 'Tanks' is a factor, see what you get from


  -Peter Ehlers

Marlin Keith Cox wrote:
> OK, I need help plotting.  I have column headings of Day, Wgt, Foodin, Rep,
> Grp and Tanks.  Rep=c(1,2,3) and Tanks=c(a1,a2,a3,a4,a5,a6,
> c1,c2,c3,c4,c5,c6, h1,h2,h3,h4,h5,h6).
> I created a subset where I only would like Rep=2, and Tanks=c(a4,c4,h4) and
> would like to graph (points) of Wgt and Day.  I would think that I only need
> 3 colors, but when I run with only 3, only 2 lines show up.  When I add a
> 4th color (pink in this case), I get the 3rd line.  If I subset for
> c(a1,a2,a3), it works using three colors.  Should be simple, but I dont see
> it.
> rm(list=ls())
> daily<-subset(raw, subset=Foodin>1 & Rep==2 & Grp=="fed" & Tanks=="a4"|
> Foodin>1 & Rep==2 & Grp=="fed" & Tanks=="c4"|Foodin>1 & Rep==2 & Grp=="fed"
> & Tanks=="h4")
> attach(daily)
> x11()
> par(cex=1.4)
> plot(Day, Wgt col=c("red","blue","purple","pink")[Tanks])
> detach(daily)

Peter Ehlers
University of Calgary

More information about the R-help mailing list