我正在尝试制作一个光栅图(如 hovmoller 图),并希望有人能提供帮助。我已经查看了 rasterVis 和其他一些人的帮助,但似乎无法让他们的示例适合我的数据,这可能需要以某种我无法理解的方式进行转换。我设法创建了绘图,但单元格的填充值与原始数据不对应。我已经复制了我的数据框示例的 dput() 文件(希望这是正确的方法)。我想要的是沿 x 轴的一年中的几天(DOY),每个 DOY 上方有 48 个矩形的 y 轴(DF 中的小时列)。这些矩形将代表每个 DOY 的半小时间隔,并根据其对应的值(DF 中的 qc 列)为 0,1 或 2 着色
到目前为止,我已经提出了以下代码,但似乎将 z 值(qc 列)分配给颜色存在问题,我认为这些值由于某种原因没有正确排列......
mcol <- c("green","blue","red")
x=unique(DF[,"DOY"])
y=unique(DF[,"hour"])
z=matrix(DF[,"qc"],nrow=length(unique(DF[,"DOY"])),
ncol=length(unique(DF[,"hour"])))
image(x,y,z, col=mcol,
xlab="Day of Year 2012",
ylab="Hour of day",
main="Hovmoller plot of 2012 qc flags",
useRaster=TRUE)
似乎正在发生的是填充值矩阵(z)首先沿x轴底部(从左到右)运行,然后循环到顶部,而我需要它从左下角开始并向上然后从左到右循环(希望有某种意义!)我这里的示例数据只涵盖三天,但完整的数据集将是一整年(2012 年为 366)。提前感谢您的帮助,
乔恩
structure(list(DOY = c(4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 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
2L, 2L, 0L, 2L, 2L, 0L, 0L, 1L, 2L, 0L, 2L, 0L, 1L, 2L, 1L,
2L, 2L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 2L, 2L, 2L, 0L, 0L,
2L, 0L, 0L, 0L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L)), .Names = c("DOY",
"hour", "qc"), class = "data.frame", row.names = c(NA, -144L))