[R] Scatterplot Question

Petr Savicky savicky at praha1.ff.cuni.cz
Tue Feb 1 12:04:21 CET 2011


On Tue, Feb 01, 2011 at 10:51:12PM +1300, Surrey Jackson wrote:
> Hello,
> 
> I have some data where a number of events (the total amount varies)
> occur at cumulating times,  I would like to create a scatterplot
> (easily achieved using plot etc) of these events (the events can
> either be times using poxist or I can convert them into just seconds
> which is probably easier to work with), however I would like the
> events/times to re-begin plotting every 10th occurrence and start
> being plotted again from 0 on the Y axis.  The result would be a
> scatte rplot that looks like it has lots of ups and downs in it, as
> opposed to one that just keeps on going on up and up and up.  This
> would allow me to compare the time of the events across multiple
> sessions of data.
> 
> Now I can create a scatterplot of the first 10 occurrences and then
> minus the 10th time from the next 10 occurrences so the times will be
> plotted correctly on the Y axis.  However I can't make them plot in
> the 11:20 slot.
> 
> I have read all the help files for plot, dotchart etc and can't figure it out.
> 
> I am after an elegant solution as I have many hundreds of data files
> that I will need to do this for and I have been creating all my other
> graphs and doing other anaylsis using a loop and all the files have
> varying numbers of events to be plotted.

Hello.

I think that a transformation of the data before the plot can be used.
Below, i suggest a solution, where the y-values at indices 1, 10, 20, ...
are subtracted. So, also the first interval is plotted relatively to its
starting value. I am not sure, whether this is suitable for your application.

  # create an irregularly increasing sequence
  n <- 33
  y <- cumsum(runif(n))
  plot(y)
  # restarting indices
  ind <- 1:n - (1:n) %% 10
  ind[ind == 0] <- 1
  plot(y - y[ind])

Is this close to what you want?

If not, then i suggest to send the loop solution as a part of the description.

Petr Savicky.



More information about the R-help mailing list