I would like to produce a contourplot using the lattice package in which the y axis starts at the top and goes to the bottom (i.e. smallest value at top, largest value at bottom). If I change the following:
contourplot(Male ~ Age * Year, data=this.ds)
to
contourplot(Male ~ Age * rev(Year), data=this.ds)
Then the graph is plotted correctly but the y axis tickmark labels are not reversed. (i.e. still start at the bottom and go to the top.) - (See end of message for fully reproducible example.)
I think the answer involves using the 'scales' list object (so I think this has a one line solution) but am not sure what it is.
Help much appreciated, Jon
Fully reproducible example:
library(lattice)
attach(environmental)
ozo.m <- loess((ozone^(1/3)) ~ wind * temperature * radiation,
parametric = c("radiation", "wind"), span = 1, degree = 2)
w.marginal <- seq(min(wind), max(wind), length.out = 50)
t.marginal <- seq(min(temperature), max(temperature), length.out = 50)
r.marginal <- seq(min(radiation), max(radiation), length.out = 4)
wtr.marginal <- list(wind = w.marginal, temperature = t.marginal,
radiation = r.marginal)
grid <- expand.grid(wtr.marginal)
grid[, "fit"] <- c(predict(ozo.m, grid))
Plotting as usual:
contourplot(fit ~ wind * temperature, data = grid,
cuts = 10, region = TRUE,
xlab = "Wind Speed (mph)",
ylab = "Temperature (F)",
main = "Cube Root Ozone (cube root ppb)")
Using the rev() function on temperature:
contourplot(fit ~ wind * rev(temperature), data = grid,
cuts = 10, region = TRUE,
xlab = "Wind Speed (mph)",
ylab = "Temperature (F)",
main = "Cube Root Ozone (cube root ppb)")
detach()
I would like it so the y (temperature) axis labels are reversed as well as as the y axis values. (i.e. it reads 90, 80, 70, 60 going bottom to top rather than 60, 70, 80, 90)