Skip to content

Commit

Permalink
New argument ci added in ggerrorplot #94
Browse files Browse the repository at this point in the history
  • Loading branch information
kassambara committed Aug 10, 2018
1 parent b857784 commit 91ba2f0
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
## Minor changes

- New argument `position` added in `gghistogram()`. Allowed values include "identity", "stack", "dodge".
- New argument `ci` added in `ggerrorplot()` [@abrar-alshaer, #94](https://github.com/kassambara/ggpubr/issues/94)

## Bug fixes

Expand Down
3 changes: 2 additions & 1 deletion R/add_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ NULL
#'@export
add_summary <- function(p, fun = "mean_se", error.plot = "pointrange",
color = "black", fill = "white",
width = NULL, shape = 19, size = 1,
width = NULL, shape = 19, size = 1, ci = 0.95,
data = NULL, position = position_dodge(0.8))
{

Expand Down Expand Up @@ -109,6 +109,7 @@ add_summary <- function(p, fun = "mean_se", error.plot = "pointrange",
color = color, geom = geom, size = size,
data = data, position = position,
fun.args = list(error.limit = error.limit))
if(fun == "mean_ci") opts$fun.args$ci <- ci

# Specific option
#::::::::::::::::::::::::::::::::::::::::::::::::::
Expand Down
4 changes: 2 additions & 2 deletions R/ggadd.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ NULL
ggadd <- function(p, add = NULL, color = "black", fill = "white",
width = 1, shape = 19, size = NULL, alpha = 1, jitter = 0.2,
binwidth = NULL, dotsize = size,
error.plot = "pointrange",
error.plot = "pointrange", ci = 0.95,
data = NULL, position = position_dodge(0.8),
p_geom = ""
)
Expand Down Expand Up @@ -138,7 +138,7 @@ ggadd <- function(p, add = NULL, color = "black", fill = "white",
width <- 0.1
else if(error.plot == "crossbar" & .geom(p) == "violin") width = 0.2
p <- p %>% add_summary(errors, error.plot = error.plot, color = color, shape = shape,
position = position, size = size, width = width)
position = position, size = size, width = width, ci = ci)
}

p
Expand Down
9 changes: 5 additions & 4 deletions R/ggerrorplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ NULL
#'@description Visualizing error.
#'@inheritParams ggboxplot
#'@inheritParams ggplot2::geom_errorbar
#'@param ci the percent range of the confidence interval (default is 0.95).
#'@param x,y x and y variables for drawing.
#'@param color,fill outline and fill colors.
#'@param desc_stat descriptive statistics to be used for visualizing errors. Default value is "mean_se".
Expand Down Expand Up @@ -76,7 +77,7 @@ ggerrorplot <- function(data, x, y, desc_stat = "mean_se",
select = NULL, remove = NULL, order = NULL,
add = "none",
add.params = list(),
error.plot = "pointrange",
error.plot = "pointrange", ci = 0.95,
position = position_dodge(),
ggtheme = theme_pubr(),
...)
Expand All @@ -92,7 +93,7 @@ ggerrorplot <- function(data, x, y, desc_stat = "mean_se",
title = title, xlab = xlab, ylab = ylab,
facet.by = facet.by, panel.labs = panel.labs, short.panel.labs = short.panel.labs,
select = select , remove = remove, order = order,
add = add, add.params = add.params, error.plot = error.plot,
add = add, add.params = add.params, error.plot = error.plot, ci = ci,
position = position, ggtheme = ggtheme, ...)
if(!missing(data)) .opts$data <- data
if(!missing(x)) .opts$x <- x
Expand Down Expand Up @@ -124,7 +125,7 @@ ggerrorplot_core <- function(data, x, y, desc_stat = "mean_se",
select = NULL, order = NULL,
add = "none",
add.params = list(),
error.plot = "pointrange",
error.plot = "pointrange", ci = 0.95,
position = position_dodge(0.8),
ggtheme = theme_pubr(),
...)
Expand All @@ -143,7 +144,7 @@ ggerrorplot_core <- function(data, x, y, desc_stat = "mean_se",
if(inherits(position, "PositionDodge") & is.null(position$width)) position$width = 0.8
p <- ggplot(data, aes_string(x, y))
add.params <- add.params %>%
.add_item(add = add, data = data, error.plot = error.plot, position = position, p = p)
.add_item(add = add, data = data, error.plot = error.plot, ci = ci, position = position, p = p)
p <- do.call(ggadd, add.params)

# Main plot
Expand Down
6 changes: 3 additions & 3 deletions man/add_summary.Rd

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

4 changes: 3 additions & 1 deletion man/ggadd.Rd

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

4 changes: 3 additions & 1 deletion man/ggerrorplot.Rd

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

0 comments on commit 91ba2f0

Please sign in to comment.