Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 270d20e

Browse files
authored
Fix geom2trace.geompoint incorrect filling (closes #2298) (#2299)
1 parent a1c3089 commit 270d20e

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

‎NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

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

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

1113
## New features

‎R/layers2traces.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,12 @@ geom2trace.GeomPoint <- function(data, params, p) {
767767
# fill is only relevant for pch %in% 21:25
768768
pch <- uniq(data$shape) %||% params$shape %||% GeomPoint$default_aes$shape
769769
if (any(idx <- pch %in% 21:25) || any(idx <- !is.null(data[["fill_plotlyDomain"]]))) {
770-
L$marker$color[idx] <- aes2plotly(data, params, "fill")[idx]
770+
fill_value <- aes2plotly(data, params, "fill")
771+
if (length(idx) == 1) {
772+
L$marker$color <- fill_value
773+
} else {
774+
L$marker$color[idx] <- fill_value[idx]
775+
}
771776
}
772777
compact(L)
773778
}

‎tests/testthat/test-ggplot-point.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ test_that("marker color inherits from fill, when appropriate", {
4848
})
4949

5050

51+
test_that("when marker color inherits from fill, colours are assigned correctly #2298", {
52+
df <- data.frame(x = c(1,2), y = c(0,0), color = rep("yellow", 2), fill = 1:2)
53+
p <- ggplot(df) +
54+
geom_point(aes(x = x, y = y, fill = fill, color = color), size = 5, shape = 21) +
55+
scale_fill_gradient(low = "green", high = "red")
56+
pb <- plotly_build(p)
57+
expect_equivalent(pb$x$data[[1]]$marker$color, c("rgba(0,255,0,1)", "rgba(255,0,0,1)"))
58+
})
59+
60+
5161
test_that("can plot on sub-second time scale", {
5262
d <- data.frame(
5363
x = as.POSIXct("2018年09月28日 15:13:06 CDT") + 1e-3 * c(1:9, 5000),

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /