Skip to content

Commit

Permalink
ggcorrmat legend changed to account for NAs; CRAN resubmission 0.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil committed Sep 30, 2018
1 parent 9772657 commit cb87614
Show file tree
Hide file tree
Showing 49 changed files with 595 additions and 141 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
^Meta$
^doc$
^.*\.Rproj$
^\.Rproj\.user$
^README\.Rmd$
Expand Down
12 changes: 2 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,49 +1,41 @@
Meta
doc
# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# =========================

# Operating System Files

# OSX
.DS_Store
.AppleDouble
.LSOverride

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# R Studio files
.Rproj.user
.Rhistory
Expand Down
4 changes: 2 additions & 2 deletions CRAN-RELEASE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
This package was submitted to CRAN on 2018-09-26.
Once it is accepted, delete this file and tag the release (commit e50fcf3def).
This package was submitted to CRAN on 2018-09-30.
Once it is accepted, delete this file and tag the release (commit 9772657f8b).
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ importFrom(dplyr,mutate_at)
importFrom(dplyr,mutate_if)
importFrom(dplyr,n)
importFrom(dplyr,select)
importFrom(dplyr,select_if)
importFrom(dplyr,summarize)
importFrom(dplyr,vars)
importFrom(effsize,cohen.d)
Expand All @@ -91,7 +92,9 @@ importFrom(paletteer,scale_fill_paletteer_d)
importFrom(psych,cohen.d.ci)
importFrom(psych,corr.p)
importFrom(psych,corr.test)
importFrom(purrr,flatten_dbl)
importFrom(purrr,is_bare_double)
importFrom(purrr,is_bare_numeric)
importFrom(purrr,map)
importFrom(purrr,map_dfr)
importFrom(purrr,set_names)
Expand All @@ -111,6 +114,7 @@ importFrom(stats,cor)
importFrom(stats,cor.test)
importFrom(stats,kruskal.test)
importFrom(stats,lm)
importFrom(stats,median)
importFrom(stats,na.omit)
importFrom(stats,oneway.test)
importFrom(stats,qt)
Expand All @@ -120,6 +124,7 @@ importFrom(stats,shapiro.test)
importFrom(stats,t.test)
importFrom(stats,var.test)
importFrom(stats,wilcox.test)
importFrom(tibble,as.tibble)
importFrom(tibble,as_data_frame)
importFrom(tibble,rowid_to_column)
importFrom(tibble,rownames_to_column)
Expand Down
6 changes: 3 additions & 3 deletions R/ggbetweenstats.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@
#' \url{https://cran.r-project.org/package=ggstatsplot/vignettes/ggbetweenstats.html}
#'
#' @examples
#'
#'
#' # to get reproducible results from bootstrapping
#' set.seed(123)
#'
#'
#' # simple function call with the defaults
#' ggstatsplot::ggbetweenstats(
#' data = mtcars,
Expand All @@ -157,7 +157,7 @@
#' caption = "Transmission (0 = automatic, 1 = manual)",
#' bf.message = TRUE
#' )
#'
#'
#' # more detailed function call
#' ggstatsplot::ggbetweenstats(
#' data = datasets::morley,
Expand Down
87 changes: 82 additions & 5 deletions R/ggcorrmat.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#' `"plot"` (for visualization matrix) or `"correlations"` (or `"corr"` or
#' `"r"`; for correlation matrix) or `"p-values"` (or `"p.values"` or `"p"`;
#' for a matrix of *p*-values) or `"ci"` (for a tibble with confidence
#' intervals for unique correlation pairs; not available for robust correlation).
#' intervals for unique correlation pairs; not available for robust
#' correlation) or `"n"` (or `"sample.size"` for a tibble with sample sizes
#' for each correlation pair).
#' @param matrix.type Character, `"full"` (default), `"upper"` or `"lower"`, display
#' full matrix, lower triangular or upper triangular matrix.
#' @param method Character argument that decides the visualization method of
Expand Down Expand Up @@ -118,6 +120,7 @@
#' @importFrom WRS2 pball
#' @importFrom psych corr.test
#' @importFrom psych corr.p
#' @importFrom purrr flatten_dbl
#'
#' @seealso \code{\link{grouped_ggcorrmat}} \code{\link{ggscatterstats}}
#' \code{\link{grouped_ggscatterstats}}
Expand Down Expand Up @@ -224,6 +227,12 @@ ggcorrmat <-
df <- data %>%
dplyr::select(.data = ., !!rlang::enquo(cor.vars))

# counting number of NAs present in the dataframe
na_total <- df %>%
purrr::map_df(.x = ., .f = ~sum(is.na(.))) %>%
purrr::flatten_dbl(.x = .) %>%
sum(., na.rm = TRUE)

# renaming the columns if so desired (must be equal to the number of number of cor.vars)
if (!is.null(cor.vars.names)) {
# check if number of cor.vars is equal to the number of names entered
Expand Down Expand Up @@ -278,6 +287,13 @@ ggcorrmat <-

# compute a correlation matrix of p-values
p.mat <- corr_df$p

# in case of NAs, compute minimum and maximum sample sizes of pairs
if (na_total != 0) {

# dataframe with minimum, median, and maximum sample sizes
n_summary <- numdf_n_summary(df = corr_df$n)
}
} else if (corr.method == "robust") {

# this is just get a matrix of samples sizes to be used `n` argument in
Expand All @@ -291,6 +307,14 @@ ggcorrmat <-
ci = FALSE
)

# in case of NAs, compute minimum, median, and maximum sample sizes of
# pairs
if (na_total != 0) {

# dataframe with minimum, median, and maximum sample sizes
n_summary <- numdf_n_summary(df = n_df$n)
}

# computing the percentage bend correlation matrix
rob_cor <- WRS2::pball(x = df, beta = beta)

Expand Down Expand Up @@ -331,6 +355,41 @@ ggcorrmat <-
# creating the basic plot
if (output == "plot") {
if (corr.method %in% c("pearson", "spearman", "kendall", "robust")) {

# legend title with information about correlation type and sample
if (na_total == 0) {
legend.title.text <-
bquote(atop(
atop(
bold("sample size:"),
italic(n) ~ "=" ~ .(nrow(x = data))
),
atop(
bold("correlation:"),
.(corr.method)
)
))
} else {
legend.title.text <-
bquote(atop(
atop(
atop(
bold("sample size:"),
italic(n)[min] ~ "=" ~ .(n_summary$n_min[[1]])
),
atop(
italic(n)[median] ~ "=" ~ .(n_summary$n_median[[1]]),
italic(n)[max] ~ "=" ~ .(n_summary$n_max[[1]])
)
),
atop(
bold("correlation:"),
.(corr.method)
)
))
}


# plotting the correlalogram
plot <- ggcorrplot::ggcorrplot(
corr = corr.mat,
Expand All @@ -344,7 +403,7 @@ ggcorrmat <-
outline.color = outline.color,
ggtheme = ggtheme,
colors = colors,
legend.title = paste("n = ", nrow(x = data), "\n", corr.method, sep = ""),
legend.title = legend.title.text,
lab_col = lab.col,
lab_size = lab.size,
insig = insig,
Expand Down Expand Up @@ -460,14 +519,32 @@ ggcorrmat <-

# return the tibble
return(corr.mat)
} else if (output %in% c("n", "sample.size")) {
if (corr.method %in% c("pearson", "spearman", "kendall")) {
# sample size matrix
sample_size_df <- corr_df$n %>%
base::as.data.frame(x = .) %>%
tibble::rownames_to_column(., var = "variable") %>%
tibble::as_data_frame(x = .)

return(sample_size_df)
} else {
# sample size matrix
sample_size_df <- n_df$n %>%
base::as.data.frame(x = .) %>%
tibble::rownames_to_column(., var = "variable") %>%
tibble::as_data_frame(x = .)

return(sample_size_df)
}
} else if (output %in% c("p-values", "p.values", "p")) {

# if p-values were adjusted, notify how they are going to be displayed
if (p.adjust.method != "none") {
base::message(cat(
crayon::green("Note: "),
crayon::blue(
"In the correlation matrix, the upper triangle denotes p-values adjusted for multiple comparisons, while the lower triangle denotes unadjusted p-values.\n"
"In the correlation matrix, the upper triangle denotes p-values adjusted for multiple comparisons,\nwhile the lower triangle denotes unadjusted p-values.\n"
),
sep = ""
))
Expand Down Expand Up @@ -500,7 +577,7 @@ ggcorrmat <-
base::message(cat(
crayon::red("Warning: "),
crayon::blue(
"Confidence intervals for correlations are currently not available for robust correlation.\n"
"Confidence intervals are currently not available for robust correlations.\n"
),
sep = ""
))
Expand All @@ -512,7 +589,7 @@ ggcorrmat <-
base::message(cat(
crayon::green("Note: "),
crayon::blue(
"In the correlation matrix, the upper triangle is based on p-values adjusted for multiple comparisons, while the lower triangle is based on unadjusted p-values.\n"
"In the correlation matrix, the upper triangle is based on p-values adjusted for multiple comparisons,\nwhile the lower triangle is based on unadjusted p-values.\n"
),
sep = ""
))
Expand Down
Loading

0 comments on commit cb87614

Please sign in to comment.