[R] plotting a point graph with data in X-axis

2007-05-08 Thread Milton Cezar Ribeiro
Dear all,

I have two data frame, on with a complete list of my field survey with 
frequency data of a sample species. This data frame looks like:


simulation-data.frame(cbind(my.year=c(rep(2000,8),rep(2001,12),rep(2002,12)),my.month=c(5:12,1:12,1:12)))
simulation$year.month-paste(simulation$my.year,_,ifelse(simulation$my.month=10,simulation$my.month,paste(0,simulation$my.month,sep=)),sep=)
simulation$freq-sample(1:40,32)
attach(simulation)
plot(year.month, freq)

As you can see, I have a collumn with the year and month of my samples, and a 
freq variable with simulated data. I would like to plot this data but when I 
try to use the plot showed above, I get a error message. 

After bypass this problem, I would like add points in my graph with simulated 
data for only a random number of survey month, but I need that the full range 
of surveys be kept on the X-axis. Just to simulate a sample I am using:

simulation.sample-simulation[sample(1:length(year.month),8, replace=F),]
simulation.sample$freq-sample(1:40,8)

Any ideas?

Kind regards

Miltinho

__


[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] plotting a point graph with data in X-axis

2007-05-08 Thread jim holtman
You have to have a valid 'date' object on the x-axis.  Try this:

simulation-data.frame(cbind(my.year=c(rep(2000,8),rep(2001,12),rep(2002,12)),my.month=c(5:12,1:12,1:12)))
simulation$year.month-paste(simulation$my.year,_,ifelse(simulation$my.month=10,simulation$my.month,paste(0,simulation$my.month,sep=)),sep=)
simulation$freq-sample(1:40,32)
# create POSIXct time
simulation$time - ISOdate(simulation$my.year, simulation$my.month,1)
attach(simulation)
plot(time, freq)


On 5/8/07, Milton Cezar Ribeiro [EMAIL PROTECTED] wrote:
 Dear all,

 I have two data frame, on with a complete list of my field survey with 
 frequency data of a sample species. This data frame looks like:


 simulation-data.frame(cbind(my.year=c(rep(2000,8),rep(2001,12),rep(2002,12)),my.month=c(5:12,1:12,1:12)))
 simulation$year.month-paste(simulation$my.year,_,ifelse(simulation$my.month=10,simulation$my.month,paste(0,simulation$my.month,sep=)),sep=)
 simulation$freq-sample(1:40,32)
 attach(simulation)
 plot(year.month, freq)

 As you can see, I have a collumn with the year and month of my samples, and a 
 freq variable with simulated data. I would like to plot this data but when I 
 try to use the plot showed above, I get a error message.

 After bypass this problem, I would like add points in my graph with simulated 
 data for only a random number of survey month, but I need that the full range 
 of surveys be kept on the X-axis. Just to simulate a sample I am using:

 simulation.sample-simulation[sample(1:length(year.month),8, replace=F),]
 simulation.sample$freq-sample(1:40,8)

 Any ideas?

 Kind regards

 Miltinho

 __


[[alternative HTML version deleted]]

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] plotting a point graph with data in X-axis

2007-05-08 Thread Gabor Grothendieck
- use proper spacing to make it easier to read
- start off with set.seed to make it reproducible
- omit cbind and combine all the rep's into one rep in first line
- make the date column a known date class (here Date),


set.seed(1)
sim - data.frame(
   my.year = rep(2000:2002, c(8, 12, 12)),
   my.month = c(5:12, 1:12, 1:12),
   freq = sample(1:40, 32)
)
sim$date - as.Date(paste(sim$my.year, sim$my.month, 1, sep = -))
plot(freq ~ date, sim)

On 5/8/07, Milton Cezar Ribeiro [EMAIL PROTECTED] wrote:
 Dear all,

 I have two data frame, on with a complete list of my field survey with 
 frequency data of a sample species. This data frame looks like:


 simulation-data.frame(cbind(my.year=c(rep(2000,8),rep(2001,12),rep(2002,12)),my.month=c(5:12,1:12,1:12)))
 simulation$year.month-paste(simulation$my.year,_,ifelse(simulation$my.month=10,simulation$my.month,paste(0,simulation$my.month,sep=)),sep=)
 simulation$freq-sample(1:40,32)
 attach(simulation)
 plot(year.month, freq)

 As you can see, I have a collumn with the year and month of my samples, and a 
 freq variable with simulated data. I would like to plot this data but when I 
 try to use the plot showed above, I get a error message.

 After bypass this problem, I would like add points in my graph with simulated 
 data for only a random number of survey month, but I need that the full range 
 of surveys be kept on the X-axis. Just to simulate a sample I am using:

 simulation.sample-simulation[sample(1:length(year.month),8, replace=F),]
 simulation.sample$freq-sample(1:40,8)

 Any ideas?

 Kind regards

 Miltinho

 __


[[alternative HTML version deleted]]

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] plotting a point graph with data in X-axis

2007-05-08 Thread Adaikalavan Ramasamy
R understands only numerical and Date class values for axis. So either


a) plot them using the sequence 1, ..., 32 and then explicitly label 
them. Here is an example:

  n - length(year.month)
  plot( 1:n, freq, xaxt=n)
  mtext( text=year.month, side=1, at=1:n, las=2 )


b) or create the dates in Date format. This option is preferable if the 
dates were varying unequally.

  x - seq( as.Date(2000-05-01), as.Date(2002-12-01), by=1 month )
  plot(x, simulation$freq)


BTW, you could also have created year.month via
   paste( rep( 2000:2002, c(8,12,12) ),
  formatC( c(5:12,1:12,1:12), width=2, flag=0 ) , sep=_ )


Regards, Adai




Milton Cezar Ribeiro wrote:
 Dear all,
 
 I have two data frame, on with a complete list of my field survey with 
 frequency data of a sample species. This data frame looks like:
 
 
 simulation-data.frame(cbind(my.year=c(rep(2000,8),rep(2001,12),rep(2002,12)),my.month=c(5:12,1:12,1:12)))
 simulation$year.month-paste(simulation$my.year,_,ifelse(simulation$my.month=10,simulation$my.month,paste(0,simulation$my.month,sep=)),sep=)
 simulation$freq-sample(1:40,32)
 attach(simulation)
 plot(year.month, freq)
 
 As you can see, I have a collumn with the year and month of my samples, and a 
 freq variable with simulated data. I would like to plot this data but when I 
 try to use the plot showed above, I get a error message. 
 
 After bypass this problem, I would like add points in my graph with simulated 
 data for only a random number of survey month, but I need that the full range 
 of surveys be kept on the X-axis. Just to simulate a sample I am using:
 
 simulation.sample-simulation[sample(1:length(year.month),8, replace=F),]
 simulation.sample$freq-sample(1:40,8)
 
 Any ideas?
 
 Kind regards
 
 Miltinho
 
 __
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] plotting a point graph with data in X-axis

2007-05-08 Thread Gabor Grothendieck
One other idea.  If your dates are continguous, as they are here,
you might want to use a ts series for this.  Using the same sim
as in my prior post:

 set.seed(1)
 x - with(sim, ts(freq, start = c(my.year[1], my.month[1]), freq = 12))
 x
 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2000  11  15  22  34   8  32  33  38
2001  21   2   7   6  20  40  35  13  18  23   9  17
2002  19   5  12   3  28  29   1  16  27   4  25  39
 plot(x)


On 5/8/07, Gabor Grothendieck [EMAIL PROTECTED] wrote:
 - use proper spacing to make it easier to read
 - start off with set.seed to make it reproducible
 - omit cbind and combine all the rep's into one rep in first line
 - make the date column a known date class (here Date),


 set.seed(1)
 sim - data.frame(
   my.year = rep(2000:2002, c(8, 12, 12)),
   my.month = c(5:12, 1:12, 1:12),
   freq = sample(1:40, 32)
 )
 sim$date - as.Date(paste(sim$my.year, sim$my.month, 1, sep = -))
 plot(freq ~ date, sim)

 On 5/8/07, Milton Cezar Ribeiro [EMAIL PROTECTED] wrote:
  Dear all,
 
  I have two data frame, on with a complete list of my field survey with 
  frequency data of a sample species. This data frame looks like:
 
 
  simulation-data.frame(cbind(my.year=c(rep(2000,8),rep(2001,12),rep(2002,12)),my.month=c(5:12,1:12,1:12)))
  simulation$year.month-paste(simulation$my.year,_,ifelse(simulation$my.month=10,simulation$my.month,paste(0,simulation$my.month,sep=)),sep=)
  simulation$freq-sample(1:40,32)
  attach(simulation)
  plot(year.month, freq)
 
  As you can see, I have a collumn with the year and month of my samples, and 
  a freq variable with simulated data. I would like to plot this data but 
  when I try to use the plot showed above, I get a error message.
 
  After bypass this problem, I would like add points in my graph with 
  simulated data for only a random number of survey month, but I need that 
  the full range of surveys be kept on the X-axis. Just to simulate a sample 
  I am using:
 
  simulation.sample-simulation[sample(1:length(year.month),8, replace=F),]
  simulation.sample$freq-sample(1:40,8)
 
  Any ideas?
 
  Kind regards
 
  Miltinho
 
  __
 
 
 [[alternative HTML version deleted]]
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.