Skip to content

Commit

Permalink
Merge pull request #45 from jamiemkass/figs_edits
Browse files Browse the repository at this point in the history
Final figs edits
  • Loading branch information
sylvainschmitt authored Jun 12, 2024
2 parents 24d8883 + 22c4834 commit 1566031
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 55 deletions.
31 changes: 15 additions & 16 deletions R/plot_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ plot_table <- function(
data_integration = "data integration",
env_collinearity = "environmental variable collinearity",
env_process = "environmental variable processing",
bias = "addressing data biases",
study_region = "defining model training extent",
bias = "address data biases",
study_region = "define model training extent",
backg_sample = "background data sampling",
data_partitioning = "occurrence data partitioning",
mod_fit = "model fitting",
Expand All @@ -47,9 +47,9 @@ plot_table <- function(
mod_multispecies = "multispecies modeling",
mod_mechanistic = "mechanistic modeling",
pred_general = "model prediction",
pred_extrapolation = "model extrapolation tools/plots",
pred_inspect = "model behavior inspection/plots",
post_processing = "using predictions as analysis inputs",
pred_extrapolation = "model extrapolation tools",
pred_inspect = "model behavior inspection",
post_processing = "post-processing",
gui = "graphical user interface",
metadata = "metadata tools"
)
Expand All @@ -75,19 +75,18 @@ plot_table <- function(

d_n <- rev(unique(dd$category))
dd$category <- factor(dd$category, levels = d_n)
dd <- dd |> dplyr::filter(value == TRUE)

ggplot(dd, aes(y = category, x = name, fill = value)) +
geom_tile() +
scale_fill_discrete(
guide = "none",
type = c("white", "gray30")
) +
ggplot(dd, aes(y = category, x = name, fill = category)) +
geom_tile(color = "white", fill = "gray20") +
coord_equal() +
theme_bw() +
scale_x_discrete(position = "top") +
theme(
axis.text.x = element_text(color = pkg_cols, angle = 90, size = 12),
axis.text.y = element_text(size = 12),
axis.title = element_blank()
) +
scale_x_discrete(position = "top")
axis.text.x.top = element_text(color = pkg_cols, angle = 90, size = 14,
hjust = 0, vjust = 0.5, face = "bold"),
axis.text.y = element_text(size = 14),
axis.title = element_blank(),
legend.position = "none"
)
}
67 changes: 28 additions & 39 deletions inst/scripts/ms_figs.R
Original file line number Diff line number Diff line change
@@ -1,48 +1,37 @@
library(dplyr)

d <- prep_table(where = "online")
d$env_process <- ifelse(d$env_collinearity == TRUE, TRUE, d$env_process)
d$study_region <- ifelse(d$backg_sample == TRUE, TRUE, d$study_region)
d$pred_inspect <- ifelse(d$pred_extrapolation == TRUE, TRUE, d$pred_inspect)
d$mod_combine <- d$mod_ensemble
d$mod_combine <- ifelse(d$mod_stack == TRUE, TRUE, d$mod_combine)
d <- select(d, -data_integration, -env_collinearity, -backg_sample,
-pred_extrapolation, -mod_multispecies, -mod_mechanistic,
-mod_stack, -mod_ensemble, -pred_general, -mod_fit) |>
filter(name != "rgbif", name != "ibis.iSDM", name != "dismo")

pal <- c("#1b9e77", "#d95f02", "#7570b3", "#e7298a", "#66a61e", "#e6ab02",
"#a6761d", "#666666")

pdf("fig3.pdf", height = 7, width = 16)
f2a <- plot_dendrogram(d, k = 8, cex = 0.7, diff_method = "binary",
k_colors = pal, horiz = TRUE, main = "")
f2b <- plot_dendrogram(d, k = 7, cex = 1, diff_method = "binary",
type = "phylogenic", repel = TRUE, k_colors = pal)
gridExtra::grid.arrange(f2a, f2b, nrow = 1, widths = c(10, 6))
dev.off() #nolint

clust <- plot_dendrogram(d, k = 8, cex = 0.7, diff_method = "binary",

d <- filter(d, name != "rgbif",
name != "ibis.iSDM",
name != "dismo") |>
select(-mod_mechanistic,
-mod_multispecies)

pal <- RColorBrewer::brewer.pal(n = 5, name = "Dark2")

pdf("fig3.pdf", height = 5, width = 9.7)
plot_dendrogram(d, k = 5, cex = 0.7, diff_method = "binary",
k_colors = pal, horiz = TRUE, main = "")
dev.off()

clust <- plot_dendrogram(d, k = 5, cex = 1, diff_method = "binary",
k_colors = pal, horiz = TRUE, main = "",
return_clust = TRUE)
pkg_order <- rev(clust$labels[clust$order])

png("fig3.png", height = 480, width = 1100)
gridExtra::grid.arrange(f2a, f2b, nrow = 1, widths = c(10, 6))
dev.off() #nolint

pkg_cols <- pkg_order
names(pkg_cols) <- pkg_order
pkg_cols[1:4] <- pal[8]
pkg_cols[5] <- pal[7]
pkg_cols[6:7] <- pal[6]
pkg_cols[8:27] <- pal[5]
pkg_cols[28] <- pal[4]
pkg_cols[29:31] <- pal[3]
pkg_cols[32:34] <- pal[2]
pkg_cols[35] <- pal[1]

g <- plot_table(d,
pkg_order = pkg_order,
remove_empty_cats = TRUE)
ggplot2::ggsave("inst/img/pkgs.png", g, height = 10, width = 10)

pkg_cols[1:21] <- pal[5]
pkg_cols[22:26] <- pal[4]
pkg_cols[27:30] <- pal[3]
pkg_cols[31] <- pal[2]
pkg_cols[32:33] <- pal[1]

pdf("fig2.pdf", height = 7, width = 16)
plot_table(d,
pkg_order = pkg_order,
pkg_cols = pkg_cols,
remove_empty_cats = TRUE)
dev.off()

0 comments on commit 1566031

Please sign in to comment.