David W. wrote à It also looses it year labels and you may need to suppress the x-axis
à and substitute your own. You can use plot(yourTimeSeries, type="n") to set up the usual time series axis and then use lines() or points() to add the data. E.g., plot(serieONI, type="n") points(serieONI, type="h", col=c('red', 'white', 'blue')[ findInterval(serieONI, c(-Inf, -0.5, +0.5, Inf))]) lines(serieONI) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of David Winsemius Sent: Friday, July 06, 2012 11:20 AM To: John Kane Cc: r-help@r-project.org; Denisse Archundia Subject: Re: [R] how to do a graph with tree different colors?? On Jul 6, 2012, at 1:24 PM, John Kane wrote: > > Thanks Dennise, > Now I see what you have. It was not obvious from the original > data set that > you posted that is is a time series. > I am afraid my knowledge of time series is about zero but I am > sure others > here can help now that we have a good idea of what the data > really looks > like. > I'm sorry I cannot be of more immediate help. There is a special plot.ts function which refuses my eminently reasonable requests to color points, so .... I coerced it to an atomic vector: plot( as.vector(serieONI), col=c('red', 'white', 'blue')[ findInterval(serieONI, c( -Inf, -0.5, 0.5, Inf) )] , type="b") (White is a rather unusual color for plotting, but we aim to please. It also looses it year labels and you may need to suppress the x-axis and substitute your own.) > > John Kane > Kingston ON Canada > > -----Original Message----- > From: denissearchun...@yahoo.com.mx<mailto:denissearchun...@yahoo.com.mx> > Sent: Fri, 6 Jul 2012 06:01:42 -0700 (PDT) > To: jrkrid...@inbox.com<mailto:jrkrid...@inbox.com> > Subject: Re: [R] how to do a graph with tree different colors?? > > hi!! > > here they are the data in the form you ask. > thanks for your help!! DENISSE > > dput(serieONI) > structure(c(-1.4, -1.3, -1.2, -1.2, -1.1, -0.9, -0.6, -0.5, -0.4, > -0.5, -0.5, -0.7, -0.8, -0.6, -0.4, -0.2, 0, 0.4, 0.6, 1, 1.1, > 1.2, 1.1, 0.9, 0.6, 0.4, 0.3, 0.3, 0.3, 0.1, -0.1, 0, 0.2, 0.2, > 0.2, 0.3, 0.5, 0.6, 0.6, 0.7, 0.7, 0.7, 0.7, 0.7, 0.8, 0.8, 0.8, > 0.7, 0.7, 0.5, 0.1, -0.3, -0.5, -0.5, -0.6, -0.7, -0.8, -0.7, > -0.7, -0.7, -0.7, -0.7, -0.7, -0.8, -0.8, -0.8, -0.8, -0.7, -1, > -1.4, -1.7, -1.6, -1.1, -0.8, -0.6, -0.5, -0.5, -0.5, -0.5, -0.6, > -0.5, -0.5, -0.5, -0.5, -0.3, 0, 0.4, 0.7, 0.9, 1, 1.1, 1.2, > 1.2, 1.3, 1.5, 1.8, 1.8, 1.6, 1.2, 0.9, 0.7, 0.6, 0.5, 0.3, 0.3, > 0.4, 0.5, 0.6, 0.6, 0.6, 0.5, 0.3, 0.2, -0.1, -0.2, -0.3, -0.1, > 0, 0.1, 0, -0.1, -0.2, -0.2, -0.1, -0.1, 0, 0.1, 0.2, 0.2, 0.1, > 0.1, 0.1, 0, 0, 0, 0.1, 0.3, 0.4, 0.2, -0.1, -0.3, -0.3, -0.2, > -0.1, -0.2, -0.3, -0.3, -0.3, -0.2, -0.1, 0, -0.1, -0.2, -0.3, > -0.4, -0.5, -0.4, -0.2, 0.1, 0.2, 0.3, 0.5, 0.8, 1.1, 1.2, 1.3, > 1.4, 1.3, 1.1, 0.6, 0.1, -0.3, -0.6, -0.6, -0.6, -0.7, -0.8, > -0.8, -0.8, -0.8, -0.6, -0.3, 0, 0.2, 0.5, 0.8, 1.2, 1.4, 1.7, > 1.9, 1.9, 1.7, 1.4, 1.1, 0.9, 0.6, 0.4, 0.3, 0.2, 0.1, 0, -0.1, > -0.1, -0.2, -0.3, -0.4, -0.5, -0.4, -0.2, 0.1, 0.1, -0.1, -0.3, > -0.3, -0.3, -0.4, -0.6, -0.8, -0.7, -0.5, -0.2, 0.1, 0.4, 0.5, > 0.5, 0.6, 0.8, 1, 1.1, 1.1, 1, 0.9, 0.8, 0.6, 0.5, 0.5, 0.8, > 0.9, 0.9, 0.8, 0.6, 0.4, 0.4, 0.3, 0.1, -0.2, -0.5, -0.7, -0.7, > -0.7, -0.8, -1, -1.2, -1.3, -1, -0.8, -0.7, -0.7, -0.7, -0.7, > -0.7, -0.8, -0.9, -0.8, -0.6, -0.3, 0, 0.3, 0.6, 0.8, 1.1, 1.4, > 1.6, 1.9, 2.1, 2.1, 1.8, 1.2, 0.6, 0, -0.5, -0.8, -1, -1.2, -1.3, > -1.6, -1.9, -2, -1.9, -1.6, -1.2, -1, -0.8, -0.7, -0.5, -0.4, > -0.4, -0.6, -0.8, -0.7, -0.5, -0.5, -0.6, -0.6, -0.8, -1, -1.1, > -1.2, -1.4, -1.5, -1.6, -1.7, -1.5, -1.1, -0.7, -0.5, -0.3, -0.1, > 0.2, 0.4, 0.6, 0.7, 0.8, 0.8, 0.6, 0.6, 0.3, 0.3, 0.3, 0.4, 0.4, > 0.4, 0.5, 0.7, 0.8, 0.8, 0.7, 0.5, 0.1, -0.2, -0.3, -0.3, -0.3, > -0.4, -0.4, -0.3, -0.1, -0.1, -0.1, 0.1, 0.2, 0.3, 0.2, 0, 0, > 0.2, 0.3, 0.5, 0.5, 0.6, 0.5, 0.4, 0.3, 0.3, 0.4, 0.4, 0.2, 0, > -0.1, 0, 0, -0.1, -0.4, -0.6, -0.5, -0.4, -0.3, -0.3, -0.4, -0.4, > -0.3, -0.2, -0.2, -0.1, -0.1, 0, 0.1, 0.3, 0.5, 0.6, 0.7, 1, > 1.5, 1.9, 2.1, 2.2, 2.2, 1.9, 1.5, 1.2, 0.9, 0.6, 0.2, -0.2, > -0.5, -0.8, -0.9, -0.8, -0.5, -0.3, -0.2, -0.4, -0.5, -0.5, -0.3, > -0.2, -0.3, -0.6, -0.9, -1.1, -1, -0.9, -0.7, -0.7, -0.7, -0.6, > -0.5, -0.5, -0.5, -0.4, -0.4, -0.4, -0.5, -0.4, -0.2, -0.2, -0.1, > 0, 0.3, 0.5, 0.7, 0.9, 1.1, 1.2, 1.2, 1.3, 1.2, 1.1, 1, 1.2, > 1.4, 1.6, 1.6, 1.5, 1.3, 1.1, 0.7, 0.5, 0.1, -0.2, -0.7, -1.2, > -1.3, -1.2, -1.3, -1.6, -1.9, -1.9, -1.7, -1.5, -1.1, -0.8, -0.6, > -0.4, -0.3, -0.3, -0.3, -0.3, -0.2, -0.1, 0.1, 0.2, 0.2, 0.2, > 0.2, 0.2, 0.3, 0.3, 0.3, 0.3, 0.3, 0.4, 0.3, 0.2, 0.2, 0.3, 0.5, > 0.7, 0.8, 0.7, 0.7, 0.8, 1.1, 1.4, 1.6, 1.5, 1.4, 1.2, 1, 0.7, > 0.3, 0, -0.2, -0.3, -0.2, 0, 0.2, 0.3, 0.5, 0.6, 0.6, 0.5, 0.3, > 0.2, 0.2, 0.2, 0.1, 0.1, 0.1, 0.1, 0.2, 0.3, 0.4, 0.4, 0.4, 0.4, > 0.5, 0.7, 1, 1.2, 1, 0.8, 0.6, 0.3, 0.2, 0, -0.1, -0.4, -0.7, > -0.8, -0.9, -0.9, -0.9, -0.8, -0.6, -0.4, -0.3, -0.2, -0.2, -0.3, > -0.3, -0.3, -0.4, -0.5, -0.5, -0.4, -0.1, 0.2, 0.7, 1.2, 1.5, > 1.8, 2.1, 2.3, 2.4, 2.3, 2.2, 1.8, 1.4, 0.9, 0.4, -0.2, -0.7, > -1, -1.2, -1.2, -1.4, -1.5, -1.5, -1.3, -1, -0.9, -0.9, -1, -1, > -1.1, -1.1, -1.3, -1.5, -1.7, -1.7, -1.5, -1.1, -0.9, -0.8, -0.7, > -0.6, -0.5, -0.5, -0.6, -0.8, -0.8, -0.7, -0.6, -0.5, -0.3, -0.2, > -0.1, 0, 0, -0.1, -0.2, -0.2, -0.3, -0.2, 0, 0.1, 0.3, 0.5, 0.7, > 0.8, 0.8, 0.9, 1.2, 1.3, 1.3, 1.1, 0.8, 0.4, 0, -0.2, -0.1, 0.2, > 0.4, 0.4, 0.4, 0.4, 0.3, 0.3, 0.2, 0.1, 0.1, 0.1, 0.3, 0.5, 0.7, > 0.7, 0.7, 0.7, 0.7, 0.6, 0.4, 0.3, 0.3, 0.3, 0.3, 0.2, 0.1, 0, > -0.2, -0.5, -0.8, -0.9, -0.7, -0.5, -0.3, 0, 0.1, 0.2, 0.3, 0.5, > 0.8, 1, 1, 0.7, 0.3, -0.1, -0.2, -0.3, -0.3, -0.3, -0.6, -0.9, > -1.1, -1.2, -1.4, -1.5, -1.5, -1.2, -0.9, -0.7, -0.5, -0.3, -0.2, > -0.1, -0.2, -0.4, -0.7, -0.9, -0.8, -0.6, -0.2, 0.1, 0.4, 0.5, > 0.6, 0.7, 1, 1.4, 1.6, 1.6, 1.4, 1.1, 0.7, 0.2, -0.3, -0.8, -1.2, > -1.4, -1.5, -1.5, -1.5, -1.4, -1.3, -1, -0.7, -0.4, -0.2, -0.2, > -0.3, -0.6, -0.8, -1, -1), .Tsp = c(1950, 2011.91666666667, 12 > ), class = "ts") >> > De: John Kane <jrkrid...@inbox.com<mailto:jrkrid...@inbox.com>> > Para: Denisse Archundia > <denissearchun...@yahoo.com.mx<mailto:denissearchun...@yahoo.com.mx>> > Enviado: Martes, 3 de julio, 2012 13:57:16 > Asunto: Re: [R] how to do a graph with tree different colors?? > Thank you for the data but it would be better to receive it in the > form that > dput() supplies. If your dataset is called Mydata, then > issue the command dput(Mydata) and copy the output into the email. > At the moment I am not sure how go graph your data as it is not > easy to get > the months and years together. > > John Kane > Kingston ON Canada > > -----Original Message----- > From: denissearchun...@yahoo.com.mx<mailto:denissearchun...@yahoo.com.mx> > Sent: Tue, 3 Jul 2012 09:12:40 -0700 (PDT) > To: jrkrid...@inbox.com<mailto:jrkrid...@inbox.com> > Subject: Re: [R] how to do a graph with tree different colors?? > > i works with the oceanic niño index: > > YEAR A B C D E F G H I J K L > 1950 -1,4 -1,3 -1,2 -1,2 -1,1 -0,9 -0,6 -0,5 -0,4 -0,5 -0,5 -0,7 > 1951 -0,8 -0,6 -0,4 -0,2 0 0,4 0,6 1 1,1 1,2 1,1 0,9 > 1952 0,6 0,4 0,3 0,3 0,3 0,1 -0,1 0 0,2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,8 1 1 > 2007 0,7 0,3 -0,1 -0,2 -0,3 -0,3 -0,3 -0,6 -0,9 -1,1 -1,2 -1,4 > 2008 -1,5 -1,5 -1,2 -0,9 -0,7 -0,5 -0,3 -0,2 -0,1 -0,2 -0,4 -0,7 > 2009 -0,9 -0,8 -0,6 -0,2 0,1 0,4 0,5 0,6 0,7 1 1,4 1,6 > 2010 1,6 1,4 1,1 0,7 0,2 -0,3 -0,8 -1,2 -1,4 -1,5 -1,5 -1,5 > 2011 -1,4 -1,3 -1 -0,7 -0,4 -0,2 -0,2 -0,3 -0,6 -0,8 -1 -1 > > THANKS > DENISSE > De: John Kane <jrkrid...@inbox.com<mailto:jrkrid...@inbox.com>> > > Para:denissearchundia<denissearchun...@yahoo.com.mx<mailto:denissearchun...@yahoo.com.mx>>;r-help@r-project.org > Enviado: Martes, 3 de julio, 2012 8:03:23 > Asunto: RE: [R] how to do a graph with tree different colors?? > Any sample data for us to work with? See ?dput for a good > method of > supplying sample data. > John Kane > Kingston ON Canada >> -----Original Message----- >> From: [1]denissearchun...@yahoo.com.mx<mailto:denissearchun...@yahoo.com.mx> >> Sent: Mon, 2 Jul 2012 14:04:53 -0700 (PDT) >> To: [2]r-help@r-project.org<mailto:r-help@r-project.org> >> Subject: [R] how to do a graph with tree different colors?? >> >> hi >> >> i try to do a graph of a time series which shows in red the values > >> -0.05, >> in blue the values >0.05 and in white the values between -0.05 and >> 0.05 >> >> for un exemple :[3]http://www.appinsys.com/globalwarming/enso.htm >> >> thanks !!!!! >> >> denisse >> >> -- >> View this message in context: >> > [4]http://r.789695.n4.nabble.com/how-to-do-a-graph-with-tree-different-color > s-tp4635206.html >> Sent from the R help mailing list archive at Nabble.com. > David Winsemius, MD West Hartford, CT ______________________________________________ R-help@r-project.org<mailto: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]]
______________________________________________ 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.