Skip to content

Commit 03db5fa

Browse files
committed
Merge branch 'ggplotly' of https://github.com/ropensci/plotly into ggplotly
2 parents 50f70b8 + 3b2b41e commit 03db5fa

File tree

4 files changed

+38
-31
lines changed

4 files changed

+38
-31
lines changed

.travis.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@ before_script:
77
- ./travis-tool.sh install_deps
88
- ./travis-tool.sh install_r RCurl RJSONIO
99
notifications:
10-
hipchat:
11-
rooms:
12-
secure: aeV2r8L8WTt1/FcRZgl0UHyZSxiQJgXyNAPuqEkmUGKV6bhGuQ5I36d7xOnlI8v8MAPUqH9co5t0uupY+81Etp+NE3hk+1J5bTqXfY6l/Bz2l6B51HAWnS6Wo25Bz0BPJdSfGqKYmlM4k+2khR15CSXlbxNimgFrvQ4WNndXPp0=
10+
slack: ropensci:wh30e1MP9Am3wXb2wJx1ZRFi

R/ggplotly.R

+31-22
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,15 @@ geom2trace <-
165165
L$marker$size <- data$size
166166
}
167167
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+
169177

170178
#' Convert ggplot2 aes to line parameters.
171179
aes2line <- c(linetype="dash",
@@ -175,7 +183,8 @@ aes2line <- c(linetype="dash",
175183
markLegends <-
176184
list(point=c("colour", "fill", "shape"),
177185
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"))
179188

180189
markUnique <- as.character(unique(unlist(markLegends)))
181190

@@ -220,11 +229,11 @@ gg2list <- function(p){
220229
for(i in seq_along(built$plot$layers)){
221230
## This is the layer from the original ggplot object.
222231
L <- p$layers[[i]]
223-
232+
224233
## for each layer, there is a correpsonding data.frame which
225234
## evaluates the aesthetic mapping.
226235
df <- built$data[[i]]
227-
236+
228237
## Test fill and color to see if they encode a quantitative
229238
## variable. This may be useful for several reasons: (1) it is
230239
## sometimes possible to plot several different colors in the same
@@ -249,7 +258,7 @@ gg2list <- function(p){
249258
})
250259
}
251260
}
252-
261+
253262
## scales are needed for legend ordering.
254263
for(sc in p$scales$scales){
255264
a <- sc$aesthetics
@@ -260,10 +269,10 @@ gg2list <- function(p){
260269
misc$breaks[[sc$aesthetics]] <- ranks
261270
}
262271
}
263-
272+
264273
## This extracts essential info for this geom/layer.
265274
traces <- layer2traces(L, df, misc)
266-
275+
267276
## Do we really need to coord_transform?
268277
##g$data <- ggplot2:::coord_transform(built$plot$coord, g$data,
269278
## built$panel$ranges[[1]])
@@ -275,7 +284,7 @@ gg2list <- function(p){
275284
# grid 0-1 scale). This allows transformations to be used
276285
# out of the box, with no additional d3 coding.
277286
theme.pars <- ggplot2:::plot_theme(p)
278-
287+
279288
## Flip labels if coords are flipped - transform does not take care
280289
## of this. Do this BEFORE checking if it is blank or not, so that
281290
## individual axes can be hidden appropriately, e.g. #1.
@@ -349,21 +358,21 @@ gg2list <- function(p){
349358
!is.blank(s("axis.ticks.%s"))
350359
layout[[s("%saxis")]] <- ax.list
351360
}
352-
361+
353362
## Remove legend if theme has no legend position
354363
if(theme.pars$legend.position=="none") layout$showlegend <- FALSE
355-
364+
356365
## Main plot title.
357366
layout$title <- built$plot$labels$title
358-
367+
359368
## Background color.
360369
layout$plot_bgcolor <- toRGB(theme.pars$panel.background$fill)
361370
layout$paper_bgcolor <- toRGB(theme.pars$plot.background$fill)
362-
371+
363372
## Legend.
364373
layout$margin$r <- 10
365374
layout$legend <- list(bordercolor="transparent", x=100, y=1/2)
366-
375+
367376
trace.list$kwargs <- list(layout=layout)
368377
trace.list
369378
}
@@ -409,41 +418,41 @@ layer2traces <- function(l, d, misc){
409418
## {"bar":"foo"}
410419
names(g$params[[p.name]]) <- NULL
411420
}
412-
421+
413422
## Convert complex ggplot2 geoms so that they are treated as special
414423
## cases of basic geoms. In ggplot2, this processing is done in the
415424
## draw method of the geoms.
416-
425+
417426
## Every plotly trace has one of these types
418427
## type=scatter,bar,box,histogramx,histogram2d,heatmap
419-
428+
420429
## for type=scatter, you can define
421430
## mode=none,markers,lines,lines+markers where "lines" is the
422431
## default for 20 or more points, "lines+markers" is the default for
423432
## <20 points. "none" is useful mainly if fill is used to make area
424433
## plots with no lines.
425-
434+
426435
## marker=list(size,line,color="rgb(54,144,192)",opacity,symbol)
427-
436+
428437
## symbol=circle,square,diamond,cross,x,
429438
## triangle-up,triangle-down,triangle-left,triangle-right
430-
439+
431440
## First convert to a "basic" geom, e.g. segments become lines.
432441
convert <- toBasic[[g$geom]]
433442
basic <- if(is.null(convert)){
434443
g
435444
}else{
436445
convert(g)
437446
}
438-
447+
439448
## Then split on visual characteristics that will get different
440449
## legend entries.
441450
data.list <- if(basic$geom %in% names(markLegends)){
442451
mark.names <- markLegends[[basic$geom]]
443452
## However, continuously colored points are an exception: they do
444453
## not need a legend entry, and they can be efficiently rendered
445454
## using just 1 trace.
446-
455+
447456
## Maybe it is nice to show a legend for continuous points?
448457
## if(basic$geom == "point"){
449458
## to.erase <- names(misc$is.continuous)[misc$is.continuous]
@@ -472,7 +481,7 @@ layer2traces <- function(l, d, misc){
472481
data.list <- structure(list(list(data=basic$data, params=basic$params)),
473482
names=basic$params$name)
474483
}
475-
484+
476485
getTrace <- geom2trace[[basic$geom]]
477486
if(is.null(getTrace)){
478487
stop("conversion not implemented for geom_",

R/plotly.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ plotly <- function(username=NULL, key=NULL){
9494
w <- if(is.null(options[["width"]])) "600" else options[["width"]]
9595
h <- if(is.null(options[["height"]])) "600" else options[["height"]]
9696
paste("<iframe height=\"", h, "\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\"\n\t\t\t\tsrc=\"",
97-
options[["url"]], "\" width=\"", w, "\"></iframe>", sep = "")
97+
options[["url"]], "\" width=\"", w, "\" frameBorder=\"0\"></iframe>", sep = "")
9898
}
9999
}
100100
pub$plotly <- function(..., kwargs = list(filename = NULL, fileopt = NULL)) {

inst/tests/test-ggplot-bar.R

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ researchers <-
99
gg <- ggplot(researchers, aes(country, papers, fill=field))
1010

1111
test_that("position_dodge is translated to barmode=group", {
12-
gg.dodge <- gg+geom_bar(stat="identity", position="dodge")
12+
gg.dodge <- gg + geom_bar(stat="identity", position="dodge")
1313
L <- gg2list(gg.dodge)
1414
expect_equal(length(L), 3)
1515
trace.names <- sapply(L[1:2], "[[", "name")
@@ -18,17 +18,17 @@ test_that("position_dodge is translated to barmode=group", {
1818
})
1919

2020
test_that("position_stack is translated to barmode=stack", {
21-
gg.stack <- gg+geom_bar(stat="identity", position="stack")
22-
gg2list(gg.stack)
21+
gg.stack <- gg + geom_bar(stat="identity", position="stack")
22+
L <- gg2list(gg.stack)
2323
expect_equal(length(L), 3)
2424
trace.names <- sapply(L[1:2], "[[", "name")
2525
expect_true(all(c("Math", "Bio") %in% trace.names))
2626
expect_identical(L$kwargs$layout$barmode, "stack")
2727
})
2828

2929
test_that("position_identity is translated to barmode=overlay", {
30-
gg.identity <- gg+geom_bar(stat="identity", position="identity")
31-
gg2list(gg.identity)
30+
gg.identity <- gg + geom_bar(stat="identity", position="identity")
31+
L <- gg2list(gg.identity)
3232
expect_equal(length(L), 3)
3333
trace.names <- sapply(L[1:2], "[[", "name")
3434
expect_true(all(c("Math", "Bio") %in% trace.names))

0 commit comments

Comments
 (0)