plot_upset_fishtissue: Plot Fish Study Upset

View source: R/plot_upset_fishtissue.R

plot_upset_fishtissueR Documentation

Plot Fish Study Upset

Description

Upset plot for fish study projects

Usage

plot_upset_fishtissue(
  df_data,
  intersect = names(df_data)[-1],
  title_str = NA,
  title_custloc = FALSE,
  title_x = 0.2,
  title_y = 0.9,
  title_fontsize = 16,
  cap_str = NA,
  cap_custloc = FALSE,
  cap_x = 0.5,
  cap_y = 0.025,
  cap_fontsize = 8,
  ...
)

Arguments

intersect

Columns to be used to compose the intersection. Default = names(data)[-1]

title_str

Title string. Default = NA

title_custloc

Use a custom location for the title? Default = FALSE

title_x

Title x placement. Default = 0.2

title_y

Title y placement. Default = 0.9

title_fontsize

Title font size. Default = 16

cap_str

Caption string. Default = NA

cap_custloc

Use a custom location for the caption? Default = FALSE

cap_x

Caption x placement. Default = 0.5

cap_y

Caption y placement. Default = 0.025

cap_fontsize

Caption font size. Default = 8

...

Arguments to be passed on to ComplexUpset::upset

data

Data as data frame (variables are 1 or 0 as columns).

Details

Upset plot using the 'ComplexUpset' package.

Upset plots show co-occurrence of different variables. The left side sizes plot is turned on by default. This creates extra area in the upper left that can be used for an alternative location for the plot title. The function is set up to use the basic title as default but has input parameters to change the location (e.g., upper left).

A ggplot object is returned that the user can further modify and save. #' # 2023-07-20, moved code to package scripts. Derived for Great Lakes studies.

Value

A ggplot object is returned.

Examples

# Data
df_data <- data_gl2010_upset

# Parameters ----
namedata <- "Great Lakes, 2010"
fishconsumer <- "general"
sv_hg <- 300
sv_pfas <- 0.52
sv_pcb <- 12

# Plot Parts ----
title_str <- paste0(namedata
                    , "\n(n = ", nrow(df_data), ")"
                    , "\nExceeds Screening Value")
cap_str <- paste0("Screening Values for "
                  , fishconsumer
                  , " fish consumer; "
                  , "Mercury = "
                  , sv_hg
                  , ", "
                  , "PFAS = "
                  , sv_pfas
                  , ", "
                  , "Total PCBs = "
                  , sv_pcb
                  )

# Plot, title and caption, base location ----
p1 <- plot_upset_fishtissue(df_data = df_data
                           , title_str = title_str
                           , cap_str = cap_str)
p1

# Plot, title and caption, custom location ----
p2 <- plot_upset_fishtissue(df_data = df_data
                           , title_str = title_str
                           , title_custloc = TRUE
                           , title_x = 0.16
                           , title_y = 0.90
                           , title_fontsize = 16
                           , cap_str = cap_str
                           , cap_custloc = TRUE
                           , cap_x = 0.5
                           , cap_y = 0.025
                           , cap_fontsize = 8)
p2


leppott/ProjectTasks documentation built on Oct. 12, 2023, 1:18 a.m.