i need help about reverse axes

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

i need help about reverse axes

Ali Alsamawi

Hello

     im trying to plot 3d  with scatterplot packages , everything is work on my program below  but my problenm i want to set my pressure level or axis(z-axis) to reverse like from bottom to top, i used function "rev" but not work just for 2d plots the figure in attachment and the program shows below, can anyone help me to do this


Thanks
Ali




##load rgl package
library()
library(scatterplot3d)


## open binary file to read
dat <- file("/srv/scratch/z3303149/back_Traj/parcel1_1",open="rb")
skip1st1 = seek(dat,where=4)
alldata = readBin(dat,numeric(),n=5040,size=4)
dim(alldata) <- c(10,504)

totlen= 504
## replace zeros in lon,lat,pres,wv_cont with missing
for (i in 1:totlen) {
  if (alldata[2,i]==0) alldata[2,i] = NA
  if (alldata[3,i]==0) alldata[3,i] = NA
  if (alldata[4,i]==0) alldata[4,i] = NA
  if (alldata[10,i]==0) alldata[10,i] = NA
}

## total number of non-missing values
len = totlen - sum(is.na(alldata[2,]))



## set the dataset to use for colouring
coldat = alldata[10,1:len]

## creat colour from wv_cont - in hsv
hcol = cumsum(coldat)

hcol = hcol/max(hcol,na.rm=TRUE)
print(hcol)
col <- hsv(h=hcol,s=1,v=1)






X <- scatterplot3d(alldata[2,1:len],alldata[3,1:len],alldata[4,1:len],
xlab="lon",ylab="lat",zlab="pres",main="The Trajectory of the parcel1_1 (%)",zlim=rev(range(alldata[4,1:len])))

#to show the first point of the trajectory
X$points3d(alldata[2,1],alldata[3,1],alldata[4,1],col =col, type = "p", pch = 15)

X$points3d(alldata[2,1:len],alldata[3,1:len],alldata[4,1:len],col =col, type = "p", pch = 1)


## create labelbar - need to create an image in order to do so
lbcol = hsv(h=seq(0,1,0.01),s=1,v=1)
tmp1=c(1:len)
tmp3=matrix(coldat,len,1)




par(oma=c( 0,0,0,0),font.axis=1,mar=(c(14.1,4.1,4.1,1.1)),cex=0.8)
image.plot(tmp1,1,tmp3,add=TRUE,legend.only=TRUE,col=lbcol,nlevel=10
,legend.shrink=0.8,legend.width=1)





#png()




______________________________________________
[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.

Rplot001.png (9K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: i need help about reverse axes

Uwe Ligges-3
scatterplot3d() currently does not supoort it, but you can hack an ugly
workaround:

If you want to do it only once ot twice:

mirror your z data at mean(range of z axis) and add z.ticklabs manually
(the reverse numbers)

Example:

x <- 1:10
y <- 1:10
z <- 1:10
s3d <- scatterplot3d(x, y, z)
env <- environment(s3d[[1]])
zmin <- get("z.min", env=env) * get("z.scal", env=env)
zmax <- get("z.max", env=env) * get("z.scal", env=env)
zmean <- mean(c(zmin, zmax))
znew <- 2*zmean - z
scatterplot3d(x, y, znew, z.ticklabs=rev(get("z.prty", env=env)))

Best,
Uwe Ligges











Am 04.06.2010 02:48, schrieb Ali Alsamawi:

>
> Hello
>
>       im trying to plot 3d  with scatterplot packages , everything is work on my program below  but my problenm i want to set my pressure level or axis(z-axis) to reverse like from bottom to top, i used function "rev" but not work just for 2d plots the figure in attachment and the program shows below, can anyone help me to do this
>
>
> Thanks
> Ali
>
>
>
>
> ##load rgl package
> library()
> library(scatterplot3d)
>
>
> ## open binary file to read
> dat<- file("/srv/scratch/z3303149/back_Traj/parcel1_1",open="rb")
> skip1st1 = seek(dat,where=4)
> alldata = readBin(dat,numeric(),n=5040,size=4)
> dim(alldata)<- c(10,504)
>
> totlen= 504
> ## replace zeros in lon,lat,pres,wv_cont with missing
> for (i in 1:totlen) {
>    if (alldata[2,i]==0) alldata[2,i] = NA
>    if (alldata[3,i]==0) alldata[3,i] = NA
>    if (alldata[4,i]==0) alldata[4,i] = NA
>    if (alldata[10,i]==0) alldata[10,i] = NA
> }
>
> ## total number of non-missing values
> len = totlen - sum(is.na(alldata[2,]))
>
>
>
> ## set the dataset to use for colouring
> coldat = alldata[10,1:len]
>
> ## creat colour from wv_cont - in hsv
> hcol = cumsum(coldat)
>
> hcol = hcol/max(hcol,na.rm=TRUE)
> print(hcol)
> col<- hsv(h=hcol,s=1,v=1)
>
>
>
>
>
>
> X<- scatterplot3d(alldata[2,1:len],alldata[3,1:len],alldata[4,1:len],
> xlab="lon",ylab="lat",zlab="pres",main="The Trajectory of the parcel1_1 (%)",zlim=rev(range(alldata[4,1:len])))
>
> #to show the first point of the trajectory
> X$points3d(alldata[2,1],alldata[3,1],alldata[4,1],col =col, type = "p", pch = 15)
>
> X$points3d(alldata[2,1:len],alldata[3,1:len],alldata[4,1:len],col =col, type = "p", pch = 1)
>
>
> ## create labelbar - need to create an image in order to do so
> lbcol = hsv(h=seq(0,1,0.01),s=1,v=1)
> tmp1=c(1:len)
> tmp3=matrix(coldat,len,1)
>
>
>
>
> par(oma=c( 0,0,0,0),font.axis=1,mar=(c(14.1,4.1,4.1,1.1)),cex=0.8)
> image.plot(tmp1,1,tmp3,add=TRUE,legend.only=TRUE,col=lbcol,nlevel=10
> ,legend.shrink=0.8,legend.width=1)
>
>
>
>
>
> #png()
>
>
>
>
>
> Rplot001.png
>
>
>
>
> ______________________________________________
> [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.

______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: i need help about reverse axes

Nissim Kaufmann
This post has NOT been accepted by the mailing list yet.
This post was updated on .
In reply to this post by Ali Alsamawi
Here is an example workaround that will work with the current rgl functions (scatterplot() and environment()  seem to be extinct):

# reverse the direction of the y axis in rgl plot
x <- 2:10
y <- 2:10
z <- 2:10
s3d <- plot3d(x, y, z)
bbox <- par3d('bbox')
ynew <- -y+bbox[3]+bbox[4]
plot3d(x, ynew, z, axes=FALSE)
box3d()
axis3d('x',at=seq(min(range(x)),max(range(x)),len=5))
axis3d('z',at=seq(min(range(z)),max(range(z)),len=5))
axis3d('y',at=seq(min(range(z)),max(range(z)),len=5),labels=rev(seq(min(range(z)),max(range(z)),len=5)))

Nissim Kaufmann
ILS at UAlbany
Nissim Kaufmann
Research Scientist
ILS at UAlbany
www.ils.ualbany.edu