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. Any help would be greatly appreciated. Regards Surrey Jackson
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.
Hi: Not sure, but perhaps you had something like this in mind: y <- runif(100) w <- matrix(y, nrow = 10) # fills in column-wise v <- apply(w, 2, cumsum) plot(1:100, y, type = 'l', col = 'blue') lines(1:100, as.vector(v), type = 'l', col = 'red') Reshaping into a matrix and using apply() to produce column-wise cumulative sums seems like what you were after. The difference between the overall cumulative sum (of y) and the column-wise cumulative sums is shown in the graph. HTH, Dennis On Tue, Feb 1, 2011 at 1:51 AM, Surrey Jackson <surreyjackson@gmail.com>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. > > Any help would be greatly appreciated. > > Regards > > Surrey Jackson > > ______________________________________________ > R-help@r-project.org 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. >[[alternative HTML version deleted]]
Maybe Matching Threads
- Selecting the first occurrence of a value after an occurrence of a different value
- Display of data points in the Scatterplot
- Difference between prcomp and cmdscale
- cross-validation / sensitivity anaylsis for logistic regression model
- Extracting the name of an object into a character string and vice versa