Skip to content

Commit

Permalink
Merge pull request #43 from ibecav/master
Browse files Browse the repository at this point in the history
Suggested improvement to Histograms (grouped and non grouped)
  • Loading branch information
IndrajeetPatil committed Sep 14, 2018
2 parents e0b99ff + f4f31b7 commit 38eee48
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 38 deletions.
9 changes: 4 additions & 5 deletions R/combine_plots.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#'
#' @title Combining multiple plots using `cowplot::plot_grid()` with a
#' combination of title, caption, and annotation label
#' @name combine_plots
Expand Down Expand Up @@ -65,10 +64,10 @@
#' \url{https://cran.r-project.org/package=ggstatsplot/vignettes/combine_plots.html}
#'
#' @examples
#'
#'
#' # loading the necessary libraries
#' library(ggplot2)
#'
#'
#' # preparing the first plot
#' p1 <-
#' ggplot2::ggplot(
Expand All @@ -77,7 +76,7 @@
#' ) +
#' geom_point() +
#' labs(title = "setosa")
#'
#'
#' # preparing the second plot
#' p2 <-
#' ggplot2::ggplot(
Expand All @@ -86,7 +85,7 @@
#' ) +
#' geom_point() +
#' labs(title = "versicolor")
#'
#'
#' # combining the plot with a title and a caption
#' combine_plots(
#' p1,
Expand Down
5 changes: 0 additions & 5 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#'
#' @title Movie information and user ratings from IMDB.com (wide format).
#' @name movies_wide
#' @details Modified dataset from `ggplot2movies` package.
Expand Down Expand Up @@ -34,8 +33,6 @@
#' head(movies_wide)
"movies_wide"


#'
#' @title Movie information and user ratings from IMDB.com (long format).
#' @name movies_long
#' @details Modified dataset from `ggplot2movies` package.
Expand Down Expand Up @@ -94,8 +91,6 @@
#' head(Titanic_full)
"Titanic_full"


#'
#' @title Moral judgments about third-party moral behavior.
#' @name intent_morality
#' @details This dataset contains data from a recent study about how people
Expand Down
3 changes: 1 addition & 2 deletions R/ggcoefstats.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#'
#' @title Model coefficients for fitted models with the model summary as a
#' caption.
#' @name ggcoefstats
Expand Down Expand Up @@ -126,7 +125,7 @@
#' \url{https://cran.r-project.org/package=ggstatsplot/vignettes/ggcoefstats.html}
#'
#' @examples
#'
#'
#' set.seed(123)
#' ggcoefstats(x = lm(formula = mpg ~ cyl * am, data = mtcars))
#' @export
Expand Down
11 changes: 5 additions & 6 deletions R/ggcorrmat.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#'
#' @title Visualization of a correlalogram (or correlation matrix)
#' @name ggcorrmat
#' @aliases ggcorrmat
Expand Down Expand Up @@ -124,7 +123,7 @@
#' \url{https://cran.r-project.org/package=ggstatsplot/vignettes/ggcorrmat.html}
#'
#' @examples
#'
#'
#' # to get the correlalogram
#' # note that the function will run even if the vector with variable names is
#' # not of same length as the number of variables
Expand All @@ -133,14 +132,14 @@
#' cor.vars = sleep_total:bodywt,
#' cor.vars.names = c("total sleep", "REM sleep")
#' )
#'
#'
#' # to get the correlation matrix
#' ggstatsplot::ggcorrmat(
#' data = ggplot2::msleep,
#' cor.vars = sleep_total:bodywt,
#' output = "r"
#' )
#'
#'
#' # setting output = "p-values" (or "p") will return the p-value matrix
#' ggstatsplot::ggcorrmat(
#' data = ggplot2::msleep,
Expand All @@ -149,15 +148,15 @@
#' p.adjust.method = "fdr",
#' output = "p"
#' )
#'
#'
#' # setting output = "ci" will return the confidence intervals for unique
#' # correlation pairs
#' ggstatsplot::ggcorrmat(
#' data = ggplot2::msleep,
#' cor.vars = sleep_total:bodywt,
#' output = "ci"
#' )
#'
#'
#' # modifying few elements of the correlation matrix by changing function defaults
#' ggstatsplot::ggcorrmat(
#' data = datasets::iris,
Expand Down
7 changes: 6 additions & 1 deletion R/gghistostats.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#'
#' @title Histogram for distribution of a numeric variable
#' @name gghistostats
#' @aliases gghistostats
Expand Down Expand Up @@ -190,6 +189,12 @@ gghistostats <-
data %<>%
tibble::as_data_frame(x = .)

# Adding some binwidth sanity checking
if (is.null(binwidth)) {
binwidth <- (max(data$x) - min(data$x))/sqrt(length(data$x))
}


# ========================================== stats ==================================================================

if (isTRUE(results.subtitle)) {
Expand Down
1 change: 0 additions & 1 deletion R/ggpiestats.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#'
#' @title Pie charts with statistical tests
#' @name ggpiestats
#' @aliases ggpiestats
Expand Down
1 change: 0 additions & 1 deletion R/ggscatterstats.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#'
#' @title Scatterplot with marginal distributions
#' @name ggscatterstats
#' @aliases ggscatterstats
Expand Down
1 change: 0 additions & 1 deletion R/grouped_ggbetweenstats.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#'
#' @title Violin plots for group or condition comparisons in between-subjects
#' designs repeated across all levels of a grouping variable.
#' @name grouped_ggbetweenstats
Expand Down
7 changes: 3 additions & 4 deletions R/grouped_ggcorrmat.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#'
#' @title Visualization of a correlalogram (or correlation matrix) for all
#' levels of a grouping variable
#' @name grouped_ggcorrmat
Expand Down Expand Up @@ -38,7 +37,7 @@
#'
#'
#' @examples
#'
#'
#' # for getting plot
#' ggstatsplot::grouped_ggcorrmat(
#' data = ggplot2::msleep,
Expand All @@ -49,15 +48,15 @@
#' nrow = 2,
#' ncol = 2
#' )
#'
#'
#' # for getting correlations
#' ggstatsplot::grouped_ggcorrmat(
#' data = ggplot2::msleep,
#' grouping.var = vore,
#' cor.vars = sleep_total:bodywt,
#' output = "correlations"
#' )
#'
#'
#' # for getting confidence intervals
#' # if robust correlation is selected, confidence intervals will not be
#' # available
Expand Down
20 changes: 18 additions & 2 deletions R/grouped_gghistostats.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#'
#' @title Grouped histograms for distribution of a numeric variable
#' @name grouped_gghistostats
#' @aliases grouped_gghistostats
Expand Down Expand Up @@ -88,7 +87,6 @@ grouped_gghistostats <- function(data,
messages = TRUE,
...) {
# ================== preparing dataframe ==================

# getting the dataframe ready
df <- dplyr::select(
.data = data,
Expand All @@ -100,6 +98,24 @@ grouped_gghistostats <- function(data,
title.text = !!rlang::enquo(grouping.var)
)

binmax <- dplyr::select(
.data = data,
!!rlang::enquo(x)
) %>% max

binmin <- dplyr::select(
.data = data,
!!rlang::enquo(x)
) %>% min

bincount <- as.integer(data %>% dplyr::count())

# Adding some binwidth sanity checking
if (is.null(binwidth)) {
binwidth <- (binmax - binmin)/sqrt(bincount)
}


# creating a nested dataframe
df %<>%
dplyr::mutate_if(
Expand Down
9 changes: 4 additions & 5 deletions R/grouped_ggscatterstats.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#'
#' @title Scatterplot with marginal distributions for all levels of a grouping
#' variable
#' @name grouped_ggscatterstats
Expand Down Expand Up @@ -36,10 +35,10 @@
#' @inherit ggscatterstats return details
#'
#' @examples
#'
#'
#' # to ensure reproducibility
#' set.seed(123)
#'
#'
#' # basic function call
#' ggstatsplot::grouped_ggscatterstats(
#' data = dplyr::filter(
Expand All @@ -53,7 +52,7 @@
#' formula = y ~ x + I(x^3),
#' grouping.var = genre
#' )
#'
#'
#' # using labeling
#' ggstatsplot::grouped_ggscatterstats(
#' data = dplyr::filter(ggplot2::mpg, cyl != 5),
Expand All @@ -66,7 +65,7 @@
#' label.expression = hwy > 25 & displ > 2.5,
#' messages = FALSE
#' )
#'
#'
#' # labeling without expression
#' ggstatsplot::grouped_ggscatterstats(
#' data = dplyr::filter(
Expand Down
3 changes: 0 additions & 3 deletions R/helpers_effsize_ci.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#'
#' @title A heteroscedastic one-way ANOVA for trimmed means with confidence
#' interval for effect size.
#' @name t1way_ci
Expand Down Expand Up @@ -469,7 +468,6 @@ chisq_v_ci <- function(data,
}


#'
#' @title Robust correlation coefficient and its confidence interval
#' @name robcor_ci
#' @description Custom function to get confidence intervals for percentage bend
Expand Down Expand Up @@ -620,7 +618,6 @@ robcor_ci <- function(data,
return(results_df)
}

#'
#' @title Confidence intervals for partial eta-squared and omega-squared for
#' linear models.
#' @name lm_effsize_ci
Expand Down
2 changes: 0 additions & 2 deletions R/theme_ggstatsplot.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#'
#' @title Default theme used in all `ggstatsplot` package plots
#' @name theme_ggstatsplot
#' @author Indrajeet Patil
Expand Down Expand Up @@ -68,7 +67,6 @@ theme_ggstatsplot <- function(ggtheme = ggplot2::theme_bw(), ggstatsplot.layer =
}
}

#'
#' @title Default theme used in all `ggstatsplot` package plots
#' @name theme_mprl
#' @author Indrajeet Patil
Expand Down

0 comments on commit 38eee48

Please sign in to comment.