@@ -13,10 +13,7 @@ layer2traces <- function(l, d, misc) {
13
13
g <- list (geom = l $ geom $ objname ,
14
14
data = not.na(d ),
15
15
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
+
20
17
# needed for when group, etc. is an expression.
21
18
g $ aes <- sapply(l $ mapping , function (k ) as.character(as.expression(k )))
22
19
# Partial conversion for geom_violin (Plotly does not offer KDE yet)
@@ -26,6 +23,22 @@ layer2traces <- function(l, d, misc) {
26
23
probability density estimation is not supported in Plotly yet." )
27
24
}
28
25
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
+ }
29
42
# Barmode and bargap
30
43
barmode <- " group"
31
44
if (g $ geom == " bar" || g $ geom == " histogram" ) {
@@ -285,7 +298,13 @@ layer2traces <- function(l, d, misc) {
285
298
}
286
299
no.sort [[tr.i ]]$ sort <- NULL
287
300
}
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
+ }
289
308
}# layer2traces
290
309
291
310
@@ -652,4 +671,26 @@ geom2trace <- list(
652
671
mode = " lines" ,
653
672
line = paramORdefault(params , aes2line , line.defaults ))
654
673
}
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
+ # }
655
696
)
0 commit comments