Skip to content

Commit

Permalink
inserted roxygen doc + built README
Browse files Browse the repository at this point in the history
  • Loading branch information
lindadelacombaz committed Apr 16, 2024
1 parent 249c36e commit ddf6acc
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 26 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Imports:
eurostat,
ggalluvial,
ggplot2,
ggpubr,
giscoR,
glue,
grDevices,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ importFrom(ggplot2,unit)
importFrom(ggplot2,xlim)
importFrom(ggplot2,ylab)
importFrom(ggplot2,ylim)
importFrom(ggpubr,ggarrange)
importFrom(giscoR,gisco_get_nuts)
importFrom(glue,glue)
importFrom(grDevices,rgb)
Expand Down
41 changes: 25 additions & 16 deletions R/scatter_plot_financial.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,19 @@ scatter_plot_financial <- function(data,
),
scenario = c("IPR", "WEO"),
year = c(2030, 2050)) {
#FIXME: .env$ instead of _arg seems to cause a bug too ?
#FIXME: .env$ instead of _arg seems to cause a bug only for benchmarks.
benchmarks_arg <- arg_match(benchmarks, multiple = TRUE)
scenario_arg <- arg_match(scenario)
year_arg <- year
scenario <- arg_match(scenario)
year <- year
mode <- mode |>
arg_match() |>
switch_mode()

data |>
check_scatter_plot_financial() |>
prepare_scatter_plot_financial(benchmarks_arg, scenario_arg, year_arg) |>
prepare_scatter_plot_financial(benchmarks_arg, scenario, year) |>
calculate_scatter_plot_financial(mode) |>
plot_scatter_financial_implementation()

plot_scatter_financial()
}

#' Check scatter plot with financial data
Expand Down Expand Up @@ -77,7 +76,7 @@ check_scatter_plot_financial <- function(data) {
data
}

#' Process data
#' Prepare data
#'
#' @param data A data frame.
#' @param benchmarks A character vector.
Expand All @@ -86,12 +85,12 @@ check_scatter_plot_financial <- function(data) {
#'
#' @return A data frame.
#' @noRd
prepare_scatter_plot_financial <- function(data, benchmarks_arg, scenario_arg, year_arg) {
prepare_scatter_plot_financial <- function(data, benchmarks, scenario, year) {
data <- data |>
filter(
.data$benchmark %in% benchmarks_arg,
.data$scenario == scenario_arg,
.data$year == year_arg
.data$benchmark %in% .env$benchmarks,
.data$scenario == .env$scenario,
.data$year == .env$year
)

data
Expand Down Expand Up @@ -119,8 +118,14 @@ calculate_rank <- function(data, mode, col) {
list(rank,data)
}

#' Implement Rank
#'
#' @param data A data frame.
#' @param mode A string.
#'
#' @return A data frame.
#' @noRd
calculate_scatter_plot_financial <- function(data, mode) {

data <- calculate_rank(data, mode, "profile_ranking")[[2]]

data$emission_profile_average <- calculate_rank(data, mode, "profile_ranking")[[1]]
Expand All @@ -129,8 +134,13 @@ calculate_scatter_plot_financial <- function(data, mode) {
data
}

plot_scatter_financial_implementation <- function(data) {

#' Plot the scatter financial plot
#'
#' @param data A data frame.
#'
#' @return A [ggplot] object.
#' @noRd
plot_scatter_financial <- function(data) {
emission_rank_legend <- label_emission_rank() |> format_label()
transition_risk_legend <- label_transition_risk() |> format_label()

Expand All @@ -150,9 +160,8 @@ plot_scatter_financial_implementation <- function(data) {
ylab(transition_risk_legend) +
theme_tiltplot()

plot <- ggarrange(emission_rank_plot, transition_score_plot, ncol = 2, nrow = 1)
plot <- ggarrange(emission_rank_plot, transition_score_plot)
plot

}


1 change: 1 addition & 0 deletions R/tiltPlot-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#' @importFrom ggplot2 xlim
#' @importFrom ggplot2 ylab
#' @importFrom ggplot2 ylim
#' @importFrom ggpubr ggarrange
#' @importFrom giscoR gisco_get_nuts
#' @importFrom glue glue
#' @importFrom grDevices rgb
Expand Down
1 change: 0 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ switch_mode <- function(mode) {
#' names_matching(data, "ab")
#' @noRd
names_matching <- function(data, pattern) {
#names(select(data, matches(paste0("\\b", pattern, "\\b"))))
names(select(data, matches(pattern)))
}

Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fin <- financial
scenario <- "WEO"
year <- 2030
benchmarks = c("all", "unit")
mode = "equal_weight"
mode = "best_case"
scatter_plot_financial(fin,
benchmarks = benchmarks,
Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,14 @@ bar_plot_emission_profile(no_fin, benchmarks) +
fin <- financial
scenario <- "WEO"
year <- 2030
benchmarks = c("all", "unit")
mode = "best_case"

scatter_plot_financial(fin,
benchmarks = c("all", "unit"),
mode = "worst_case",
benchmarks = benchmarks,
mode = mode,
scenario = scenario,
year = year
) +
labs(title = paste(
"Scatter plot for financial data. Scenario", scenario,
"and year", year
))
year = year)
```

<img src="man/figures/README-unnamed-chunk-13-1.png" width="100%" />
Expand All @@ -220,6 +217,7 @@ map_region_risk(no_fin, "DE", benchmark = "tilt_sector", mode = "worst_case") +
that are found in one region.
© EuroGeographics for the administrative boundaries ")
#> Extracting data using giscoR package, please report issues on https://github.com/rOpenGov/giscoR/issues
#> Cache management as per giscoR. see 'giscoR::gisco_get_nuts()'
```

<img src="man/figures/README-unnamed-chunk-14-1.png" width="100%" />
Binary file modified man/figures/README-unnamed-chunk-13-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ddf6acc

Please sign in to comment.