Skip to content

Commit fe92937

Browse files
committed
Implement conversion from position to barmode
1 parent fc7da4f commit fe92937

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

R/ggplotly.R

+14-6
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ aesConverters <-
100100
toRGB(col)
101101
},size=identity,alpha=identity,shape=function(pch){
102102
pch2symbol[as.character(pch)]
103-
}, barmode=function(bm) {
104-
position2barmode[bm][[1]]
105103
})
106104

107105
toBasic <-
@@ -174,7 +172,6 @@ geom2trace <-
174172
name=params$name,
175173
text=data$text,
176174
type="bar",
177-
# barmode=paramORdefault(...),
178175
fillcolor=toRGB(params$fill))
179176
}
180177
)
@@ -189,7 +186,7 @@ markLegends <-
189186
list(point=c("colour", "fill", "shape"),
190187
path=c("linetype", "size", "colour"),
191188
polygon=c("colour", "fill", "linetype", "size", "group"),
192-
bar=c("fill", "barmode"))
189+
bar=c("fill"))
193190

194191
markUnique <- as.character(unique(unlist(markLegends)))
195192

@@ -227,6 +224,19 @@ gg2list <- function(p){
227224
if(!is.data.frame(p$layers[[layer.i]]$data)){
228225
p$layers[[layer.i]]$data <- p$data
229226
}
227+
geom_type <- p$layers[[layer.i]]$geom
228+
geom_type <- strsplit(capture.output(geom_type), "geom_")[[1]][2]
229+
geom_type <- strsplit(geom_type, ": ")[[1]]
230+
## Barmode.
231+
layout$barmode <- "group"
232+
if (geom_type == "bar") {
233+
pos <- capture.output(p$layers[[layer.i]]$position)
234+
if (length(grep("identity", pos)) > 0) {
235+
layout$barmode <- "overlay"
236+
} else if (length(grep("stack", pos)) > 0) {
237+
layout$barmode <- "stack"
238+
}
239+
}
230240
}
231241
## Extract data from built ggplots
232242
built <- ggplot2::ggplot_build(p)
@@ -378,8 +388,6 @@ gg2list <- function(p){
378388
layout$margin$r <- 10
379389
layout$legend <- list(bordercolor="transparent", x=100, y=1/2)
380390

381-
## Barmode.
382-
# layout$barmode <- position2barmode[...][[1]]
383391
trace.list$kwargs <- list(layout=layout)
384392
trace.list
385393
}

0 commit comments

Comments
 (0)