[R] How to Standardise the x/y coordinates to the unit square?

Jim Lemon jim at bitwrit.com.au
Tue Sep 18 12:45:39 CEST 2007


张志杰 wrote:
> Dear Rusers, I want to standardise the values of x/y coordinates to the unit square, i.e. make the x-values all lie within [0,1] and all the y-values lie within [0,1] in the bottom example.  I had thought to use scale() function to do it, but it seems that it's used to standardise a variable and the scaled value was not within [0,1]. OR, i can divide x/y-values by their maximum value to get it.  I'm not sure about it.#Example data data <- matrix(1:10, nc=2)
> data<-as.data.frame(data)
> names(data)<-c('x','y')> data
>   x  y
> 1 1  6
> 2 2  7
> 3 3  8
> 4 4  9
> 5 5 10  I'd appreciate your help. 
> --

Hi John,
You can do this with the "rescale" function in the plotrix package.

newx<-rescale(x,c(0,1))
newy<-rescale(y,c(0,1))

Jim



More information about the R-help mailing list