Skip to content

Commit 7a3430c

Browse files
committed
Don't showlegend for line trace of geom_smooth
1 parent 2378655 commit 7a3430c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

R/ggplotly.R

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,22 @@ gg2list <- function(p){
219219
# This extracts essential info for this geom/layer.
220220
if (L$geom$objname == "smooth") {
221221
# smooth is really a line + ribbon geom
222-
misc$smoothRibbon <- TRUE
223-
trace1 <- if (isTRUE(L$stat_params$se == FALSE)) {
222+
# always draw the line
223+
misc$smoothLine <- TRUE
224+
trace1 <- layer2traces(L, df, misc)
225+
trace1 <- lapply(trace1, function(x) { x$showlegend <- FALSE; x })
226+
misc$smoothLine <- FALSE
227+
# draw ribbon unless se = FALSE
228+
trace2 <- if (isTRUE(L$stat_params$se == FALSE)) {
224229
NULL
225230
} else {
231+
misc$smoothRibbon <- TRUE
226232
layer2traces(L, df, misc)
227233
}
228-
misc$smoothRibbon <- FALSE
229-
misc$smoothLine <- TRUE
230-
traces <- c(trace1, layer2traces(L, df, misc))
234+
traces <- c(trace1, trace2)
231235
} else {
232236
traces <- layer2traces(L, df, misc)
233237
}
234-
235238
possible.legends <- markLegends[[L$geom$objname]]
236239
actual.legends <- possible.legends[possible.legends %in% names(L$mapping)]
237240
layer.legends[[paste(i)]] <- actual.legends

0 commit comments

Comments
 (0)