|
| 1 | +## ----message=FALSE, echo=TRUE, fig.cap="Demo workflow", fig.width=6, fig.height=6---- |
| 2 | +library(gsplot) |
| 3 | + |
| 4 | +MaumeeDV <- MaumeeDV |
| 5 | + |
| 6 | +demoPlot <- gsplot() %>% |
| 7 | + points(y=c(3,1,2), x=1:3, xlim=c(0,NA),ylim=c(0,NA), |
| 8 | + col="blue", pch=18, legend.name="Points", xlab="Index") %>% |
| 9 | + lines(c(3,4,3), c(2,4,6), legend.name="Lines", ylab="Data") %>% |
| 10 | + abline(b=1, a=0, legend.name="1:1") %>% |
| 11 | + legend(location="topleft",title="Awesome!") %>% |
| 12 | + grid() %>% |
| 13 | + error_bar(x=1:3, y=c(3,1,2), y.high=c(0.5,0.25,1), y.low=0.1) %>% |
| 14 | + error_bar(x=1:3, y=c(3,1,2), x.low=.2, x.high=.2, col="red",lwd=3) %>% |
| 15 | + callouts(x=1, y=2.8, lwd=2, angle=250, labels="Weird data") %>% |
| 16 | + title("Graphing Fun") |
| 17 | +demoPlot |
| 18 | + |
| 19 | + |
| 20 | +## ----echo=TRUE, message=FALSE-------------------------------------------- |
| 21 | + |
| 22 | +sites <- unique(MaumeeDV$site_no) |
| 23 | +dates <- sapply(sites, function(x) MaumeeDV$Date[which(MaumeeDV$site_no==x)], USE.NAMES=TRUE) |
| 24 | +flow <- sapply(sites, function(x) MaumeeDV$Flow[which(MaumeeDV$site_no==x)], USE.NAMES=TRUE) |
| 25 | +pH <- sapply(sites, function(x) MaumeeDV$pH_Median[which(MaumeeDV$site_no==x)], USE.NAMES=TRUE) |
| 26 | +Wtemp <- sapply(sites, function(x) MaumeeDV$Wtemp[which(MaumeeDV$site_no==x)], USE.NAMES=TRUE) |
| 27 | + |
| 28 | + |
| 29 | +## ----echo=TRUE, fig.cap="Fig. 1 Simple flow timeseries using `gsplot`.", fig.width=6, fig.height=6---- |
| 30 | +site <- '04193500' |
| 31 | +demoPlot <- gsplot(mgp=c(2.75, 0.3, 0.0)) %>% |
| 32 | + lines(dates[[site]], flow[[site]], col="royalblue") %>% |
| 33 | + title(main=paste("Site", site), ylab="Flow, ft3/s") %>% |
| 34 | + grid() |
| 35 | +demoPlot |
| 36 | + |
| 37 | + |
| 38 | +## ----echo=TRUE, fig.cap="Fig. 2 Simple flow timeseries with a logged y-axis using `gsplot`.", fig.width=6, fig.height=6---- |
| 39 | +site <- '04193500' |
| 40 | +options(scipen=5) |
| 41 | +demoPlot <- gsplot(mgp=c(3, 0.3, 0.0)) %>% |
| 42 | + lines(dates[[site]], flow[[site]], |
| 43 | + col="royalblue", log='y', |
| 44 | + ylab= expression(paste("Discharge in ",ft^3/s))) %>% |
| 45 | + title(main=paste("Site", site)) %>% |
| 46 | + grid(equilogs=FALSE) |
| 47 | +demoPlot |
| 48 | + |
| 49 | + |
| 50 | +## ----echo=TRUE, fig.cap="Fig. 3 (a) pH vs water temperature, (b) pH timeseries, (c) water temperature timeseries.", fig.width=6, fig.height=6---- |
| 51 | +site <- '04193490' |
| 52 | +plot1 <- gsplot() %>% |
| 53 | + points(Wtemp[[site]], pH[[site]], col="black")%>% |
| 54 | + title(main=paste("Site", site), xlab="Water Temperature (deg C)", ylab="pH") |
| 55 | +plot2 <- gsplot() %>% |
| 56 | + lines(dates[[site]], pH[[site]], col="seagreen")%>% |
| 57 | + title(main="", xlab="time", ylab="pH") |
| 58 | +plot3 <- gsplot() %>% |
| 59 | + lines(dates[[site]], Wtemp[[site]], col="orangered")%>% |
| 60 | + title(main="", xlab="time", ylab="Water Temperature (deg C)") |
| 61 | + |
| 62 | +layout(matrix(c(1,2,3), byrow=TRUE, nrow=3)) |
| 63 | +plot1 |
| 64 | +plot2 |
| 65 | +plot3 |
| 66 | + |
| 67 | + |
| 68 | +## ----echo=TRUE, fig.cap="Fig. 4 Water temperature timeseries on primary y-axis with pH timeseries on secondary y-axis.", fig.width=6, fig.height=6---- |
| 69 | +site <- '04193490' |
| 70 | +demoPlot <- gsplot(mar=c(7.1, 4.1, 4.1, 4.1)) %>% |
| 71 | + lines(dates[[site]], Wtemp[[site]], col="orangered", |
| 72 | + legend.name="Water Temperature", ylab='Water Temperature (deg C)') %>% |
| 73 | + lines(dates[[site]], pH[[site]], col="seagreen", side=4, |
| 74 | + legend.name="pH", ylab='pH (pH Units)') %>% |
| 75 | + title(main=paste("Site", site), xlab='time') %>% |
| 76 | + legend(location="below") |
| 77 | +demoPlot |
| 78 | + |
| 79 | + |
| 80 | +## ----echo=TRUE, fig.cap="Fig. 5 Initial plot of water temperature timeseries.", fig.width=6, fig.height=6---- |
| 81 | +# initially plot the data |
| 82 | +site <- '04193490' |
| 83 | +demoPlot <- gsplot() %>% |
| 84 | + lines(dates[[site]], Wtemp[[site]], col="orangered") %>% |
| 85 | + title(main=paste("Site", site), xlab='time', ylab='Water Temperature (deg C)') |
| 86 | +demoPlot |
| 87 | + |
| 88 | +## ----echo=TRUE, fig.cap="Fig. 6 Plot of water temperature timeseries with 'Missing Data' callout retroactively added.", fig.width=6, fig.height=6---- |
| 89 | +# notice the missing data from ~ 1991 through ~2011 and add a callout |
| 90 | +demoPlot <- callouts(demoPlot, x=as.Date("2000-01-01"), y=10,labels="Missing Data") |
| 91 | +demoPlot |
| 92 | + |
| 93 | + |
0 commit comments