@@ -13,10 +13,7 @@ layer2traces <- function(l, d, misc) {
1313 g <- list (geom = l $ geom $ objname ,
1414 data = not.na(d ),
1515 prestats.data = not.na(misc $ prestats.data ))
16- if (g $ geom == " smooth" ) {
17- if (isTRUE(misc $ smoothRibbon )) g $ geom <- " smoothRibbon"
18- if (isTRUE(misc $ smoothLine )) g $ geom <- " smoothLine"
19- }
16+
2017 # needed for when group, etc. is an expression.
2118 g $ aes <- sapply(l $ mapping , function (k ) as.character(as.expression(k )))
2219 # Partial conversion for geom_violin (Plotly does not offer KDE yet)
@@ -26,6 +23,22 @@ layer2traces <- function(l, d, misc) {
2623 probability density estimation is not supported in Plotly yet." )
2724 }
2825
26+ # geom_smooth() means geom_line() + geom_ribbon()
27+ # Note the line is always drawn, but ribbon is not if se = FALSE.
28+ if (g $ geom == " smooth" ) {
29+ # If smoothLine has been compiled already, consider smoothRibbon.
30+ if (isTRUE(misc $ smoothLine )) {
31+ misc $ smoothLine <- FALSE
32+ if (isTRUE(L $ stat_param $ se == FALSE )) {
33+ return (NULL )
34+ } else {
35+ g $ geom <- " smoothRibbon"
36+ }
37+ } else {
38+ misc $ smoothLine <- TRUE
39+ g $ geom <- " smoothLine"
40+ }
41+ }
2942 # Barmode and bargap
3043 barmode <- " group"
3144 if (g $ geom == " bar" || g $ geom == " histogram" ) {
@@ -285,7 +298,13 @@ layer2traces <- function(l, d, misc) {
285298 }
286299 no.sort [[tr.i ]]$ sort <- NULL
287300 }
288- no.sort
301+ # if line portion of geom_smooth was compiled, call layer2traces()
302+ # again for ribbon portion
303+ if (isTRUE(misc $ smoothLine )) {
304+ c(layer2traces(l , d , misc ), no.sort )
305+ } else {
306+ no.sort
307+ }
289308}# layer2traces
290309
291310
@@ -652,4 +671,26 @@ geom2trace <- list(
652671 mode = " lines" ,
653672 line = paramORdefault(params , aes2line , line.defaults ))
654673 }
674+ # smooth=function(data, params) {
675+ # if (isTRUE(params$se == FALSE)) {
676+ # L1 <- NULL
677+ # } else {
678+ # L1 <- list(x=c(data$x[1], data$x, rev(data$x)),
679+ # y=c(data$ymin[1], data$ymax, rev(data$ymin)),
680+ # type="scatter",
681+ # line=paramORdefault(params, aes2line, ribbon.line.defaults),
682+ # fill="tonexty",
683+ # fillcolor=toFill(params$fill, ifelse(is.null(params$alpha), 1,
684+ # params$alpha)))
685+ # }
686+ # # $showlegend <- FALSE
687+ # c(L1,
688+ # list(x=data$x,
689+ # y=data$y,
690+ # name=params$name,
691+ # text=data$text,
692+ # type="scatter",
693+ # mode="lines",
694+ # line=paramORdefault(params, aes2line, line.defaults)))
695+ # }
655696)
0 commit comments