@@ -165,7 +165,16 @@ geom2trace <-
165
165
L $ marker $ size <- data $ size
166
166
}
167
167
L
168
- })
168
+ },
169
+ bar = function (data , params ) {
170
+ list (x = data $ x ,
171
+ y = data $ y ,
172
+ name = params $ name ,
173
+ text = data $ text ,
174
+ type = " bar" )
175
+ }
176
+ )
177
+
169
178
170
179
# ' Convert ggplot2 aes to line parameters.
171
180
aes2line <- c(linetype = " dash" ,
@@ -175,7 +184,8 @@ aes2line <- c(linetype="dash",
175
184
markLegends <-
176
185
list (point = c(" colour" , " fill" , " shape" ),
177
186
path = c(" linetype" , " size" , " colour" ),
178
- polygon = c(" colour" , " fill" , " linetype" , " size" , " group" ))
187
+ polygon = c(" colour" , " fill" , " linetype" , " size" , " group" ),
188
+ bar = c(" fill" ))
179
189
180
190
markUnique <- as.character(unique(unlist(markLegends )))
181
191
@@ -215,11 +225,11 @@ gg2list <- function(p){
215
225
for (i in seq_along(built $ plot $ layers )){
216
226
# # This is the layer from the original ggplot object.
217
227
L <- p $ layers [[i ]]
218
-
228
+
219
229
# # for each layer, there is a correpsonding data.frame which
220
230
# # evaluates the aesthetic mapping.
221
231
df <- built $ data [[i ]]
222
-
232
+
223
233
# # Test fill and color to see if they encode a quantitative
224
234
# # variable. In that case, we do not make traces for separate
225
235
# # colors, since there are too many!
@@ -237,7 +247,7 @@ gg2list <- function(p){
237
247
FALSE
238
248
})
239
249
}
240
-
250
+
241
251
# # scales are needed for legend ordering.
242
252
for (sc in p $ scales $ scales ){
243
253
a <- sc $ aesthetics
@@ -248,10 +258,10 @@ gg2list <- function(p){
248
258
misc $ breaks [[sc $ aesthetics ]] <- ranks
249
259
}
250
260
}
251
-
261
+
252
262
# # This extracts essential info for this geom/layer.
253
263
traces <- layer2traces(L , df , misc )
254
-
264
+
255
265
# # Do we really need to coord_transform?
256
266
# #g$data <- ggplot2:::coord_transform(built$plot$coord, g$data,
257
267
# # built$panel$ranges[[1]])
@@ -263,7 +273,7 @@ gg2list <- function(p){
263
273
# grid 0-1 scale). This allows transformations to be used
264
274
# out of the box, with no additional d3 coding.
265
275
theme.pars <- ggplot2 ::: plot_theme(p )
266
-
276
+
267
277
# # Flip labels if coords are flipped - transform does not take care
268
278
# # of this. Do this BEFORE checking if it is blank or not, so that
269
279
# # individual axes can be hidden appropriately, e.g. #1.
@@ -329,21 +339,21 @@ gg2list <- function(p){
329
339
! is.blank(s(" axis.ticks.%s" ))
330
340
layout [[s(" %saxis" )]] <- ax.list
331
341
}
332
-
342
+
333
343
# # Remove legend if theme has no legend position
334
344
if (theme.pars $ legend.position == " none" ) layout $ showlegend <- FALSE
335
-
345
+
336
346
# # Main plot title.
337
347
layout $ title <- built $ plot $ labels $ title
338
-
348
+
339
349
# # Background color.
340
350
layout $ plot_bgcolor <- toRGB(theme.pars $ panel.background $ fill )
341
351
layout $ paper_bgcolor <- toRGB(theme.pars $ plot.background $ fill )
342
-
352
+
343
353
# # Legend.
344
354
layout $ margin $ r <- 10
345
355
layout $ legend <- list (bordercolor = " transparent" , x = 100 , y = 1 / 2 )
346
-
356
+
347
357
trace.list $ kwargs <- list (layout = layout )
348
358
trace.list
349
359
}
@@ -359,7 +369,7 @@ layer2traces <- function(l, d, misc){
359
369
data = d )
360
370
# # needed for when group, etc. is an expression.
361
371
g $ aes <- sapply(l $ mapping , function (k ) as.character(as.expression(k )))
362
-
372
+
363
373
# # use un-named parameters so that they will not be exported
364
374
# # to JSON as a named object, since that causes problems with
365
375
# # e.g. colour.
@@ -373,41 +383,41 @@ layer2traces <- function(l, d, misc){
373
383
# # {"bar":"foo"}
374
384
names(g $ params [[p.name ]]) <- NULL
375
385
}
376
-
386
+
377
387
# # Convert complex ggplot2 geoms so that they are treated as special
378
388
# # cases of basic geoms. In ggplot2, this processing is done in the
379
389
# # draw method of the geoms.
380
-
390
+
381
391
# # Every plotly trace has one of these types
382
392
# # type=scatter,bar,box,histogramx,histogram2d,heatmap
383
-
393
+
384
394
# # for type=scatter, you can define
385
395
# # mode=none,markers,lines,lines+markers where "lines" is the
386
396
# # default for 20 or more points, "lines+markers" is the default for
387
397
# # <20 points. "none" is useful mainly if fill is used to make area
388
398
# # plots with no lines.
389
-
399
+
390
400
# # marker=list(size,line,color="rgb(54,144,192)",opacity,symbol)
391
-
401
+
392
402
# # symbol=circle,square,diamond,cross,x,
393
403
# # triangle-up,triangle-down,triangle-left,triangle-right
394
-
404
+
395
405
# # First convert to a "basic" geom, e.g. segments become lines.
396
406
convert <- toBasic [[g $ geom ]]
397
407
basic <- if (is.null(convert )){
398
408
g
399
409
}else {
400
410
convert(g )
401
411
}
402
-
412
+
403
413
# # Then split on visual characteristics that will get different
404
414
# # legend entries.
405
415
data.list <- if (basic $ geom %in% names(markLegends )){
406
416
mark.names <- markLegends [[basic $ geom ]]
407
417
# # However, continuously colored points are an exception: they do
408
418
# # not need a legend entry, and they can be efficiently rendered
409
419
# # using just 1 trace.
410
-
420
+
411
421
# # Maybe it is nice to show a legend for continuous points?
412
422
# # if(basic$geom == "point"){
413
423
# # to.erase <- names(misc$is.continuous)[misc$is.continuous]
@@ -436,7 +446,7 @@ layer2traces <- function(l, d, misc){
436
446
data.list <- structure(list (list (data = basic $ data , params = basic $ params )),
437
447
names = basic $ params $ name )
438
448
}
439
-
449
+
440
450
getTrace <- geom2trace [[basic $ geom ]]
441
451
if (is.null(getTrace )){
442
452
stop(" conversion not implemented for geom_" ,
0 commit comments