[R] Correct scaling of axis in persp3d plot

Ivanov Ruporvrich ivanovruporvrich at yahoo.com
Tue Jun 25 21:40:50 CEST 2013


Hi,
I want to format my axis in my persp3d plot.

With my data, which I attached I created a persp3d plot with the following code, which I summarized from different code snippets I found:

library(rugarch)library(rgl)library(fGarch)fd <-as.data.frame(modelfit,which ='density')color <-rgb(85,141,85,maxColorValue=255)x <-seq(-0.2,0.2,length=100)y <-c(1:2318)f <-function(s,t){dged(s,mean=fd[t,'Mu'],sd=fd[t,'Sigma'],nu=fd[t,'Shape'])}z <-outer(x,y,f)persp3d(x,y,z,theta=50,phi=25,expand=0.75,col=color,ticktype="detailed",xlab="",ylab="time",zlab="",axes=TRUE,axes=FALSE)

axes3d(c('x--','z'))axis3d(edge='y+-',at =seq(500,2000,by=500),labels =rownames(fd)[seq(500,2000,by=500)])

My first question is:
Currently I have four date ticks on my axis, but what I don't like is, that in my data, 
the starting date is in 2004, but the plots look like, as if the starting year
would be 2006. So I would like to have the starting year on the axis, but I don't
know how to implement this (my R programming skills are limited)?

So e.g. I would like to have always the beginning of each year, 2004, 2005, 2006, 2007, 2008, 
2009, 2010, 2011 , 2012 or if this does not fit at leas I would like to
have the beginning of the years 2004,2006,2008,2010,2012 so each second year.

My second question is:
I would like to have a colored surface. So I would like to have e.g. the spikes of the surface in red (values 
which are very larger) and lower values e.g. in green with a nice smooth transition between, e.g.
values in the middle in yellow. So the coloring should depend on the z values. I tried the following, but it does not 
give nice results:

nrz <- nrow(z)
ncz <- ncol(z)
jet.colors <- colorRampPalette( c("#ffcccc", "#cc0000") ) 
# Generate the desired number of colors from this palette
nbcol <- 100
color <- jet.colors(nbcol)

# Compute the z-value at the facet centres
zfacet <- z[-1, -1] + z[-1, -ncz] + z[-nrz, -1] + z[-nrz, -ncz]
# Recode facet z-values into color indices
facetcol <- cut(zfacet, nbcol)

persp3d(x, y, z, theta=50, phi=25, expand=0.75, col=color[facetcol],
ticktype="detailed", xlab="", ylab="time", zlab="",axes=TRUE)

Thanks a lot for your help,
Ivanov


More information about the R-help mailing list