Dear R users, I have the following problem I have a panel data across countries and individuals. For each country I have a sequence of dates For France for example 22/02/09 22/03/09 19/04/09 17/05/09 12/07/09 09/08/09 06/09/09 04/10/09 01/11/09 29/11/09 27/12/09 31/01/10 For Italy 14/06/09 12/07/09 09/08/09 06/09/09 04/10/09 01/11/09 29/11/09 27/12/09 31/01/10 28/02/10 28/03/10 The structure of the MS excel file is the following France Italy ...... 22/02/09 14/06/09 22/03/09 12/7/2009 19/04/09 9/8/2009 17/05/09 6/9/2009 12/7/2009 4/10/2009 09/08/09 01/11/09 6/9/2009 29/11/09 4/10/2009 27/12/09 01/11/09 31/01/10 29/11/09 28/02/10 27/12/09 28/03/10 31/01/10 I want to "plot" (in one graph) these sequences of dates in the sense that I want to have a "visual" contact of the behaviour of each of these 2 sequences because as you can see I do not have the same start date and end date for each country and each next date is not always every other 28 days. So the difference between 2 successive dates is not always 28 days but 35 is some cases or otherwise. Put differently, I have "jumps". I would like to visualize these characteristics of the series of dates by making a plot similar to http://i46.tinypic.com/2h7gpvn.png But this is not enough. I want to measure the distance between 2 successive knots (the difference between 2 successive dates) and note on the plot the number of weeks that separate apart the successive knots-dates Something like http://www.survey-design.com.au/stripplot3.png where as you can see between the knots there are some red lines. In my case these red lines would inform the reader about the number of weeks between successive knots-dates I need a specific code for this because a simple hint will not help me as I am a new R user. Thank you all
On Jun 3, 2012, at 9:27 AM, stef salvez wrote:> Dear R users, > > I have the following problem > > I have a panel data across countries and individuals. For each country > I have a sequence of dates > For France for example > 22/02/09 > 22/03/09 > 19/04/09 > 17/05/09 > 12/07/09 > 09/08/09 > 06/09/09 > 04/10/09 > 01/11/09 > 29/11/09 > 27/12/09 > 31/01/10 > > For Italy > 14/06/09 > 12/07/09 > 09/08/09 > 06/09/09 > 04/10/09 > 01/11/09 > 29/11/09 > 27/12/09 > 31/01/10 > 28/02/10 > 28/03/10 > > > The structure of the MS excel file is the following > France Italy ...... > 22/02/09 14/06/09 > 22/03/09 12/7/2009 > 19/04/09 9/8/2009 > 17/05/09 6/9/2009 > 12/7/2009 4/10/2009 > 09/08/09 01/11/09 > 6/9/2009 29/11/09 > 4/10/2009 27/12/09 > 01/11/09 31/01/10 > 29/11/09 28/02/10 > 27/12/09 28/03/10 > 31/01/10 > > > > I want to "plot" (in one graph) these sequences of dates in the > sense that I want to have a "visual" contact of the behaviour > of each of these 2 sequences because as you can see I do not have > the same > start date and end date for each country and each next date is not > always every other 28 days. So the difference between 2 successive > dates is not always 28 days but 35 is some cases or otherwise. Put > differently, I have "jumps". > I would like to visualize these > characteristics of the series of dates by > making a plot similar to > > http://i46.tinypic.com/2h7gpvn.pngThat looks like an ordinary R plot and the fact that you might want "jumps" suggests you might want to use the "s" line type. Or you might be talking about "gaps". Hard to tell without specific examples. Look at ?plot.default and ?par for information on the 'lty' parameter. You should be converting your dates to 'Date' class vectors so that they have the proper numeric distance. You would also get Date formating with the axis calls. > Italy <- scan(what="character") 1: 14/06/09 2: 12/07/09 3: 09/08/09 4: 06/09/09 5: 04/10/09 6: 01/11/09 7: 29/11/09 8: 27/12/09 9: 31/01/10 10: 28/02/10 11: 28/03/10 12: Read 11 items > Italy.Dt <- as.Date(Italy, format="%d/%m/%y") > Italy.Dt [1] "2009-06-14" "2009-07-12" "2009-08-09" "2009-09-06" "2009-10-04" "2009-11-01" "2009-11-29" [8] "2009-12-27" "2010-01-31" "2010-02-28" "2010-03-28" >> > But this is not enough.Well, in many ways you are already asking too much, since you have provided no sample dataset in a form that can be readily pasted into a console session. There are Wiki entries on importing Excel data that you should be able to find without too much difficulty. You are expected to do quite a bit of self-study and to post your coding efforts. A lot of people have spent a lot of time over the years in putting material in the R-wiki, their own blogs and of course the Contributed materials at CRAN.> I want to measure the distance between 2 successive knots (the > difference between 2 successive dates) and note on the plot the > number of weeks that separate apart the successive knots-dates > Something like > > http://www.survey-design.com.au/stripplot3.pngThat reminds me a bit of a type of plot called something like ""beehive plot". There have been implementations in R and searching he archives would be the way to go. It's still not exactly clear how the stacking of interim observations should be specified. Again, with no data object (and please, please, do not offer console-print()ed output) , not much more coding can be suggested.> > where as you can see between the knots there are some red lines. In my > case these red lines would inform the reader about the number of weeks > between successive knots-datesWhatever that actually means ...> > I need a specific code for this because a simple hint will not help me > as I am a new R user.That's _not_ the implicit agreement that you committed to when you posted to Rhelp. Please read the Posting Guide.. again? This is not a tutorial website. -- David Winsemius, MD West Hartford, CT
On 06/03/2012 11:27 PM, stef salvez wrote:> Dear R users, > > I have the following problem > > I have a panel data across countries and individuals. For each country > I have a sequence of dates > For France for example > 22/02/09 > 22/03/09 > 19/04/09 > 17/05/09 > 12/07/09 > 09/08/09 > 06/09/09 > 04/10/09 > 01/11/09 > 29/11/09 > 27/12/09 > 31/01/10 > > For Italy > 14/06/09 > 12/07/09 > 09/08/09 > 06/09/09 > 04/10/09 > 01/11/09 > 29/11/09 > 27/12/09 > 31/01/10 > 28/02/10 > 28/03/10 > > > The structure of the MS excel file is the following > France Italy ...... > 22/02/09 14/06/09 > 22/03/09 12/7/2009 > 19/04/09 9/8/2009 > 17/05/09 6/9/2009 > 12/7/2009 4/10/2009 > 09/08/09 01/11/09 > 6/9/2009 29/11/09 > 4/10/2009 27/12/09 > 01/11/09 31/01/10 > 29/11/09 28/02/10 > 27/12/09 28/03/10 > 31/01/10 > > > > I want to "plot" (in one graph) these sequences of dates in the > sense that I want to have a "visual" contact of the behaviour > of each of these 2 sequences because as you can see I do not have the same > start date and end date for each country and each next date is not > always every other 28 days. So the difference between 2 successive > dates is not always 28 days but 35 is some cases or otherwise. Put > differently, I have "jumps". > I would like to visualize these > characteristics of the series of dates by > making a plot similar to > > http://i46.tinypic.com/2h7gpvn.png > > But this is not enough. > I want to measure the distance between 2 successive knots (the > difference between 2 successive dates) and note on the plot the > number of weeks that separate apart the successive knots-dates > Something like > > http://www.survey-design.com.au/stripplot3.png > > where as you can see between the knots there are some red lines. In my > case these red lines would inform the reader about the number of weeks > between successive knots-dates > >Hi stef, This is rather messy and needs some axis tuning, but it might do what you want: France<-c("22/02/09","22/03/09","19/04/09","17/05/09","12/07/09", "09/08/09","06/09/09","04/10/09","01/11/09","29/11/09","27/12/09", "31/01/10") Italy<-c("14/06/09","12/07/09","09/08/09","06/09/09","04/10/09", "01/11/09","29/11/09","27/12/09","31/01/10","28/02/10","28/03/10") Francedates<-as.Date(France,"%d/%m/%y") Italydates<-as.Date(Italy,"%d/%m/%y") require(plotrix) plot(Francedates,rep(1,length(France)), xlim=as.Date(c("01/01/09","01/04/10"),"%d/%m/%y"),ylim=c(0,3), yaxt="n",type="b",xlab="",ylab="") axis(2,at=1:2,labels=c("France","Italy"),las=1) points(Italydates,rep(2,length(Italy)),type="b",pch=2) segments(as.numeric(Francedates)[1:(length(Francedates)-1)]+ diff(as.numeric(Francedates))/2,rep(1,length(Francedates)-1), seq(min(as.numeric(Francedates)),max(as.numeric(Francedates)), length.out=length(Francedates)-1),rep(0.25,length(Francedates)-1)) boxed.labels(seq(min(as.numeric(Francedates)), max(as.numeric(Francedates)),length.out=length(Francedates)-1), rep(0.25,length(Francedates)-1), diff(as.numeric(Francedates))/7) segments(as.numeric(Italydates)[1:(length(Italydates)-1)]+ diff(as.numeric(Italydates))/2,rep(2,length(Italydates)-1), seq(min(as.numeric(Italydates)),max(as.numeric(Italydates)), length.out=length(Italydates)-1),rep(2.75,length(Italydates)-1)) boxed.labels(seq(min(as.numeric(Italydates)), max(as.numeric(Italydates)),length.out=length(Italydates)-1), rep(2.75,length(Italydates)-1), diff(as.numeric(Italydates))/7) You have also alerted me to the fact that the spread.labels function doesn't do quite what I would like it to do, so it will be revised. Jim
Apparently Analagous Threads
- tensor product of equi-spaced B-splines in the unit square
- Automatic Knot selection in Piecewise linear splines
- Automatic Knot selection in Piecewise linear splines
- confidence interval for logistic joinpoint regression from package ljr
- mgcv gam predict problem