[R] plotting evolution of dates
Jim Lemon
jim at bitwrit.com.au
Mon Jun 4 11:54:05 CEST 2012
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
More information about the R-help
mailing list