Skip to content

Commit c2621ac

Browse files
Closes plotly#1614. Implemented to_basic for the geom_alluvium and geom_stratum
1 parent c35a44e commit c2621ac

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

R/layers2traces.R

+29
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,35 @@ to_basic.GeomQuantile <- function(data, prestats_data, layout, params, p, ...){
613613
dat
614614
}
615615

616+
#' @export
617+
to_basic.GeomStratum <- function (data, ...) {
618+
to_basic.GeomRect(data, ...)
619+
}
620+
621+
#' @export
622+
to_basic.GeomAlluvium <- function (data, ...) {
623+
prefix_class(transform_alluvium(data), "GeomPolygon")
624+
}
625+
626+
# tranform the alluvium data into the corresponding polygons
627+
transform_alluvium <- function(data) {
628+
data <- data[order(data$x), ]
629+
630+
if(unique(data$colour) == 0) data$colour <- NULL
631+
632+
unused_aes <- ! names(data) %in% c("x", "y", "ymin", "ymax")
633+
634+
row_number <- nrow(data)
635+
636+
data_rev <- data[nrow(data):1L, ]
637+
638+
structure(rbind(
639+
cbind(x = data$x, y = data$ymin, data[unused_aes]),
640+
cbind(x = data$x[row_number], y = data$ymin[row_number], data[row_number, unused_aes]),
641+
cbind(x = data_rev$x, y = data_rev$ymax, data_rev[unused_aes])
642+
), class = class(data))
643+
}
644+
616645
#' @export
617646
to_basic.default <- function(data, prestats_data, layout, params, p, ...) {
618647
data

0 commit comments

Comments
 (0)