Creating count _down_ axes in R
I'm drawing a pretty weird wireframe. The y-axis should run from -50 to 0, but should be labeled with positive numbers. So the origin should be (0.50,0), with y decreasing along the y-axis.
My first thought was to take the original command:
wireframe(z~x*(10*log10(y)), grid, colorkey=TRUE, drape=TRUE, scales=list(arrows=FALSE))
and just negate y in the formula:
wireframe(z~x*(-10*log10(y)), grid, colorkey=TRUE, drape=TRUE, scales=list(arrows=FALSE))
But the wireframe is too smart and flips the axes (and plotted data!) Around so that the x-axis now goes up from 0 to 50.
How can I manually specify the tic labels on the y-axis?
EDIT: Here's the R code to create this issue:
tf_model <- function(n,l){
tf = n*l
return(tf)
}
n <- c(0:100)/100 * 0.1
l <- -c(0:100)/2
l <- 10^(l/10)
grid <- expand.grid(x=n, y=l)
grid$z <- tf_model(grid$x, grid$y)
library('lattice')
trellis.par.set("axis.line",list(col=NA,lty=1,lwd=1))
wireframe(z~x*(10*log10(y)), grid, colorkey=TRUE, drape=TRUE, scales=list(arrows=FALSE))
wireframe(z~x*(-10*log10(y)), grid, colorkey=TRUE, drape=TRUE, scales=list(arrows=FALSE))
source to share
It looks like you really want to change the labels attached to the y-axis labels. You can do this by setting the component labels
of the y
list component passed to the argument scales
:
wireframe(z~x*(10*log10(y)), grid, colorkey=TRUE, drape=TRUE,
scales = list(arrows = FALSE, y = list(labels = seq(0, 50, by = 10))))
## Or perhaps this -- I can't quite make out which you want.
wireframe(z~x*(10*log10(y)), grid, colorkey=TRUE, drape=TRUE,
scales = list(arrows = FALSE, y = list(labels = seq(50, 0, by = -10))))
In general, you can achieve pretty complete control over, say, the y-axis of a lattice plot by setting a combination of the ylim
and components at
and the labels
list passed toscales
-
ylim : Determines the degree and orientation of the y-axis. For example, set
ylim=c(0, 1000)
to widen the y-axis, orylim=c(0,-50)
to change orientation. -
at : controls the position of the labels on the axis. For example,
scales = list(y=list(at=c(0,-50)))
will only place labels at the end point of the default axes. -
labels : set the labels to be placed on labels (which are either the default or an argument
at
). For example,scales = list(y=list(at=c(0,-50), labels=c("Zero", "Below Zero")))
source to share