[R] Subset and plot

Jeff Laake Jeff.Laake at noaa.gov
Wed Feb 3 05:21:51 CET 2010


Don't need to convert the factors to numeric as that will happen 
automatically.  See below.  However as Rolf pointed out they will be 
numbered from 1-4 even though only 3 are left in the subset as all 4 
levels are maintained.  So the snippet below will work as long as you 
specify 4 possible pch values.  Below I show how you can change to 3 levels.

daily <- data.frame(Trial = rep(c(1,2),each=12),
                             
Tanks=rep(rep(c("a3","a4","c4","h4"),each=3),2),
                             Day=rep(c(1:12),2),
                             Wgt=c(1:24))
daily.sub<-subset(daily, subset=Trial==2 & Tanks=="a4"|Trial==2 &
Tanks=="c4"|Trial==2 & Tanks=="h4")
with(daily.sub,plot(Wgt ~ Day,  pch=c(2,19,21,23)[Tanks]))

# with 3 levels
daily.sub$Tanks=factor(daily.sub$Tanks)
with(daily.sub,plot(Wgt ~ Day,  pch=c(19,21,23)[Tanks]))


On 2/2/2010 5:54 PM, Dennis Murphy wrote:
> plot(Wgt ~ Day, data = daily.sub,  pch=c(2,19,21)[tanks])
>



More information about the R-help mailing list