Skip to content

Commit

Permalink
remove animated scatter plot (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjyetman authored Sep 20, 2024
1 parent 63e0938 commit 3795acb
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 785 deletions.
2 changes: 0 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ Imports:
dplyr,
ggplot2,
glue,
htmlwidgets,
networkD3,
plotly,
r2dii.analysis,
r2dii.data (>= 0.5.0),
r2dii.match,
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
export(plot_sankey)
export(plot_scatter)
export(plot_scatter_alignment_exposure)
export(plot_scatter_animated)
export(prep_sankey)
export(prep_scatter)
export(prep_scatter_alignment_exposure)
export(prep_scatter_animated)
importFrom(dplyr,"%>%")
importFrom(rlang,":=")
importFrom(rlang,.data)
Expand Down
244 changes: 0 additions & 244 deletions R/plot_aggregate_loanbooks.R
Original file line number Diff line number Diff line change
Expand Up @@ -385,120 +385,6 @@ plot_aggregate_loanbooks <- function(config) {
)
}


### animated scatter plot for group level comparison----
region_scatter <- region_select
data_level_group <- "group_var"
# automotive
sector_scatter <- "automotive"
if (length(by_group) <= 1) {
if (
nrow(loanbook_exposure_aggregated_alignment_bo_po) > 0 &
nrow(loanbook_exposure_aggregated_alignment_net) > 0
) {
data_scatter_automotive_group_a <- prep_scatter_animated(
loanbook_exposure_aggregated_alignment_bo_po,
loanbook_exposure_aggregated_alignment_net,
sector = sector_scatter,
region = region_scatter,
group_var = by_group,
data_level = data_level_group
)

if (is.null(by_group)) {
output_file_scatter_sector <- glue::glue("scatter_{sector_scatter}")
} else {
output_file_scatter_sector <- glue::glue("scatter_{sector_scatter}_by_{by_group}")
}

data_scatter_automotive_group_a %>%
readr::write_csv(
file = file.path(
output_path_aggregated,
glue::glue("data_{output_file_scatter_sector}_animated.csv")
),
na = ""
)

plot_scatter_automotive_group_a <- plot_scatter_animated(
data_scatter_automotive_group_a,
sector = sector_scatter,
data_level = data_level_group,
region = region_scatter,
scenario_source = scenario_source_input,
scenario = scenario_select,
alignment_limit = 1
)

htmlwidgets::saveWidget(
plot_scatter_automotive_group_a,
file = file.path(
output_path_aggregated,
glue::glue("plot_{output_file_scatter_sector}_animated.html")
)
)
}
} else {
print(
glue::glue("Scatter plot BO/PO cannot process more than one group_var at a time. Skipping!")
)
}

# power
sector_scatter <- "power"
if (length(by_group) <= 1) {
if (
nrow(loanbook_exposure_aggregated_alignment_bo_po) > 0 &
nrow(loanbook_exposure_aggregated_alignment_net) > 0
) {
data_scatter_power_group_a <- prep_scatter_animated(
loanbook_exposure_aggregated_alignment_bo_po,
loanbook_exposure_aggregated_alignment_net,
sector = sector_scatter,
region = region_scatter,
group_var = by_group,
data_level = data_level_group
)

if (is.null(by_group)) {
output_file_scatter_sector <- glue::glue("scatter_{sector_scatter}")
} else {
output_file_scatter_sector <- glue::glue("scatter_{sector_scatter}_by_{by_group}")
}

data_scatter_power_group_a %>%
readr::write_csv(
file = file.path(
output_path_aggregated,
glue::glue("data_{output_file_scatter_sector}_animated.csv")
),
na = ""
)

plot_scatter_power_group_a <- plot_scatter_animated(
data_scatter_power_group_a,
sector = sector_scatter,
data_level = data_level_group,
region = region_scatter,
scenario_source = scenario_source_input,
scenario = scenario_select,
alignment_limit = 1
)

htmlwidgets::saveWidget(
plot_scatter_power_group_a,
file = file.path(
output_path_aggregated,
glue::glue("plot_{output_file_scatter_sector}_animated.html")
)
)
}
} else {
print(
glue::glue("Scatter plot BO/PO cannot process more than one group_var at a time. Skipping!")
)
}

# group level plots ----
# create sub directories for each relevant group.
# TODO: Note that this implies that no groups across different .by variables
Expand Down Expand Up @@ -652,134 +538,4 @@ plot_aggregate_loanbooks <- function(config) {
glue::glue("Scatter plot BO/PO only available for group_var of length 1. Skipping!")
)
}

### animated scatter plot for company level comparison----

# for all companies per group, not all companies across groups

# automotive
sector_scatter <- "automotive"

if (length(by_group) == 1) {
unique_by_group <- company_aggregated_alignment_bo_po %>%
dplyr::filter(
.data[["sector"]] == .env[["sector_scatter"]],
!grepl("benchmark_corporate_economy_", !!rlang::sym(by_group))
) %>%
dplyr::pull(!!rlang::sym(by_group)) %>%
unique()

for (i in unique_by_group) {
data_scatter_automotive_company_animated_i <- prep_scatter_animated(
company_aggregated_alignment_bo_po,
company_aggregated_alignment_net,
sector = sector_scatter,
region = region_scatter,
group_var = by_group,
data_level = data_level_company,
groups_to_plot = i
)

if (nrow(data_scatter_automotive_company_animated_i) > 0) {
data_scatter_automotive_company_animated_i %>%
readr::write_csv(
file = file.path(
output_path_aggregated,
i,
glue::glue("data_scatter_automotive_company_by_{by_group}_{i}_animated.csv")
),
na = ""
)

plot_scatter_animated_i <- plot_scatter_animated(
data_scatter_automotive_company_animated_i,
sector = sector_scatter,
data_level = data_level_company,
region = region_scatter,
scenario_source = scenario_source_input,
scenario = scenario_select,
floor_outliers = -1.5,
cap_outliers = 1.5
)

htmlwidgets::saveWidget(
plot_scatter_animated_i,
file = file.path(
output_path_aggregated,
i,
glue::glue("plot_scatter_automotive_company_by_{by_group}_{i}_animated.html")
)
)
} else {
next()
}
}
} else {
print(
glue::glue("Animated scatter plot BO/PO only available for group_var of length 1. Skipping!")
)
}

# power
sector_scatter <- "power"

if (length(by_group) == 1) {
unique_by_group <- company_aggregated_alignment_bo_po %>%
dplyr::filter(
.data[["sector"]] == .env[["sector_scatter"]],
!grepl("benchmark_corporate_economy_", !!rlang::sym(by_group))
) %>%
dplyr::pull(!!rlang::sym(by_group)) %>%
unique()

for (i in unique_by_group) {
data_scatter_power_company_animated_i <- prep_scatter_animated(
company_aggregated_alignment_bo_po,
company_aggregated_alignment_net,
sector = sector_scatter,
region = region_scatter,
group_var = by_group,
data_level = data_level_company,
groups_to_plot = i
)

if (nrow(data_scatter_power_company_animated_i) > 0) {
data_scatter_power_company_animated_i %>%
readr::write_csv(
file = file.path(
output_path_aggregated,
i,
glue::glue("data_scatter_power_company_by_{by_group}_{i}_animated.csv")
),
na = ""
)

plot_scatter_animated_i <- plot_scatter_animated(
data_scatter_power_company_animated_i,
sector = sector_scatter,
data_level = data_level_company,
region = region_scatter,
scenario_source = scenario_source_input,
scenario = scenario_select,
floor_outliers = -1.5,
cap_outliers = 1.5
)

htmlwidgets::saveWidget(
plot_scatter_animated_i,
file = file.path(
output_path_aggregated,
i,
glue::glue("plot_scatter_power_company_by_{by_group}_{i}_animated.html")
)
)
} else {
next()
}
}
} else {
print(
glue::glue("Animated scatter plot BO/PO only available for group_var of length 1. Skipping!")
)
}
}
Loading

0 comments on commit 3795acb

Please sign in to comment.