Skip to content

plot and factors

4 messages · Jason Miller, PIKAL Petr, Tom +1 more

#
Read R-helpers,

I'm relatively new to R and trying to jump in feet first.  I've been  
able to learn a lot from on-line and printed documentation, but  
here's one question to which I can't find an answer.  Well, it's a  
question with a couple parts.  Thanks in advance for any direction  
(partial or complete) that anyone can provide.

I have a data frame with three columns: Year, Semester, value1.  I  
want to treat Year and Semester as factors; there are many years, and  
there are three semesters (Fall, Spring, Summer).

First, I would like to be able to plot the data in this frame as Year  
v. value with one curve for each factor.  I have been unable to do  
this.  Is there any built-in R functionality that makes this easy, or  
do I need to build this by hand (e.g., using the techniques in FAQ  
5.11 or 5.29)?

Second, I would like to be able to plot the values against a doubly  
labeled axis that uses Year and Semester (three Semester ticks per  
Year).  Is there a relatively straightforward way to do this?   
(What's happening, of course, is that I'd like to treat Year+Semester  
as a single factor for the purpose of marking the axis, but I'm not  
sure how to do that, either.)

Again, thanks for whatever pointers people can share.

Jason

================================================================
Jason E. Miller, Ph.D.
Associate Professor of Mathematics
Truman State University
Kirksville, MO
http://pyrite.truman.edu/~millerj/
660.785.7430
#
Hi
On 2 Dec 2005 at 6:40, Jason Miller wrote:
To:             	r-help at stat.math.ethz.ch
From:           	Jason Miller <millerj at truman.edu>
Date sent:      	Fri, 2 Dec 2005 06:40:48 -0600
Subject:        	[R] plot and factors
Not sure what do you want to achieve. If x is factor you will get 
boxplots by

plot(factor, data)

so maybe stayinng with numeric and labeling with

plot(year,data, axes=FALSE)
axis(1, ....)

can be what you want.
Try to look at ?interaction, maybe this can help you.

HTH
Petr
Petr Pikal
petr.pikal at precheza.cz
3 days later
Tom
#
Your first question seems relatively simple:

data.fall<-subset(data,semester=='fall')
data.spring<-subset(data,semester=='spring')
data.summer<-subset(data,semester=='summer')

plot(x=year,y=value1,data=data.fall)
lines(x=year,y=value1,data=data.spring)
lines(x=year,y=value1,data=data.summer)

As for the second question perhaps the paste command is the way to go

datayearsem<-paste(data$year,data$semester,sep='.')
On Fri, 2005-02-12 at 06:40 -0600, Jason Miller wrote:
#
On 12/2/05, Jason Miller <millerj at truman.edu> wrote:
Here are some possibilities using the lattice package:

library(lattice)

d <-
    data.frame(Year = factor(rep(2000:2004, each = 3)),
               Semester = gl(3, 1, 15,
               labels = c("Fall", "Spring", "Summer")),
               val = sort(rnorm(15)))

xyplot(val ~ Year, d, groups = Semester,
       type = 'o', auto.key = TRUE)

xyplot(val ~ Year:Semester, d,
       scales = list(x = list(rot = 90)))

dotplot(Year:Semester ~ val, d)

dotplot(Semester ~ val | Year, d,
        layout = c(1, 5))

HTH,
-Deepayan