Skip to content

Commit

Permalink
UGH i hate figures
Browse files Browse the repository at this point in the history
  • Loading branch information
diazrenata committed May 8, 2021
1 parent acc56ea commit 44fd44e
Show file tree
Hide file tree
Showing 110 changed files with 297 additions and 1,559 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ Breadth indices (top) and percentile scores (bottom) for communities with fewer

```{r, fig.dim = c(6,8)}
nhist <- plot_narrowness_hist(filter(all_di, dat %in% c("fia", "mcdb", "misc_abund")), "sim_pos_from_best", "Dissimilarity to the central tendency") +
nhist <- plot_narrowness_hist(filter(all_di, dat %in% c("fia", "mcdb", "misc_abund")), "sim_pos_from_best_95", "Dissimilarity to the central tendency") +
facet_wrap(vars(`Number of elements`, Dataset), scales = "free_y", nrow = 2, ncol = 3) +
xlab("Mean dissimilarity of elements of feasible set to central tendency") +
xlab("95th percentile of scores for dissimilarity to the central tendency \nfor elements of the feasible set") +
ylab("Number of communities") +
ggtitle("")
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ ggplot(all_di, aes(sim_pos_from_best, real_po, color = `Observed \npercentile sc
geom_point(data = filter(all_di, s0 < 0)) +
geom_abline(slope = 1, intercept = 0) +
scale_color_viridis_d(end = .8, direction = -1) +
xlab("Mean of elements from feasible set") +
xlab("Mean for elements from feasible set") +
ylab("Observed value") +
ggtitle("Dissimilarity to the central tendency") + theme(legend.position = "bottom")+
facet_wrap(vars(Dataset))
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ plot_narrowness_hist <- function(di_df, col_name, plot_name, facetvar = "Dataset
fig_2 <- gridExtra::grid.arrange(grobs = list(
plot_narrowness_hist(all_di, "sim_pos_from_best", "Dissimilarity to the \ncentral tendency", facetvar = "Dataset"),
plot_narrowness_hist(all_di, "sim_pos_from_best_95", "Dissimilarity to the \ncentral tendency", facetvar = "Dataset"),
plot_narrowness_hist(all_di, "nsingletons_95_ratio_2t", "\nNumber of rare species", facetvar = "Dataset"),
plot_narrowness_hist(all_di, "skew_95_ratio_2t", "\nSkewness", facetvar = "Dataset", min_s0 = 3),
plot_narrowness_hist(all_di, "simpson_95_ratio_2t", "\nSimpson evenness", facetvar = "Dataset"),
Expand All @@ -181,4 +181,4 @@ fig_2 <- gridExtra::grid.arrange(grobs = list(
```


**Figure S6**. Partially because of the uneven distribution of S and N among the different datasets, the narrowness of the feasible sets - defined either as the mean dissimilarity of samples from the feasible set to the central tendency of the feasible set, or using a breadth index for specific metrics - varies among different datasets. In particular, the FIA dataset, and subsets of the Mammal Community and Miscellaneous Abundance databases, often have highly variable, broadly-defined statistical baselines derived from the feasible set.
**Figure S6**. Partially because of the uneven distribution of S and N among the different datasets, the narrowness of the feasible sets - defined either as the 95th percentile of scores for the dissimilarity of samples from the feasible set to the central tendency of the feasible set, or using a breadth index for specific metrics - varies among different datasets. In particular, the FIA dataset, and subsets of the Mammal Community and Miscellaneous Abundance databases, often have highly variable, broadly-defined statistical baselines derived from the feasible set.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ bind_rows(simpson_perc_ks, skew_perc_ks, shannon_perc_ks, nsingletons_perc_ks, d
```{r, fig.dim = c(8,4)}
fig_2 <- gridExtra::grid.arrange(grobs = list(
plot_narrowness_hist(sub_di, "sim_pos_from_best", "Dissimilarity to the \ncentral tendency", facetvar = "Dataset"),
plot_narrowness_hist(sub_di, "sim_pos_from_best_95", "Dissimilarity to the \ncentral tendency", facetvar = "Dataset"),
plot_narrowness_hist(sub_di, "nsingletons_95_ratio_2t", "\nNumber of rare species", facetvar = "Dataset"),
plot_narrowness_hist(sub_di, "skew_95_ratio_2t", "\nSkewness", facetvar = "Dataset", min_s0 = 3),
plot_narrowness_hist(sub_di, "simpson_95_ratio_2t", "\nSimpson evenness", facetvar = "Dataset"),
Expand All @@ -424,7 +424,7 @@ simpson_rat_ks <- ks_compare(fia_di, other_di, "simpson_95_ratio_2t")
skew_rat_ks <- ks_compare(fia_di, other_di, "skew_95_ratio_2t")
shannon_rat_ks <- ks_compare(fia_di, other_di, "shannon_95_ratio_2t")
nsingletons_rat_ks <- ks_compare(fia_di, other_di, "nsingletons_95_ratio_2t")
diss_rat_ks <- ks_compare(fia_di, other_di, "sim_pos_from_best")
diss_rat_ks <- ks_compare(fia_di, other_di, "sim_pos_from_best_95")
bind_rows(simpson_rat_ks, skew_rat_ks, shannon_rat_ks, nsingletons_rat_ks, diss_rat_ks) %>%
select(var, d, p) %>%
Expand Down
Binary file not shown.
Binary file added analysis/reports/finaledit/figure_1.pdf
Binary file not shown.
Binary file added analysis/reports/finaledit/figure_2.pdf
Binary file not shown.
Binary file not shown.
Binary file added analysis/reports/finaledit/figure_3.pdf
Binary file not shown.
Binary file added analysis/reports/finaledit/figure_4.pdf
Binary file not shown.
Binary file added analysis/reports/finaledit/figure_5.pdf
Binary file not shown.
Binary file added analysis/reports/finaledit/figure_6.pdf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,12 @@ fig1 <- ggplot(all_di, aes(x = s0, y = n0, color = Dataset)) +
xlab("Species richness (S); note log scale") +
ylab("Total abundance (N); note log scale") +
scale_x_log10() +
scale_y_log10()
scale_y_log10() +
theme(legend.position = c(.3,.8), legend.justification = "center", legend.background = element_blank(), legend.text = element_text(size = 8), legend.title = element_text(size = 9), legend.key.size = unit(2, units = "mm"), axis.text = element_text(size = 7))
fig1_with_top = gridExtra::grid.arrange(grobs = list(fig1),
top = textGrob("Figure 1"))
#
# pdf("figure_1.pdf", bg = "white", paper = "letter", width = 6.5, height = 6.5)
# gridExtra::grid.arrange(grobs = list(fig1),
# top = textGrob("Figure 1"))
# dev.off()
ggsave("figure_1.pdf", plot = fig1_with_top, device = "pdf", width = 6.5, height = 6.5, units = "in")
ggsave("figure_1.pdf", plot = fig1, device = "pdf", width = 80, height = 80, units = "mm")
```
Expand Down Expand Up @@ -196,13 +189,13 @@ breadth_plots <- list(
)
fig_2 <- gridExtra::grid.arrange(grobs = breadth_plots, ncol = 2, top = textGrob("Figure 2", gp = gpar(fill = "white")))
ggsave("figure_2.pdf", plot = fig_2, device = "pdf", width = 8, height = 8, units = "in")
fig_2 <- gridExtra::grid.arrange(grobs = breadth_plots, ncol = 2)
signif(as.numeric(example_di$nparts), digits = 2)
(as.numeric(example_di2$nparts))
as.numeric(example_di3$nparts)
ggsave("figure_2.pdf", plot = fig_2, device = "pdf", width = 180, height = 180, dpi = 800, units = "mm")
#
signif(as.numeric(example_di$nparts), digits = 2)[1]
(as.numeric(example_di2$nparts))[1]
as.numeric(example_di3$nparts)[1]
DBI::dbDisconnect(db)
rm(cache)
Expand All @@ -228,14 +221,16 @@ plot_percentile_hist <- function(di_df, col_name, plot_name, tails = 2, facetvar
ggplot(filter(di_df, nparts > min_nparts, s0 >= min_s0), aes(response)) +
geom_histogram(bins = 40, boundary = 100) +
geom_histogram(bins = 100, boundary = 100) +
theme_bw() +
xlab("") +
ylab("") +
geom_vline(xintercept = cutoff_percentiles, color = "red") +
ggtitle( plot_name) +
#geom_text(data = distinct(select(di_df, Dataset)), aes(x = 45, y = 100, label = Dataset)) +
facet_wrap(vars(facetvar), ncol = 1, scales = "free_y")+
theme(plot.title = element_text(size=10))
theme(plot.title = element_text(size=9), plot.margin=unit(c(1, 0, -5, -3), units = "mm"), axis.text = element_text(size = 6), strip.text = element_text(size = 7), strip.placement = "inside") +
scale_y_continuous(n.breaks = 3)
Expand All @@ -256,25 +251,20 @@ all_di <- all_di %>%
fig_3 <- gridExtra::grid.arrange(grobs = list(
plot_percentile_hist(all_di, "real_po_percentile_mean", "Dissimilarity to the \ncentral tendency", facetvar = "Dataset", tails = 1),
plot_percentile_hist(all_di, "nsingletons_percentile_mean", "\nProportion of rare species", facetvar = "Dataset"),
plot_percentile_hist(all_di, "skew_percentile_mean", "\nSkewness", facetvar = "Dataset", min_s0 = 3),
plot_percentile_hist(all_di, "simpson_percentile_mean", "\nSimpson evenness", facetvar = "Dataset"),
plot_percentile_hist(all_di, "shannon_percentile_mean", "\nShannon diversity", facetvar = "Dataset")
), ncol = 3,
top = textGrob("Figure 3", gp = gpar(fill = "white")), left = textGrob("Number of communities", rot = 90, gp = gpar(fill = "black")),
bottom = textGrob("Percentile rank of observed value relative to feasible set"), gp = gpar(fill = "white"))
plot_percentile_hist(all_di, "real_po_percentile_mean", "Dissimilarity", facetvar = "Dataset", tails = 1),
plot_percentile_hist(all_di, "nsingletons_percentile_mean", "Proportion of rare species", facetvar = "Dataset"),
plot_percentile_hist(all_di, "skew_percentile_mean", "Skewness", facetvar = "Dataset", min_s0 = 3) + theme(plot.margin = unit(c(1, 2, -5, -5), units = "mm")),
plot_percentile_hist(all_di, "simpson_percentile_mean", "Simpson evenness", facetvar = "Dataset"),
plot_percentile_hist(all_di, "shannon_percentile_mean", "Shannon diversity", facetvar = "Dataset")
), ncol = 3,
left = textGrob("Number of communities", rot = 90, gp = gpar(fill = "black")),
bottom = textGrob("Percentile rank of observed value relative to feasible set"),
gp = gpar(fill = "white"))
#
#
# pdf("figure_3.pdf", bg = "white", paper = "letter", width = 8, height = 4)
# gridExtra::grid.arrange(grobs = list(fig_3),
# top = textGrob("Figure 3"))
# dev.off()
fig_3
ggsave("figure_3.pdf", plot = fig_3, device = "pdf", width = 8, height = 8, units = "in")
ggsave("figure_3.pdf", plot = fig_3, device = "pdf", width = 180, height = 180, dpi = 800, units = "mm")
```

Expand Down Expand Up @@ -366,7 +356,8 @@ plot_narrowness <- function(di_df, yvar, yvar_name) {
scale_x_log10() +
ggtitle(yvar_name) +
theme(legend.position = "none")+
theme(plot.title = element_text(size=10))
theme(plot.title = element_text(size=10)) +
theme(legend.text = element_text(size = 7), plot.margin = unit(c(0, 10, 0, 0), units = "mm"), axis.text = element_text(size = 7))
}
plot_narrowness_legend <- function(di_df) {
Expand All @@ -377,7 +368,7 @@ plot_narrowness_legend <- function(di_df) {
mutate(ymark = dplyr::row_number())
ggplot(legend_df, aes(1, ymark, color = Dataset)) +
geom_label(aes(x = 2, y = ymark, label = Dataset)) +
geom_text(aes(x = 2, y = ymark, label = Dataset)) +
geom_point(size = 4) +
scale_color_viridis_d(end = .9) +
xlab("") +
Expand All @@ -402,25 +393,32 @@ plot_narrowness_legend <- function(di_df) {
```{r f4, fig.dim = c(7,4)}
#
# fig_4 <- gridExtra::grid.arrange(grobs = list(
# plot_narrowness(all_di, "sim_pos_from_best_95", "Dissimilarity \nto central tendency") + ylab("Dissimilarity \n95th percentile") + theme(legend.position = "bottom", legend.direction = "vertical" , legend.margin = margin(b = 40, r = 0, t = 10, l = 0, unit = "mm")),
# gridExtra::grid.arrange(grobs = list(
# plot_narrowness(all_di, "skew_95_ratio_2t", "\nSkewness"),
# plot_narrowness(all_di, "simpson_95_ratio_2t", "\nSimpson evenness")+ ylab(""),
# plot_narrowness(all_di, "nsingletons_95_ratio_2t", "\nProportion of rare species"),
# plot_narrowness(all_di, "shannon_95_ratio_2t", "\nShannon diversity") + ylab("")
# ), ncol = 2)), ncol = 2, widths = c( 2, 4),bottom = textGrob("Number of elements in the feasible set"))
fig_4 <- gridExtra::grid.arrange(grobs = list(
plot_narrowness(all_di, "sim_pos_from_best", "Dissimilarity \nto central tendency") + ylab("Mean dissimilarity") + theme(legend.position = "bottom", legend.direction = "vertical" , legend.margin = margin(b = .25, r = 0, t = 0, l = 0, unit = "in")),
gridExtra::grid.arrange(grobs = list(
plot_narrowness(all_di, "skew_95_ratio_2t", "\nSkewness"),
plot_narrowness(all_di, "simpson_95_ratio_2t", "\nSimpson evenness")+ ylab(""),
plot_narrowness(all_di, "nsingletons_95_ratio_2t", "\nProportion of rare species"),
plot_narrowness(all_di, "shannon_95_ratio_2t", "\nShannon diversity") + ylab("")
), ncol = 2)), ncol = 2, widths = c( 2, 4), bottom = textGrob("Number of elements in the feasible set"), top = textGrob("Figure 4"))
plot_narrowness(all_di, "sim_pos_from_best_95", "Dissimilarity") + ylab("Dissimilarity \n95th percentile") + theme(legend.position = c(.65, .8), legend.justification = "center", legend.direction = "horizontal", legend.background = element_blank(), legend.key = element_blank(), legend.key.size = unit(.25, units = "mm"), legend.title = element_text(size =7)),
plot_narrowness(all_di, "skew_95_ratio_2t", "Skewness") + ylab("\nBreadth index"),
plot_narrowness(all_di, "simpson_95_ratio_2t", "Simpson evenness")+ ylab("\nBreadth index"),
plot_narrowness(all_di, "nsingletons_95_ratio_2t", "Proportion of rare species")+ ylab("\nBreadth index"),
plot_narrowness(all_di, "shannon_95_ratio_2t", "Shannon diversity")+ ylab("\nBreadth index")), ncol = 1, bottom = textGrob("Number of elements in the feasible set"))
fig_4
#fig_4
#
# pdf("figure_4.pdf", bg = "white", paper = "letter", width = 8, height = 5)
# fig_4
# dev.set(dev.next())
# while (!is.null(dev.list())) dev.off()
ggsave("figure_4.pdf", plot = fig_4, device = "pdf", width = 8, height = 5, units = "in")
ggsave("figure_4.pdf", plot = fig_4, device = "pdf", width = 180, height = 180, dpi = 800, units = "mm")
```

```{r}
Expand Down Expand Up @@ -517,19 +515,20 @@ nhist <- plot_narrowness_hist(filter(all_di, dat %in% c("fia", "mcdb", "misc_abu
facet_wrap(vars(`Number of elements`, Dataset), scales = "free_y", nrow = 2, ncol = 3) +
xlab("Breadth index") +
ylab("Number of communities") +
ggtitle("Skewness")
ggtitle("Skewness") + theme(plot.margin = unit(c(5,5,5,5), units = "mm"))
phist <- plot_percentile_hist(filter(all_di, dat %in% c("fia", "mcdb", "misc_abund")), "skew_percentile_mean", "Skewness") +
facet_wrap(vars(`Number of elements`, Dataset), scales = "free_y", nrow = 2, ncol = 3) +
xlab("Percentile rank of observed value relative to feasible set") +
ylab("Number of communities") +
ggtitle("Skewness")
ggtitle("Skewness")+ theme(plot.margin = unit(c(5,5,5,5), units = "mm"))
fig_6 <- gridExtra::grid.arrange(grobs = list(nhist, phist), nrow = 2, top = textGrob("Figure 6"))
fig_6 <- gridExtra::grid.arrange(grobs = list(nhist, phist), nrow = 2)
fig_6
ggsave("figure_6.pdf", plot = fig_6, device = "pdf", width = 6, height = 8, units = "in")
ggsave("figure_6.pdf", plot = fig_6, device = "pdf", width = 180, height = 180, dpi = 800, units = "mm")
```

Expand Down Expand Up @@ -697,29 +696,38 @@ rs_results_long <- left_join(rs_results_long, metric_names)
# scale_color_viridis_d(end = .8) +
# ylab("Proportion of extreme observed values") +
# xlab("")
#
# fig_5 <- gridExtra::grid.arrange(grobs = list(
# ggplot(filter(rs_results_long, !grepl("Misc", Dataset), !weird_dir), aes(metric_desc, value, color = `Resampling scheme`)) +
# geom_point() +
# facet_wrap(vars(Dataset), scales = "fixed", ncol =2) +
# geom_point(aes(y = percentile_cutoff), shape = 95, color = "black", size = 10) +
# scale_color_viridis_d(end = .8, option = "plasma") +
# ylab("Proportion of extreme observed values") +ylim(0, .7) +
# xlab("") + theme(legend.position = "none", axis.text.x = element_text(angle = 90)) ,
# ggplot(filter(rs_results_long, grepl("Misc", Dataset), !weird_dir), aes(metric_desc, value, color = `Resampling scheme`)) +
# geom_point() +
# facet_wrap(vars(Dataset), scales = "fixed", ncol = 2) +
# geom_point(aes(y = percentile_cutoff), shape = 95, color = "black", size = 10) +
# scale_color_viridis_d(end = .8, option = "plasma") +
# ylab("") +
# xlab("") + ylim(0, .7) +
# theme(legend.position = "bottom", legend.direction = "vertical" , legend.margin = margin(b = .3, r = 0, t = 0, l = 0, unit = "in"), axis.text.x = element_text(angle = 90))), ncol = 2, widths = c( 4,2), bottom = textGrob("Metric"), top = textGrob("Figure 5"))
fig_5 <- gridExtra::grid.arrange(grobs = list(
ggplot(filter(rs_results_long, !grepl("Misc", Dataset), !weird_dir), aes(metric_desc, value, color = `Resampling scheme`)) +
ggplot(filter(rs_results_long, !weird_dir), aes(metric_desc, value, color = `Resampling scheme`)) +
geom_point() +
facet_wrap(vars(Dataset), scales = "fixed", ncol =2) +
facet_wrap(vars(Dataset), scales = "fixed", ncol =5) +
geom_point(aes(y = percentile_cutoff), shape = 95, color = "black", size = 10) +
scale_color_viridis_d(end = .8) +
scale_color_viridis_d(end = .8, option = "plasma") +
ylab("Proportion of extreme observed values") +ylim(0, .7) +
xlab("") + theme(legend.position = "none", axis.text.x = element_text(angle = 90)) ,
ggplot(filter(rs_results_long, grepl("Misc", Dataset), !weird_dir), aes(metric_desc, value, color = `Resampling scheme`)) +
geom_point() +
facet_wrap(vars(Dataset), scales = "fixed", ncol = 2) +
geom_point(aes(y = percentile_cutoff), shape = 95, color = "black", size = 10) +
scale_color_viridis_d(end = .8) +
ylab("") +
xlab("") + ylim(0, .7) +
theme(legend.position = "bottom", legend.direction = "vertical" , legend.margin = margin(b = .3, r = 0, t = 0, l = 0, unit = "in"), axis.text.x = element_text(angle = 90))), ncol = 2, widths = c( 4,2), bottom = textGrob("Metric"), top = textGrob("Figure 5"))
xlab("Metric") + theme(legend.position = "bottom", axis.text.x = element_text(angle = 90), plot.margin = unit(c(60, 0, 0, 0), units = "mm"))))
#fig_5
ggsave("figure_5.pdf", device = "pdf", plot = fig_5, width = 6, height = 5, units = "in")
ggsave("figure_5.pdf", device = "pdf", plot = fig_5, width = 180, height =
180, dpi = 800, units = "mm")
#
# pdf("figure_5.pdf", bg = "white", paper = "letter", width = 6, height = 5)
# fig_5
Expand Down
Loading

0 comments on commit 44fd44e

Please sign in to comment.