@@ -759,12 +759,7 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all",
759
759
l <- rm_asis(l )
760
760
761
761
# start build a plotly object with meta information about the ggplot
762
- ids <- lapply(seq_along(data ), function (x ) new_id())
763
- l $ cur_data <- ids [[layerData ]]
764
- l $ visdat <- if (originalData ) lapply(layer_data , function (x ) function (y ) x ) else lapply(data , function (x ) function (y ) x )
765
- l $ visdat <- setNames(l $ visdat , ids )
766
-
767
- # translate layer mappings -> plotly attrs
762
+ # first, translate layer mappings -> plotly attrs
768
763
mappingFormulas <- lapply(layers , function (x ) {
769
764
mappings <- c(x $ mapping , if (isTRUE(x $ inherit.aes )) plot $ mapping )
770
765
if (originalData ) {
@@ -774,16 +769,27 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all",
774
769
setNames(lapply(nms , function (x ) lazyeval :: f_new(as.symbol(x ))), nms )
775
770
}
776
771
})
777
- # if (!is.null(mappingFormulas[["group"]])) {
778
- # dat <- dplyr::group_by_(dat, mappingFormulas[["group"]])
779
- # }
772
+
773
+ return_dat <- if (originalData ) layer_data else data
774
+
775
+ # translate group aesthetics to data attributes
776
+ return_dat <- Map(function (x , y ) {
777
+ if (is.null(y [[" group" ]])) return (x )
778
+ dplyr :: group_by_(x , y [[" group" ]])
779
+ }, return_dat , mappingFormulas )
780
+
780
781
# don't need to add group as an attribute anymore
781
- # mappingFormulas <- mappingFormulas[!grepl("^group$", names(mappingFormulas))]
782
+ mappingFormulas <- lapply(mappingFormulas , function (x ) x [! grepl(" ^group$" , names(x ))])
783
+
784
+ ids <- lapply(seq_along(data ), function (x ) new_id())
782
785
l $ attrs <- setNames(mappingFormulas , ids )
783
786
l $ attrs <- lapply(l $ attrs , function (x ) structure(x , class = " plotly_eval" ))
784
- # the build step remove the first attrs if no type exists
787
+ # the build step removes the first attrs if no type exists
785
788
l $ attrs [[1 ]][[" type" ]] <- " ggplotly"
786
789
790
+ l $ cur_data <- ids [[layerData ]]
791
+ l $ visdat <- setNames(lapply(return_dat , function (x ) function (y ) x ), ids )
792
+
787
793
l
788
794
}
789
795
0 commit comments