Hi, I have a density plot in which the x axis ranged from 0 to 2000. How can I scale the data so that the x-axis is scaled in -1 to 1 form? - Gundala Viswanath Jakarta - Indonesia
2 * (x - min(x))/(max(x) - min(x)) - 1 On Sun, Sep 14, 2008 at 10:13 PM, Gundala Viswanath <gundalav at gmail.com> wrote:> Hi, > > I have a density plot in which the x axis > ranged from 0 to 2000. > > How can I scale the data so that the x-axis > is scaled in -1 to 1 form? > > - Gundala Viswanath > Jakarta - Indonesia >-- Yihui Xie <xieyihui at gmail.com> Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China
Gundala Viswanath wrote:> Hi, > > I have a density plot in which the x axis > ranged from 0 to 2000. > > How can I scale the data so that the x-axis > is scaled in -1 to 1 form? > >Hi Gundala, If your data is named "mydata": mynewdata<-rescale(mydata,c(-1,1)) This will linearly transform "mydata" into the range -1 to 1. You may also want to manually create the axis on the plot: plot(mynewdata,axes=FALSE,...) box() axis(1) axis(2,at=c(-1,0,1),labels=c("0","1000","2000")) If you want the original values. Jim axis
Dear Jim, I cannot find the function "rescale". Does it belong to any particular package? - Gundala Viswanath Jakarta - Indonesia On Mon, Sep 15, 2008 at 5:24 PM, Jim Lemon <jim at bitwrit.com.au> wrote:> Gundala Viswanath wrote: >> >> Hi, >> >> I have a density plot in which the x axis >> ranged from 0 to 2000. >> >> How can I scale the data so that the x-axis >> is scaled in -1 to 1 form? >> >> > > Hi Gundala, > If your data is named "mydata": > > mynewdata<-rescale(mydata,c(-1,1)) > > This will linearly transform "mydata" into the range -1 to 1. You may also > want to manually create the axis on the plot: > > plot(mynewdata,axes=FALSE,...) > box() > axis(1) > axis(2,at=c(-1,0,1),labels=c("0","1000","2000")) > > If you want the original values. > > Jim > > axis >