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 3bd4448

Browse files
authored
Prevent RColorBrewer::brewer.pal warning (#1999)
`RColorBrewer::brewer.pal()` throws an (in this case) unnecessary warning if the output plot requires less than 2 colors. This is an easy fix, and does not change the workings of the code since `RColorBrewer::brewer.pal()` never returns less than three levels anywas: ``` > RColorBrewer::brewer.pal(2, "Set2") [1] "#66C2A5" "#FC8D62" "#8DA0CB" Warning message: In RColorBrewer::brewer.pal(2, "Set2") : minimal value for n is 3, returning requested palette with 3 different levels ```
1 parent aa619dc commit 3bd4448

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

‎R/plotly_build.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ map_color <- function(traces, stroke = FALSE, title = "", colorway, na.color = "
783783
isOrdered <- all(vapply(color[isDiscrete], is.ordered, logical(1)))
784784
lvls <- getLevels(unlist(color[isDiscrete]))
785785
N <- length(lvls)
786-
pal <- palette %||% if (isOrdered) viridisLite::viridis(N) else RColorBrewer::brewer.pal(N, "Set2")
786+
pal <- palette %||% if (isOrdered) viridisLite::viridis(N) else RColorBrewer::brewer.pal(max(N, 3L), "Set2")
787787
colScale <- scales::col_factor(pal, levels = names(pal) %||% lvls, na.color = na.color)
788788
color_codes <- Map(function(x, y) toRGB(colScale(as.character(x)), y), color[isDiscrete], alphas[isDiscrete])
789789
traces[isDiscrete] <- Map(mapColor, traces[isDiscrete], color_codes)

0 commit comments

Comments
(0)

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