# x-axis order Classic List Threaded 9 messages Open this post in threaded view
|

## x-axis order

 Hi all, I have a time series which contain data collected weekly from week 26 to week 25 the following year. How do I plot this data, so that the x-axis is displaying the week numbers, ordered as in the data? Thanks in advance, Gustaf --- x<-c(26:52,1:25) y<-rnorm(52)+1:52 plot(x,y)   ## How do I get the x axis to be ordered by the current ordering of x? -- Gustaf Rydevik, M.Sci. tel: +46(0)703 051 451 address:Essingetorget 40,112 66 Stockholm, SE skype:gustaf_rydevik ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: x-axis order

 This should do what you want. x<-c(26:52,1:25) y<-rnorm(52)+1:52 plot(seq_along(x), y, xaxt='n') axis(1, at=seq_along(x), labels=x) On 9/14/07, Gustaf Rydevik <[hidden email]> wrote: > Hi all, > > I have a time series which contain data collected weekly from week 26 > to week 25 the following year. How do I plot this data, so that the > x-axis is displaying the week numbers, ordered as in the data? > > Thanks in advance, > > Gustaf > --- > x<-c(26:52,1:25) > y<-rnorm(52)+1:52 > plot(x,y)   ## How do I get the x axis to be ordered by the current > ordering of x? > > > > -- > Gustaf Rydevik, M.Sci. > tel: +46(0)703 051 451 > address:Essingetorget 40,112 66 Stockholm, SE > skype:gustaf_rydevik > > ______________________________________________ > [hidden email] 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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: x-axis order

 On Fri, 14-Sep-2007 at 02:18PM -0400, jim holtman wrote: |> This should do what you want. |> |> x<-c(26:52,1:25) |> y<-rnorm(52)+1:52 |> |> plot(seq_along(x), y, xaxt='n') |> axis(1, at=seq_along(x), labels=x) And if you have to economize on keystrokes, seq(x) will achieve the same as seq_along(x) HTH -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.      ___    Patrick Connolly    {~._.~}           Great minds discuss ideas      _( Y )_            Middle minds discuss events (:_~*~_:)       Small minds discuss people    (_)-(_)                             ..... Anon           ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: x-axis order

 But not necessarily performance.  Look at the code for 'seq' and 'seq_along'.  Time difference may be small, but keystrokes are done only once. On 9/17/07, Patrick Connolly <[hidden email]> wrote: > On Fri, 14-Sep-2007 at 02:18PM -0400, jim holtman wrote: > > |> This should do what you want. > |> > |> x<-c(26:52,1:25) > |> y<-rnorm(52)+1:52 > |> > |> plot(seq_along(x), y, xaxt='n') > |> axis(1, at=seq_along(x), labels=x) > > And if you have to economize on keystrokes, > seq(x) will achieve the same as seq_along(x) > > HTH > > -- > ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. >   ___    Patrick Connolly >  {~._.~}                         Great minds discuss ideas >  _( Y )_                        Middle minds discuss events > (:_~*~_:)                        Small minds discuss people >  (_)-(_)                                   ..... Anon > > ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

 I am calculating the median absolute deviation using mad function, and it tends to ignore the parameter constant=1, when I am calculating it for x=seq(1:5). Am I missing something here? x<-seq(1:5) mad(x)# gives  1.4826 mad(x, constant=1)# gives  1 #Here is the long form dev.from.median<-abs((x-median(x))) dev.from.median # Gives  2 1 0 1 2 sum(dev.from.median) # Gives  6 sum(dev.from.median)/length(x) # Gives  1.2 # The long form does not match the output from the function # When x<-seq(1:10) they match x<-seq(1:10) dev.from.median<-abs((x-median(x))) sum(dev.from.median)/length(x) # Gives 2.5 mad(x, constant=1) # Gives 2.5 #The long form matches the output from the function Did I miss anything here? Cheers../Murli ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

 On 9/17/07, Nair, Murlidharan T <[hidden email]> wrote: > > I am calculating the median absolute deviation using mad function, and > it tends to ignore the parameter constant=1, when I am calculating it > for x=seq(1:5). Am I missing something here? > > x<-seq(1:5) > mad(x)# gives  1.4826 > mad(x, constant=1)# gives  1 > #Here is the long form > dev.from.median<-abs((x-median(x))) > dev.from.median # Gives  2 1 0 1 2 > sum(dev.from.median) # Gives  6 > sum(dev.from.median)/length(x) # Gives  1.2 > # The long form does not match the output from the function > > # When x<-seq(1:10) they match > x<-seq(1:10) > dev.from.median<-abs((x-median(x))) > sum(dev.from.median)/length(x) # Gives 2.5 > mad(x, constant=1) # Gives 2.5 > #The long form matches the output from the function > > Did I miss anything here? yes; mad := Median (not mean) absolute deviation (from the median, by default). -Deepayan ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

 -----Original Message----- From: Deepayan Sarkar [mailto:[hidden email]] Sent: Monday, September 17, 2007 5:10 PM To: Nair, Murlidharan T Cc: [hidden email] Subject: Re: [R] MAD On 9/17/07, Nair, Murlidharan T <[hidden email]> wrote: > > I am calculating the median absolute deviation using mad function, and > it tends to ignore the parameter constant=1, when I am calculating it > for x=seq(1:5). Am I missing something here? > > x<-seq(1:5) > mad(x)# gives  1.4826 > mad(x, constant=1)# gives  1 > #Here is the long form > dev.from.median<-abs((x-median(x))) > dev.from.median # Gives  2 1 0 1 2 > sum(dev.from.median) # Gives  6 > sum(dev.from.median)/length(x) # Gives  1.2 > # The long form does not match the output from the function > > # When x<-seq(1:10) they match > x<-seq(1:10) > dev.from.median<-abs((x-median(x))) > sum(dev.from.median)/length(x) # Gives 2.5 > mad(x, constant=1) # Gives 2.5 > #The long form matches the output from the function > > Did I miss anything here? yes; mad := Median (not mean) absolute deviation (from the median, by default). -Deepayan Indeed, its median and that what I am calculating in the long form.  So, what is that you found I was doing differently? May be I missed your point. Thx../M ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.