-
Notifications
You must be signed in to change notification settings - Fork 0
/
raster_qplot.R
127 lines (81 loc) · 3.47 KB
/
raster_qplot.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#'
#'
#' Raster plot of streamflow data. This produces a plot showing the flow data in colours
#' Raster layout lets the use see the data in a different context than in
#' a hydrograph.
#'
#' @description {
#' Produces a raster plot: years against day of year, showing magnitude of flow data
#'}
#' @param dframe - a datafile from water survey read by read.wsc()
#' @author Paul Whitfield <[email protected]>
#' Produces a colour plot of observations with colour symbol high flows in warm colours
#'
#' @export
#'
#'
#' @examples
#' data(W05AA008)
#' qplot <-raster_qplot(W05AA008)
#'
raster_qplot <- function( dframe, rastercolours=c("lightblue","cyan", "blue", "slateblue", "orange", "red")) {
##### Fixed labels and text strings
DOY <- "Day of Year"
ylabelq=expression(paste("Discharge m" ^{3}, "/sec"))
qcols=grDevices::colorRampPalette(rastercolours)
station <- as.character(dframe$ID[1])
sname<- get_wscstation(station)
title=sname$Station_lname
date <-as.Date(dframe$Date,"%Y/%m/%d")
Year <- as.numeric(format(date,"%Y"))
doy <- as.numeric(timeDate::dayOfYear(timeDate::as.timeDate(date)))
mYear <-max(Year, na.rm=TRUE)
nYear <-min(Year, na.rm=TRUE)-1
Years <-mYear-nYear
qdata <- array(dim=c(366, Years))
for (k in 1:length(dframe[,1])) {
qdata[doy[k],(Year[k]-nYear)] <- dframe$Flow[k]
}
qmax <-max(qdata, na.rm=TRUE)
qmin <-min(qdata, na.rm=TRUE)
################################ raster map of daily flows
qdata <-as.matrix(qdata)
########################################################### start plotting section
graphics::par(oma=c(0,0,3,0))
graphics::layout(matrix(c(1,1,1,1,2,1,1,1,1,3), 2, 5, byrow = TRUE))
graphics::par(mar=c(4,4,1,1))
################################################################# panel one
doys <-c(1:366)
lyears <- c((nYear+1):mYear)
graphics::image(1:366,1:length(lyears), qdata, axes=FALSE, col=qcols(9),
zlim=c(qmin,qmax), xlab="", ylab="")
sdoy <- sub_set_Years(doys,10)
graphics::axis(1, at=sdoy$position,labels=sdoy$label, cex=1.2)
if(length(lyears)>=70) nn<-10 else nn<-5
sYears <- sub_set_Years(lyears,nn)
graphics::axis(2, at=sYears$position,labels=sYears$label, cex.axis=1.2, las=1)
graphics::mtext(DOY,side=1, line =2.2, cex=0.9)
graphics::box()
################################################################# panel two
graphics::frame()
graphics::par(mar=c(2,2,2,2))
######### scale bar and legend
fields::image.plot(zlim= c(qmin,qmax), col=qcols(9), legend.only=TRUE,
legend.width=4, legend.mar=1,
legend.shrink=1.0,
bigplot=c(0.1,0.2,0.1,0.2),
legend.args=list(text=ylabelq, side=2,line=0.5, cex=0.90))
################################################################# panel three (element #ten)
graphics::frame()
graphics::frame()
graphics::frame()
graphics::frame()
graphics::frame()
############################################################## Add title
tscale=1.7
if(nchar(title)>=45) tscale=1.5
if(nchar(title)>=50) tscale=1.2
graphics::mtext(title, side=3, line=0, cex=tscale,outer=TRUE)
############################################################### end plotting section
return()
}