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

Refactored function names in R/plotme.R #68

Merged
merged 4 commits into from
Oct 8, 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
10 changes: 5 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export(add_name)
export(add_tax)
export(advanced_opts2est_walltime)
export(alignFasta)
export(assert_count_df)
export(assign_job_queue)
export(cleanClusters)
export(cleanDomainArchitecture)
Expand All @@ -35,14 +34,10 @@ export(convertAlignment2Trees)
export(convertFA2Tree)
export(convert_aln2fa)
export(count_bycol)
export(count_to_sunburst)
export(count_to_treemap)
export(createFA2Tree)
export(createWordCloud2Element)
export(createWordCloudElement)
export(create_all_col_params)
export(create_lineage_lookup)
export(create_one_col_params)
export(domain_network)
export(efetchIPG)
export(extractAccNum)
Expand Down Expand Up @@ -74,8 +69,12 @@ export(plotLineageNeighbors)
export(plotLineageQuery)
export(plotLineageSunburst)
export(plotStackedLineage)
export(plotSunburst)
export(plotTreemap)
export(plotUpSet)
export(plot_estimated_walltimes)
export(prepareColumnParams)
export(prepareSingleColumnParams)
export(prot2tax)
export(prot2tax_old)
export(removeAsterisks)
Expand All @@ -101,6 +100,7 @@ export(summarize_bylin)
export(theme_genes2)
export(to_titlecase)
export(total_counts)
export(validateCountDF)
export(wordcloud3)
export(write.MsaAAMultipleAlignment)
export(write_proc_medians_table)
Expand Down
42 changes: 21 additions & 21 deletions R/plotme.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#' @description
#' These functions help you quickly create interactive hierarchical plots
#' from categorical data. They expect the summary of the data created by
#' `dplyr::count()` and produce either a sunburst plot (`count_to_sunburst()`) or
#' a treemap plot (`count_to_treemap()`)
#' `dplyr::count()` and produce either a sunburst plot (`plotSunburst()`) or
#' a treemap plot (`plotTreemap()`)
#'
#' @param count_data An output of dplyr::count(), tibble or data frame
#' @param fill_by_n If TRUE, uses a continuous scale to fill plot by group size
Expand All @@ -20,21 +20,21 @@
#' starwars_count <- count(starwars, species, eye_color, name)
#'
#' # sunburst plot
#' count_to_sunburst(starwars_count)
#' plotSunburst(starwars_count)
#'
#' # fill by group size
#' count_to_sunburst(starwars_count, fill_by_n = TRUE)
#' plotSunburst(starwars_count, fill_by_n = TRUE)
#'
#' # treemap plot, ordered by group size
#' count_to_treemap(starwars_count, sort_by_n = TRUE)
#' plotTreemap(starwars_count, sort_by_n = TRUE)
#'
#' # display al charchaters by homeworld
#' starwars %>%
#' count(homeworld, name) %>%
#' count_to_treemap(sort_by_n = TRUE)
#' plotTreemap(sort_by_n = TRUE)
#'
count_to_sunburst <- function(count_data, fill_by_n = FALSE, sort_by_n = FALSE, maxdepth = 2) {
params <- create_all_col_params(count_data, fill_by_n, sort_by_n)
plotSunburst <- function(count_data, fill_by_n = FALSE, sort_by_n = FALSE, maxdepth = 2) {
params <- prepareColumnParams(count_data, fill_by_n, sort_by_n)

purrr::exec(plotly::plot_ly,
!!!params,
Expand All @@ -53,9 +53,9 @@ count_to_sunburst <- function(count_data, fill_by_n = FALSE, sort_by_n = FALSE,
#' @importFrom purrr exec
#'
#' @export
#' @rdname count_to_sunburst
count_to_treemap <- function(count_data, fill_by_n = FALSE, sort_by_n = FALSE) {
params <- create_all_col_params(count_data, fill_by_n, sort_by_n)
#' @rdname plotSunburst
plotTreemap <- function(count_data, fill_by_n = FALSE, sort_by_n = FALSE) {
params <- prepareColumnParams(count_data, fill_by_n, sort_by_n)

purrr::exec(plotly::plot_ly,
!!!params,
Expand All @@ -66,7 +66,7 @@ count_to_treemap <- function(count_data, fill_by_n = FALSE, sort_by_n = FALSE) {
}


#' create_all_col_params
#' prepareColumnParams
#'
#' @param count_data
#' @param fill_by_n
Expand All @@ -80,8 +80,8 @@ count_to_treemap <- function(count_data, fill_by_n = FALSE, sort_by_n = FALSE) {
#' @export
#'
#' @examples
create_all_col_params <- function(count_data, fill_by_n, sort_by_n) {
assert_count_df(count_data)
prepareColumnParams <- function(count_data, fill_by_n, sort_by_n) {
validateCountDF(count_data)
assertthat::assert_that(is.logical(fill_by_n),
length(fill_by_n) == 1,
msg = "fill_by_n must be either TRUE or FALSE"
Expand All @@ -91,12 +91,12 @@ create_all_col_params <- function(count_data, fill_by_n, sort_by_n) {
msg = "sort_by_n must be either TRUE or FALSE"
)

count_data <- all_non_n_cols_to_char(count_data)
count_data <- .all_non_n_cols_to_char(count_data)

category_num <- ncol(count_data) - 1

params <- purrr::map(1:category_num,
create_one_col_params,
prepareSingleColumnParams,
df = count_data,
root = ""
) %>%
Expand All @@ -114,7 +114,7 @@ create_all_col_params <- function(count_data, fill_by_n, sort_by_n) {
params
}

#' create_one_col_params
#' prepareSingleColumnParams
#'
#' @param df
#' @param col_num
Expand All @@ -127,7 +127,7 @@ create_all_col_params <- function(count_data, fill_by_n, sort_by_n) {
#' @export
#'
#' @examples
create_one_col_params <- function(df,
prepareSingleColumnParams <- function(df,
col_num,
root) {
col_name <- names(df)[col_num]
Expand Down Expand Up @@ -156,7 +156,7 @@ create_one_col_params <- function(df,
) %>%
dplyr::select(ids, parents, labels, values, hovertext)
}
#' assert_count_df
#' validateCountDF
#'
#' @param var
#'
Expand All @@ -167,7 +167,7 @@ create_one_col_params <- function(df,
#' @export
#'
#' @examples
assert_count_df <- function(var) {
validateCountDF <- function(var) {
msg <- paste(substitute(var), "must be a count dataframe (output of dplyr::count)")
assertthat::assert_that(is.data.frame(var),
assertthat::has_name(var, "n"),
Expand All @@ -178,7 +178,7 @@ assert_count_df <- function(var) {
assertthat::assert_that(is.numeric(n_col), msg = msg)
}

all_non_n_cols_to_char <- function(df) {
.all_non_n_cols_to_char <- function(df) {
df %>%
dplyr::mutate(dplyr::across(!matches("^n$"), as.character))
}
14 changes: 0 additions & 14 deletions man/create_all_col_params.Rd

This file was deleted.

14 changes: 0 additions & 14 deletions man/create_one_col_params.Rd

This file was deleted.

29 changes: 12 additions & 17 deletions man/count_to_sunburst.Rd → man/plotSunburst.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/prepareColumnParams.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/prepareSingleColumnParams.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions man/assert_count_df.Rd → man/validateCountDF.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading