Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function fixes #124

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion R/extract_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,11 @@ extract_data <- function(database, table = NA, col, col_value) {
ret_tmp[["traits"]] <- database[["traits"]]%>%
dplyr::semi_join(cc_traits, by = columns_to_select)

columns_to_select_excluded <- intersect(setdiff(names(database$excluded_data), "value"), names(database[[table[[i]]]]))

# Use same filtering join to trim excluded data
ret_tmp[["excluded_data"]] <- database[["excluded_data"]] %>%
dplyr::semi_join(cc_traits, by = columns_to_select)
dplyr::semi_join(cc_traits, by = columns_to_select_excluded)


for (j in seq_along(tables_tmp$tables_to_cut)) {
Expand Down
37 changes: 27 additions & 10 deletions R/plot_trait_distribution_beeswarm.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
hide_ids = FALSE) {

# Check compatability
status <- check_compatibility(database)
status <- check_compatibility(database, single_table_allowed = TRUE)

# If compatible
if(!status) {
function_not_supported(database)
Expand All @@ -44,17 +44,27 @@
factor(p, levels=names(my_shapes))
}

tax_info <- database_trait$taxa %>% dplyr::select(taxon_name, family)
if (is.null(dim(database_trait))) {

tax_info <- database_trait$taxa %>% dplyr::select(taxon_name, family, genus)

data <-
database_trait$traits %>%
dplyr::left_join(by = "taxon_name", tax_info)

} else {

data <- database_trait

Check warning on line 57 in R/plot_trait_distribution_beeswarm.R

View check run for this annotation

Codecov / codecov/patch

R/plot_trait_distribution_beeswarm.R#L57

Added line #L57 was not covered by tests

data <-
database_trait$traits %>%
}

data <- data %>%
dplyr::mutate(shapes = as_shape(value_type)) %>%
dplyr::left_join(by = "taxon_name", tax_info) %>%
dplyr::mutate(value = as.numeric(value))

# Define grouping variables and derivatives
if(!y_axis_category %in% names(data)) {
stop("Incorrect grouping variable! Currently implemented for `family` or `dataset_id`")
stop("Incorrect grouping variable! Grouping variable must be a variable in or joined to the traits table. Family and genus are supported if your input is a complete traits.build database.")

Check warning on line 67 in R/plot_trait_distribution_beeswarm.R

View check run for this annotation

Codecov / codecov/patch

R/plot_trait_distribution_beeswarm.R#L67

Added line #L67 was not covered by tests
}

# define grouping variable, ordered by group-level by mean values
Expand All @@ -77,10 +87,17 @@
if(!is.na(highlight) & highlight %in% data$Group) {
data <- dplyr::mutate(data, colour = ifelse(Group %in% highlight, "c", colour))
}


vals <- list(minimum = purrr::pluck(database_trait, "definitions", trait_name, "allowed_values_min"),
maximum = purrr::pluck(database_trait, "definitions", trait_name, "allowed_values_max"))
if (is.null(dim(database))) {

vals <- list(minimum = purrr::pluck(database_trait, "definitions", trait_name, "allowed_values_min"),
maximum = purrr::pluck(database_trait, "definitions", trait_name, "allowed_values_max"))

} else {

vals <- list(minimum = 0.8*min(data$value),
maximum = 1.2*max(data$value))

Check warning on line 99 in R/plot_trait_distribution_beeswarm.R

View check run for this annotation

Codecov / codecov/patch

R/plot_trait_distribution_beeswarm.R#L98-L99

Added lines #L98 - L99 were not covered by tests
}

range <- (vals$maximum/vals$minimum)

Expand Down
Loading