I'm trying to produce a raster graph (like a hovmoller diagram) and was hoping someone might help. I've looked at the help with rasterVis and some others but can't seem to get their examples to suit my data, which probably needs transforming in some way that is eluding me. I've managed to create the plot but the fill values for the cells are not corresponding to the original data. I've copied a dput() file of an example of my data frame (hope this is the right way to do this). What I want is days of the year (DOY) along the x axis with a y axis of 48 rectangles (hour column in DF) above each DOY. These rectangles would represent half hourly intervals for each DOY and would be coloured according to their corresponding a value (qc column in DF) which is 0,1 or 2
So far I've come up with the following code but there seems to be a problem with the allocation of the z value (qc column) to the colour, I think the values are not lining up properly for some reason...
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)
What seems to be happening is that the fill value matrix (z) is applied running along the bottom of the x axis first (left to right) then looping to the top whereas I need it to start at the bottom left hand corner and go up then loop left to right (hope that makes some sort of sense!) My example data here only covers three days but the full dataset would be for an entire year (366 in 2012). Thanks in advance for any help,
Jon
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, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L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L, 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))
OK got this worked out now, and rather simply too...
Sorry, that was rather more straightforward than I imagined. I would prefer the legend colours to be discrete rather than continuous but it's a minor detail. Thanks for your input. Jon