@@ -165,7 +165,15 @@ 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
+ type = " bar" )
174
+ }
175
+ )
176
+
169
177
170
178
# ' Convert ggplot2 aes to line parameters.
171
179
aes2line <- c(linetype = " dash" ,
@@ -175,7 +183,8 @@ aes2line <- c(linetype="dash",
175
183
markLegends <-
176
184
list (point = c(" colour" , " fill" , " shape" ),
177
185
path = c(" linetype" , " size" , " colour" ),
178
- polygon = c(" colour" , " fill" , " linetype" , " size" , " group" ))
186
+ polygon = c(" colour" , " fill" , " linetype" , " size" , " group" ),
187
+ bar = c(" fill" ))
179
188
180
189
markUnique <- as.character(unique(unlist(markLegends )))
181
190
@@ -220,11 +229,11 @@ gg2list <- function(p){
220
229
for (i in seq_along(built $ plot $ layers )){
221
230
# # This is the layer from the original ggplot object.
222
231
L <- p $ layers [[i ]]
223
-
232
+
224
233
# # for each layer, there is a correpsonding data.frame which
225
234
# # evaluates the aesthetic mapping.
226
235
df <- built $ data [[i ]]
227
-
236
+
228
237
# # Test fill and color to see if they encode a quantitative
229
238
# # variable. This may be useful for several reasons: (1) it is
230
239
# # sometimes possible to plot several different colors in the same
@@ -249,7 +258,7 @@ gg2list <- function(p){
249
258
})
250
259
}
251
260
}
252
-
261
+
253
262
# # scales are needed for legend ordering.
254
263
for (sc in p $ scales $ scales ){
255
264
a <- sc $ aesthetics
@@ -260,10 +269,10 @@ gg2list <- function(p){
260
269
misc $ breaks [[sc $ aesthetics ]] <- ranks
261
270
}
262
271
}
263
-
272
+
264
273
# # This extracts essential info for this geom/layer.
265
274
traces <- layer2traces(L , df , misc )
266
-
275
+
267
276
# # Do we really need to coord_transform?
268
277
# #g$data <- ggplot2:::coord_transform(built$plot$coord, g$data,
269
278
# # built$panel$ranges[[1]])
@@ -275,7 +284,7 @@ gg2list <- function(p){
275
284
# grid 0-1 scale). This allows transformations to be used
276
285
# out of the box, with no additional d3 coding.
277
286
theme.pars <- ggplot2 ::: plot_theme(p )
278
-
287
+
279
288
# # Flip labels if coords are flipped - transform does not take care
280
289
# # of this. Do this BEFORE checking if it is blank or not, so that
281
290
# # individual axes can be hidden appropriately, e.g. #1.
@@ -349,21 +358,21 @@ gg2list <- function(p){
349
358
! is.blank(s(" axis.ticks.%s" ))
350
359
layout [[s(" %saxis" )]] <- ax.list
351
360
}
352
-
361
+
353
362
# # Remove legend if theme has no legend position
354
363
if (theme.pars $ legend.position == " none" ) layout $ showlegend <- FALSE
355
-
364
+
356
365
# # Main plot title.
357
366
layout $ title <- built $ plot $ labels $ title
358
-
367
+
359
368
# # Background color.
360
369
layout $ plot_bgcolor <- toRGB(theme.pars $ panel.background $ fill )
361
370
layout $ paper_bgcolor <- toRGB(theme.pars $ plot.background $ fill )
362
-
371
+
363
372
# # Legend.
364
373
layout $ margin $ r <- 10
365
374
layout $ legend <- list (bordercolor = " transparent" , x = 100 , y = 1 / 2 )
366
-
375
+
367
376
trace.list $ kwargs <- list (layout = layout )
368
377
trace.list
369
378
}
@@ -409,41 +418,41 @@ layer2traces <- function(l, d, misc){
409
418
# # {"bar":"foo"}
410
419
names(g $ params [[p.name ]]) <- NULL
411
420
}
412
-
421
+
413
422
# # Convert complex ggplot2 geoms so that they are treated as special
414
423
# # cases of basic geoms. In ggplot2, this processing is done in the
415
424
# # draw method of the geoms.
416
-
425
+
417
426
# # Every plotly trace has one of these types
418
427
# # type=scatter,bar,box,histogramx,histogram2d,heatmap
419
-
428
+
420
429
# # for type=scatter, you can define
421
430
# # mode=none,markers,lines,lines+markers where "lines" is the
422
431
# # default for 20 or more points, "lines+markers" is the default for
423
432
# # <20 points. "none" is useful mainly if fill is used to make area
424
433
# # plots with no lines.
425
-
434
+
426
435
# # marker=list(size,line,color="rgb(54,144,192)",opacity,symbol)
427
-
436
+
428
437
# # symbol=circle,square,diamond,cross,x,
429
438
# # triangle-up,triangle-down,triangle-left,triangle-right
430
-
439
+
431
440
# # First convert to a "basic" geom, e.g. segments become lines.
432
441
convert <- toBasic [[g $ geom ]]
433
442
basic <- if (is.null(convert )){
434
443
g
435
444
}else {
436
445
convert(g )
437
446
}
438
-
447
+
439
448
# # Then split on visual characteristics that will get different
440
449
# # legend entries.
441
450
data.list <- if (basic $ geom %in% names(markLegends )){
442
451
mark.names <- markLegends [[basic $ geom ]]
443
452
# # However, continuously colored points are an exception: they do
444
453
# # not need a legend entry, and they can be efficiently rendered
445
454
# # using just 1 trace.
446
-
455
+
447
456
# # Maybe it is nice to show a legend for continuous points?
448
457
# # if(basic$geom == "point"){
449
458
# # to.erase <- names(misc$is.continuous)[misc$is.continuous]
@@ -472,7 +481,7 @@ layer2traces <- function(l, d, misc){
472
481
data.list <- structure(list (list (data = basic $ data , params = basic $ params )),
473
482
names = basic $ params $ name )
474
483
}
475
-
484
+
476
485
getTrace <- geom2trace [[basic $ geom ]]
477
486
if (is.null(getTrace )){
478
487
stop(" conversion not implemented for geom_" ,
0 commit comments