gpt4 book ai didi

r - 如何使用 Lattice 包在等高线图中反转 Y 轴

转载 作者:行者123 更新时间:2023-12-04 04:42:30 26 4
gpt4 key购买 nike

我想使用点阵包生成一个等高线图,其中 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)

最佳答案

您可以尝试反转 labels scales 中 y 轴的论据。

library(lattice)
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)",
scales = list(y = list(
labels = seq(from = 100, to = 60, by = -10))))

老实说我以为 seq(from = 90, to = 60, by = -10)应该可以工作,但它给了标签 80, 70, 60, NA .

关于r - 如何使用 Lattice 包在等高线图中反转 Y 轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18676219/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com