Skip to content

Fix geom2trace.geompoint incorrect filling (closes #2298) #2299

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

Merged
merged 3 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
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: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* Closed #1214: Do not warn in RStudio on Windows when scattergl is used. Recent RStudio versions can render scattergl correctly.

* Closed #2298: Fix fill assignment in geom_point when a single shape value was used with multiple fill and colour values mapped (@zeehio)

# 4.10.2

## New features
Expand Down
7 changes: 6 additions & 1 deletion R/layers2traces.R
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,12 @@ geom2trace.GeomPoint <- function(data, params, p) {
# fill is only relevant for pch %in% 21:25
pch <- uniq(data$shape) %||% params$shape %||% GeomPoint$default_aes$shape
if (any(idx <- pch %in% 21:25) || any(idx <- !is.null(data[["fill_plotlyDomain"]]))) {
L$marker$color[idx] <- aes2plotly(data, params, "fill")[idx]
fill_value <- aes2plotly(data, params, "fill")
if (length(idx) == 1) {
L$marker$color <- fill_value
} else {
L$marker$color[idx] <- fill_value[idx]
}
}
compact(L)
}
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-ggplot-point.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ test_that("marker color inherits from fill, when appropriate", {
})


test_that("when marker color inherits from fill, colours are assigned correctly #2298", {
df <- data.frame(x = c(1,2), y = c(0,0), color = rep("yellow", 2), fill = 1:2)
p <- ggplot(df) +
geom_point(aes(x = x, y = y, fill = fill, color = color), size = 5, shape = 21) +
scale_fill_gradient(low = "green", high = "red")
pb <- plotly_build(p)
expect_equivalent(pb$x$data[[1]]$marker$color, c("rgba(0,255,0,1)", "rgba(255,0,0,1)"))
})


test_that("can plot on sub-second time scale", {
d <- data.frame(
x = as.POSIXct("2018-09-28 15:13:06 CDT") + 1e-3 * c(1:9, 5000),
Expand Down