[R] plotting evolution of dates

David Winsemius dwinsemius at comcast.net
Sun Jun 3 21:30:39 CEST 2012


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.png

That 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.png

That 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-dates

Whatever 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



More information about the R-help mailing list