Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
swatdoctr
Manage
Activity
Members
Labels
Plan
Issues
5
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christoph Schürz
swatdoctr
Commits
aa216b2f
Commit
aa216b2f
authored
2 years ago
by
Christoph Schürz
Browse files
Options
Downloads
Patches
Plain Diff
Generalize plot at harvest kill function
parent
33a4e943
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
NAMESPACE
+1
-1
1 addition, 1 deletion
NAMESPACE
R/print_mgt.R
+42
-11
42 additions, 11 deletions
R/print_mgt.R
man/plot_variable_at_harvkill.Rd
+25
-0
25 additions, 0 deletions
man/plot_variable_at_harvkill.Rd
with
68 additions
and
12 deletions
NAMESPACE
+
1
−
1
View file @
aa216b2f
...
...
@@ -3,7 +3,7 @@
export(get_hru_id_by_attribute)
export(plot_climate_annual)
export(plot_hru_pw_day)
export(plot_
phuplan
t_harv
est
)
export(plot_
variable_a
t_harv
kill
)
export(print_triggered_mgt)
export(run_swat_verification)
import(ggplot2)
...
...
This diff is collapsed.
Click to expand it.
R/print_mgt.R
+
42
−
11
View file @
aa216b2f
...
...
@@ -32,33 +32,64 @@ print_triggered_mgt <- function(sim_verify, hru_id, start_year = 1900, end_year
print
(
.
,
n
=
Inf
)
}
#' Boxplot
of heat unit fractions for crop
s at harvest-kill
operation
#' Boxplot
for relevant variable
s at harvest-kill
#'
#' plot_phuplant_harvest plots boxplots of the collected heat unit fractions
#' plot_variable_at_harvkill plots boxplots of one of the variables crop heat unit
#' fractions ('phu'), crop yields ('yield'), or plant biomass ('bioms') for crops
#' at harvest-kill of a crop separated for all identified crops.
#'
#' @param sim_verify Simulation output of the function \code{run_swat_verification()}.
#' To plot the heat units at least the output option \code{outputs = 'mgt'} must
#' be set in \code{run_swat_verification()}
#' @param variable Selected variable to be plotted. Must be one of: 'phu', 'yield', 'bioms'
#' @param years Simulated years which are aggregated in the boxplot
#'
#' @return ggplot boxplot
with crop heat unit fractions
at harvest-kill.
#' @return ggplot boxplot
the selected variable
at harvest-kill.
#'
#' @importFrom dplyr filter group_by mutate rename select ungroup %>%
#' @importFrom ggplot2 aes ggplot geom_boxplot geom_hline labs theme_bw
#' @importFrom purrr set_names
#' @export
#'
plot_phuplant_harvest
<-
function
(
sim_verify
)
{
hu_harv
<-
sim_verify
$
mgt_out
%>%
plot_variable_at_harvkill
<-
function
(
sim_verify
,
variable
,
years
=
1900
:
2100
)
{
tbl_harv
<-
sim_verify
$
mgt_out
%>%
filter
(
year
%in%
years
)
%>%
filter
(
operation
%in%
c
(
'HARVEST'
,
'KILL'
))
%>%
group_by
(
hru
,
year
,
mon
,
day
)
%>%
mutate
(
n
=
n
())
%>%
ungroup
()
%>%
filter
(
n
==
2
,
operation
==
'HARVEST'
)
%>%
select
(
op_typ
,
phuplant
)
filter
(
n
==
2
,
operation
==
'HARVEST'
)
ggplot
(
data
=
hu_harv
)
+
geom_boxplot
(
aes
(
x
=
op_typ
,
y
=
phuplant
))
+
geom_hline
(
yintercept
=
1
,
lty
=
2
)
+
labs
(
x
=
'Crops'
,
y
=
'Crop HUs at harvest'
)
+
if
(
variable
==
'phu'
)
{
tbl_harv
<-
tbl_harv
%>%
select
(
op_typ
,
phuplant
)
%>%
set_names
(
c
(
'crop'
,
'var'
))
y_lbl
<-
'Crop HUs at harvest/kill'
}
else
if
(
variable
==
'yield'
)
{
tbl_harv
<-
tbl_harv
%>%
select
(
op_typ
,
op_var
)
%>%
set_names
(
c
(
'crop'
,
'var'
))
y_lbl
<-
'Crop yield at harvest/kill'
}
else
if
(
variable
==
'bioms'
)
{
tbl_harv
<-
tbl_harv
%>%
select
(
op_typ
,
plant_bioms
)
%>%
set_names
(
c
(
'crop'
,
'var'
))
y_lbl
<-
'Biomass at harvest/kill'
}
else
{
stop
(
"Variable must be one of: 'phu', 'yield', 'bioms'"
)
}
gg
<-
ggplot
(
data
=
tbl_harv
)
+
geom_boxplot
(
aes
(
x
=
crop
,
y
=
var
))
+
labs
(
x
=
'Crops'
,
y
=
'Crop HUs at harvest/kill'
)
+
theme_bw
()
if
(
variable
==
'phu'
)
{
gg
+
geom_hline
(
yintercept
=
1
,
lty
=
2
)
}
return
(
gg
)
}
This diff is collapsed.
Click to expand it.
man/plot_
phuplan
t_harv
est
.Rd
→
man/plot_
variable_a
t_harv
kill
.Rd
+
25
−
0
View file @
aa216b2f
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/print_mgt.R
\name{plot_
phuplan
t_harv
est
}
\alias{plot_
phuplan
t_harv
est
}
\title{Boxplot
of heat unit fractions for crop
s at harvest-kill
operation
}
\name{plot_
variable_a
t_harv
kill
}
\alias{plot_
variable_a
t_harv
kill
}
\title{Boxplot
for relevant variable
s at harvest-kill}
\usage{
plot_
phuplan
t_harv
est
(sim_verify)
plot_
variable_a
t_harv
kill
(sim_verify
, variable, years = 1900:2100
)
}
\arguments{
\item{sim_verify}{Simulation output of the function \code{run_swat_verification()}.
To plot the heat units at least the output option \code{outputs = 'mgt'} must
be set in \code{run_swat_verification()}}
\item{variable}{Selected variable to be plotted. Must be one of: 'phu', 'yield', 'bioms'}
\item{years}{Simulated years which are aggregated in the boxplot}
}
\value{
ggplot boxplot
with crop heat unit fractions
at harvest-kill.
ggplot boxplot
the selected variable
at harvest-kill.
}
\description{
plot_phuplant_harvest plots boxplots of the collected heat unit fractions
plot_variable_at_harvkill plots boxplots of one of the variables crop heat unit
fractions ('phu'), crop yields ('yield'), or plant biomass ('bioms') for crops
at harvest-kill of a crop separated for all identified crops.
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment