Skip to content
Prev 361188 / 398506 Next

Shaded areas in R

Thanks for your answers

I'm going to share my script and my database in an excel file, where you
can check the kind of graph I would like to make (see attached document,
you can find it in Sheet1. Sheet 3 is the one that I used in .csv format to
work with in R).

Script:

# HYDROGRAPH SEPARATION ANALYSIS FOR EVENTS: JULY 9TH AND SEPT 11TH

# Event 20. July 9th, 2015

setwd("C:\\Users\\Asus\\Desktop\\MSc Thesis - INIRENA\\R\\Downloads")
dir()

  # Ev20HS: P event 20. Hydrograph separation
Ev20HS <- read.table("Event20_Hydrograph_Separation.txt", skip=4,
header=FALSE, stringsAsFactors=FALSE)
as.data.frame(Ev20HP)
colnames(Ev20HS)<- c("Date","Hour","P", "Qt", "St2H", "P2H", "GW2H",
"St18O", "P18O", "GW18O",
                     "Qold2H", "Qnew2H", "%old2H", "%new2H", "Qold18O",
"Qnew18O", "%old18O", "%new18O")
paste(Ev20HS$Date, Ev20HS$Hour)
Ev20HS$date.time <- paste(Ev20HS$Date, Ev20HS$Hour)
as.POSIXct(Ev20HS$date.time, format="%Y/%m/%d %H:%M:%S", tz="-7")
Ev20HS$date.time <- as.POSIXct(Ev20HS$date.time, format="%Y/%m/%d
%H:%M:%S", tz="-7")

par(mar=c(4, 4, 4, 4))
plot(Ev20HS$date.time, Ev20HS$P, type="h", axes= FALSE, col="cadetblue4",
ylim=c(10,0),
     lwd=2, xlab= "Hour", xline= 1.5, ylab = " ")
axis (4, lwd= 1)
mtext (4, line=2, text="P (mm)")
par(new=T)
plot(Ev20HS$date.time, Ev20HS$Qt, type="l", col="deepskyblue", lwd=2,
ylim=c(0,0.02), xlab= " ", ylab = " ")
axis (2, lwd= 1)
mtext (2, line=2.25, text="Q (mm/10min)")
par(new=T)
plot(Ev20HS$date.time, Ev20HS$Qold2H, type="l", axes= FALSE, col="sienna3",
lwd=2, ylim=c(0,0.02), xlab= " ", ylab = " ")
cord.x <- c(7, 7, 13, 13)
cord.y <- c(0.00223742, 0.00238599, 0.01043445, 0.00970288)
polygon(cord.x, cord.y, col="steelblue3")


I want to plot in the same graph:

a) Precipitation (P) as a barplot (downwards) --> DONE
b) Total discharge in Stream (Qt) --> DONE
c) Discharge of groundwater, i.e. old component (Qold2H) --> The space
between Qt and Qold2H needs to be shaded with one colour, and the space
between Qold2H and x-axes needs to be shaded as well.


Another question, is there any option to make these curves smoother? I
don't really like those ugly peaks.
On 26 May 2016 at 17:21, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:

            
Message-ID: <CAJAnTBUQJ34Q+aauT7Xzfsx_apSpwiZ2jhPrVvyrrFKpZ5rhcg@mail.gmail.com>
In-Reply-To: <6cdb6c07-d5f0-dd08-9c58-68ca67628dc7@gmail.com>