plotly ignores scale_fill_gradient2
还没有人认领这个 Issue。
- 主要语言
- R
- 星标
- 2.7k
- 派生
- 641
- PR 合并指标
- 30 天内没有已合并 PR
描述
Thank you for writing and maintaining plotly!
When making a scatterplot, I like to specify pch = 21 to print an outline around points. This helps distinguish points when they are close together. When I use this plotting scheme, ggplot2 gives the expected output, but plotly ignores the aesthetics supplied by scale_fill_gradient2() and gives the error number of items to replace is not a multiple of replacement length. I believe this issue is similar to https://github.com/plotly/plotly.R/issues/1149.
# R v4.0.5
library(plotly) # v 4.9.4.1
library(ggplot2) # v 3.3.3
p <- ggplot(data = wdat, mapping = aes(x = Age, y = as.numeric(ABV))) +
geom_jitter(mapping = aes(fill = Score), size = 2.5, pch = 21) +
scale_fill_gradient2(low = "#0008ff",
midpoint = mean(wdat$Score),
mid = "purple",
high = "#ff0000") +
scale_y_continuous(name = "% ABV",
limits = c(40, 70),
breaks = seq(from = 40, 70, 5)) +
theme_classic()
p + ggtitle("ggplot2")
ggplotly(p + ggtitle("plotly"))


If I switch my mapping aesthetic to color with pch = 19 and specify a gradient with scale_color_gradient2(), then ggplot2 and plotly give the same output without error. However, the desired outlines are lost.
p <- ggplot(data = wdat, mapping = aes(x = Age, y = as.numeric(ABV))) +
geom_jitter(mapping = aes(color = Score), size = 2.5, pch = 19) +
scale_color_gradient2(low = "#0008ff",
midpoint = mean(wdat$Score),
mid = "purple",
high = "#ff0000") +
scale_y_continuous(name = "% ABV",
limits = c(40, 70),
breaks = seq(from = 40, 70, 5)) +
theme_classic()
p + ggtitle("ggplot2")
ggplotly(p + ggtitle("plotly"))


Here is my scheme for downloading the dataset, in case you want to troubleshoot with the same data:
library(dplyr) # v 1.0.5
library(gsheet) # v 0.4.5
url <- "https://docs.google.com/spreadsheets/d/1geSFmGKWhoSzoSblQQK6fDzWSujY-MQ9w2b3VNbTxZk"
wdat <- gsheet::construct_download_url(url = url) %>%
gsheet::gsheet2tbl(url = .) %>%
mutate(ABV = gsub("%","",ABV) %>%
as.numeric() %>%
round(., 3) %>%
format(., nsmall = 1)) %>%
na.omit()
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
运行提供的 R 示例,并比较使用 scale_fill_gradient2() 时 pch = 21 的 ggplot2 和 ggplotly 输出。从 ggplotly 转换路径开始,跟踪 fill 和点轮廓的处理方式;完成的标准是示例不再报错、保留渐变并保留轮廓。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- r
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100