From f95a3be1bd803fbe193bc235baca52533cedacb3 Mon Sep 17 00:00:00 2001 From: Dorchies David <david.dorchies@inrae.fr> Date: Tue, 7 Jul 2020 16:24:44 +0200 Subject: [PATCH] Some bug fixes: - issue for displaying ggplot - reduce dependency list - fix bugs introduced by me --- Modified Sequent Peak Algorithm (mSPA)/SPA.R | 37 ++++++-------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/Modified Sequent Peak Algorithm (mSPA)/SPA.R b/Modified Sequent Peak Algorithm (mSPA)/SPA.R index 675c430..2b820bb 100644 --- a/Modified Sequent Peak Algorithm (mSPA)/SPA.R +++ b/Modified Sequent Peak Algorithm (mSPA)/SPA.R @@ -1,27 +1,10 @@ -library("pacman") -library(hydroTSM) -library(reshape2) -pacman::p_load( - pacman, - dplyr, - GGally, - ggplot2, - ggthemes, - ggvis, - httr, - lubridate, - plotly, - rio, - rmarkdown, - shiny, - stringr, - tidyr -) +library(ggplot2) +library(readr) data <- readr::read_delim( file = "https://raw.githubusercontent.com/infohquan/link/master/inputdata_b.txt", - delim = "\t" + delim = "\t", col_names = c("inflow", "release", "precip", "evapo", "downstreamFlow") ) time <- @@ -43,11 +26,11 @@ year <- "%Y" )) n <- NROW(na.omit(data)) -Inflow <- data[, 1] -dem <- data[, 2] -prec <- data[, 3] -eva <- data[, 4] -netev <- (data[, 4] - data[, 3]) / 1000 +Inflow <- data$inflow +dem <- data$release +prec <- data$precip +eva <- data$evapo +netev <- (data$evapo - data$precip) / 1000 rule_curve <- c(34, 50, 63, 73, 77, 79, 80, 63, 46, 29, 12, 21) DS <- rep(8.5, 12) capacity <- rep(82.5, 12) @@ -155,7 +138,8 @@ result$Month = factor( result.gather <- gather(result, key = "Rule Curve", value = IndexValue, -Month) -ggplot(result.gather, +print( + ggplot2::ggplot(result.gather, aes(Month, IndexValue, group = `Rule Curve`, color = `Rule Curve`)) + ylim(0, 85) + geom_line(aes(y = IndexValue), lwd = 1.2) + @@ -164,3 +148,4 @@ ggplot(result.gather, x = "") + theme_few(base_size = 20) + scale_color_brewer(palette = "Set2") + theme(plot.title = element_text(hjust = 0.5)) +) \ No newline at end of file -- GitLab