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

Geom boxplot improvements #1512

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ Suggests:
knitr,
devtools,
shiny (>= 1.1.0),
shinytest (> 1.3.0),
shinytest (>= 1.3.0),
curl,
rmarkdown,
vdiffr,
43 changes: 30 additions & 13 deletions R/layers2traces.R
Original file line number Diff line number Diff line change
@@ -777,7 +777,7 @@ geom2trace.GeomPolygon <- function(data, params, p) {

#' @export
geom2trace.GeomBoxplot <- function(data, params, p) {
compact(list(
trace <- compact(list(
x = data[["x"]],
y = data[["y"]],
hoverinfo = "y",
@@ -786,26 +786,44 @@ geom2trace.GeomBoxplot <- function(data, params, p) {
frame = data[["frame"]],
ids = data[["ids"]],
type = "box",
notched = params[["notch"]],
notchwidth = params[["notchwidth"]],
fillcolor = toRGB(
aes2plotly(data, params, "fill"),
aes2plotly(data, params, "alpha")
),
# marker styling must inherit from GeomPoint$default_aes
# https://github.com/hadley/ggplot2/blob/ab42c2ca81458b0cf78e3ba47ed5db21f4d0fc30/NEWS#L73-L77
marker = list(
opacity = GeomPoint$default_aes$alpha,
outliercolor = toRGB(GeomPoint$default_aes$colour),
line = list(
width = mm2pixels(GeomPoint$default_aes$stroke),
color = toRGB(GeomPoint$default_aes$colour)
),
size = mm2pixels(GeomPoint$default_aes$size)
),
line = list(
color = aes2plotly(data, params, "colour"),
width = aes2plotly(data, params, "size")
)
))

# handle special `outlier.shape=NA` case
if (is.na(params$outlier.shape)) {
params$outlier.alpha <- 0
}

# redefine aes meaning using outlier params
data$alpha <- params$outlier.alpha %||% data$alpha
data$fill <- params$outlier.fill %||% data$fill
data$shape <- params$outlier.shape %||% data$shape
data$stroke <- params$outlier.stroke %||% data$stroke
data$colour <- params$outlier.colour %||% data$colour
data$size <- params$outlier.size %||% data$size

trace$marker <- list(
opacity = aes2plotly(data, params, "alpha"),
# I don't think this is relevant if line.color is defined?
color = aes2plotly(data, params, "fill"),
symbol = aes2plotly(data, params, "shape"),
line = list(
width = aes2plotly(data, params, "stroke"),
color = aes2plotly(data, params, "colour")
),
size = aes2plotly(data, params, "size")
)

trace
}


@@ -1007,7 +1025,6 @@ aes2plotly <- function(data, params, aes = "size") {
# https://github.com/ropensci/plotly/pull/1481
if ("default_aes" %in% names(geom_obj)) geom_obj$default_aes else NULL
}

vals <- uniq(data[[aes]]) %||% params[[aes]] %||% defaults[[aes]] %||% NA
converter <- switch(
aes,