我想使用 lattice 包生成等高线图,其中 y 轴从顶部开始并到达底部(即顶部的最小值,底部的最大值)。如果我更改以下内容:
contourplot(Male ~ Age * Year, data=this.ds)
到
contourplot(Male ~ Age * rev(Year), data=this.ds)
然后图形被正确绘制,但 y 轴刻度标签没有反转。(即仍然从底部开始并到顶部。) - (有关完全可重现的示例,请参阅消息末尾。)
我认为答案涉及使用“比例”列表对象(所以我认为这是一个单行解决方案),但不确定它是什么。
非常感谢您的帮助,乔恩
完全可重现的示例:
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))
像往常一样绘制:
contourplot(fit ~ wind * temperature, data = grid,
cuts = 10, region = TRUE,
xlab = "Wind Speed (mph)",
ylab = "Temperature (F)",
main = "Cube Root Ozone (cube root ppb)")
在温度上使用 rev() 函数:
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()
我想要它,所以 y(温度)轴标签以及 y 轴值是相反的。(即从下到上读取 90、80、70、60 而不是 60、70、80、90)