#' @title Plot of VWC for Adenostoma project, including precipitation.
#'
#' @description Generated July 8 2017 with all relevant data.
#'
#' @source Michala Phillips
#'
setwd("D:/R_Workspace/SDEF/2017_6_Analysis_scripts/Processed_VWC_Data/")
load(file="2017_08_07_RunningAvg_VWC_Plot_Data.RData")
source('D:/R_Workspace/SDEF/2017_6_Analysis_scripts/PlotPrecip.R')
setwd("D:/R_Workspace/SDEF/SDEF.analysis/inst/extdata/")
rain <- read.csv("SDEF_rain_events.csv")
rain$date <- strptime(rain$ï..date, format = "%m/%d/%Y")
rain$date <- as.Date(rain$date, format = "%Y-m-%d")
rain <- rain[, c(3, 2)]
rain$precip <- rain$precip*2.54
longdate <- data.frame(date=seq(as.Date("2015-10-01"), as.Date("2016-08-01"), by="days"))
adefas.mean <- merge(adefas.mean, longdate,by.x='Date',by.y='date',all.x=T,all.y=T)
adefas.mean$Native <- adefas.mean$VWC
grass.mean$Invasive <- grass.mean$VWC
bare.mean$Bare <- bare.mean$VWC
Months <- seq(min(adefas.mean$Date), max(adefas.mean$Date), format="%m-%Y",
by = "months")
par(mar = c(5,5,2,5))
plot(adefas.mean,
xlab = "Time (month)",
ylab = "Volumetric Water Content (%)",
xaxt='n',
type = "l", lwd = 3 , lty = 2, col = "gray18", ylim = c(0,20))
grid(NULL, NULL, lty=1, lwd=1, col="gray94")
lines(grass.mean, col = "gray", lty = 1, lwd = 3)
lines(bare.mean, col = 'gray87', lty = 6, lwd= 3)
PlotPrecip(df = rain, lwd = 2, col = "black")
axis(side = 4)
mtext(side = 4, line = 3, 'Precipitation (cm)')
axis.Date(1, at = Months, format="%b-%y")
legend(x="topright", y=1,
legend = c("Native plot", "Invasive plot", "Bare plot", "Precipitation"), bty = "n",
col = c("gray18", "gray", "gray87", "black" ), lty = c(2,1,6, 1), lwd = 2, cex = 1)
colnames(bare.mean) <- c("Date", "VWC", "Bare_Ground")
test_plot <- ggplot(rain)+ geom_bar(data = rain, aes(x=date, y= precip),stat="identity", fill="black")+
geom_line(data = adefas.mean, aes(x = Date, y = Native, colour = "Native"), size = 1.2)+
geom_line(data = grass.mean, aes(x = Date, y = Invasive, colour = "Invasive"), size = 1.2)+
geom_line(data = bare.mean, aes(x = Date, y = Bare_Ground, colour = "Bare_Ground"),size = 1)+
ylab("Volumetric Water Content (%)") +
scale_colour_manual("", breaks = c("Native", "Invasive", "Bare_Ground"), values=c( "gray74", "black", "grey50"))+
xlab("Time (month)") +
scale_x_date(labels = date_format("%b-%y"), date_breaks = "2 month")+
scale_y_continuous(sec.axis = sec_axis(~.*1, name = "Precipitation (cm)")) +
theme_bw(base_family = "sans", base_size = 13)
test_plot
# color plot
color_plot <- ggplot(rain)+ geom_bar(data = rain, aes(x=date, y= precip),stat="identity", fill="black")+
geom_line(data = adefas.mean, aes(x = Date, y = Native, colour = "Native"), size = 1.2)+
geom_line(data = grass.mean, aes(x = Date, y = Invasive, colour = "Invasive"), size = 1.2)+
geom_line(data = bare.mean, aes(x = Date, y = Bare_Ground, colour = "Bare_Ground"),size = 1.2)+
ylab("Volumetric Water Content (%)") +
scale_colour_manual("", breaks = c("Native", "Invasive", "Bare_Ground"), values=c("#46ACC8","#E58601", "#E2D200"))+
xlab("Time (month)") +
scale_x_date(labels = date_format("%b-%y"), date_breaks = "2 month")+
scale_y_continuous(sec.axis = sec_axis(~.*1, name = "Precipitation (cm)")) +
theme_bw()
color_plot
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.