Skip to content

Commit f4bc6b9

Browse files
committed
Merge pull request #210 from ropensci/marianne-gg2list-figure
Let gg2list return a figure object
2 parents d9ecaf4 + aff2997 commit f4bc6b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+353
-363
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: plotly
22
Type: Package
33
Title: Interactive, publication-quality graphs online.
4-
Version: 0.5.29
4+
Version: 0.5.30
55
Authors@R: c(person("Chris", "Parmer", role = c("aut", "cre"),
66
email = "[email protected]"),
77
person("Scott", "Chamberlain", role = "aut",

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by roxygen2 (4.1.0): do not edit by hand
1+
# Generated by roxygen2 (4.1.1): do not edit by hand
22

33
export(gg2list)
44
export(ggplot_build2)

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
0.5.30 -- 4 May 2015
2+
3+
Let gg2list() return a figure object.
4+
15
0.5.29 -- 16 April 2015
26

37
geom_density() as filled area chart #202

R/ggplotly.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ markUnique <- as.character(unique(unlist(markLegends)))
7070
#' Convert a ggplot to a list.
7171
#' @import ggplot2
7272
#' @param p ggplot2 plot.
73-
#' @return list representing a ggplot.
73+
#' @return figure object (list with names "data" and "layout").
7474
#' @export
75-
gg2list <- function(p){
75+
gg2list <- function(p) {
7676
if(length(p$layers) == 0) {
7777
stop("No layers in plot")
7878
}
@@ -886,7 +886,8 @@ gg2list <- function(p){
886886
flipped.layout[["yaxis"]] <- x
887887
}
888888

889-
flipped.traces$kwargs <- list(layout=flipped.layout)
889+
fig <- list(data=flipped.traces, layout=flipped.layout)
890+
891+
fig
890892

891-
flipped.traces
892893
}

R/plotly-package.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#' \itemize{
88
#' \item Package: plotly
99
#' \item Type: Package
10-
#' \item Version: 0.5.20
10+
#' \item Version: 0.5.30
1111
#' \item Date: 2014-03-07
1212
#' \item License: MIT
1313
#' }

R/plotly.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ For more help, see https://plot.ly/R or contact <[email protected]>.")
8282

8383
# public attributes/methods that the user has access to
8484
pub <- list(username=username, key=key, filename="from api", fileopt=NULL,
85-
version="0.5.20")
85+
version="0.5.30")
8686
priv <- list()
8787

8888
pub$makecall <- function(args, kwargs, origin) {
8989
if (is.null(kwargs$filename))
9090
kwargs$filename <- pub$filename
9191
if (is.null(kwargs$fileopt))
92-
kwargs$fileopt <- NULL
92+
kwargs$fileopt <- pub$fileopt
9393
url <- paste(base_url, "/clientresp", sep="")
9494

9595
respst <- postForm(url, platform="R", version=pub$version,
@@ -139,11 +139,15 @@ For more help, see https://plot.ly/R or contact <[email protected]>.")
139139
if(!is.ggplot(gg)){
140140
stop("gg must be a ggplot")
141141
}
142-
pargs <- gg2list(gg)
142+
fig <- gg2list(gg)
143143
if (!"auto_open" %in% names(kwargs)) {
144144
kwargs <- c(kwargs, auto_open=TRUE)
145145
}
146-
pargs$kwargs <- c(pargs$kwargs, kwargs)
146+
147+
pargs <- fig$data
148+
pargs$kwargs <- kwargs
149+
pargs$kwargs$layout <- fig$layout
150+
147151
if (session == "interactive") { # we are on the command line
148152
resp <- do.call(pub$plotly, pargs)
149153
if (pargs$kwargs$auto_open) {

man/ensure_file_exist.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.1.0): do not edit by hand
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
22
% Please edit documentation in R/tools.R
33
\name{ensure_file_exist}
44
\alias{ensure_file_exist}

man/get_config_file.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.1.0): do not edit by hand
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
22
% Please edit documentation in R/tools.R
33
\name{get_config_file}
44
\alias{get_config_file}

man/get_credentials_file.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.1.0): do not edit by hand
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
22
% Please edit documentation in R/tools.R
33
\name{get_credentials_file}
44
\alias{get_credentials_file}

man/gg2list.Rd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.1.0): do not edit by hand
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
22
% Please edit documentation in R/ggplotly.R
33
\name{gg2list}
44
\alias{gg2list}
@@ -10,7 +10,7 @@ gg2list(p)
1010
\item{p}{ggplot2 plot.}
1111
}
1212
\value{
13-
list representing a ggplot.
13+
figure object (list with names "data" and "layout").
1414
}
1515
\description{
1616
Convert a ggplot to a list.

man/ggplot_build2.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.1.0): do not edit by hand
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
22
% Please edit documentation in R/build_function.R
33
\name{ggplot_build2}
44
\alias{ggplot_build2}

man/group2NA.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.1.0): do not edit by hand
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
22
% Please edit documentation in R/trace_generation.R
33
\name{group2NA}
44
\alias{group2NA}

man/layer2traces.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.1.0): do not edit by hand
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
22
% Please edit documentation in R/trace_generation.R
33
\name{layer2traces}
44
\alias{layer2traces}

man/paramORdefault.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.1.0): do not edit by hand
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
22
% Please edit documentation in R/marker_conversion.R
33
\name{paramORdefault}
44
\alias{paramORdefault}

man/plotly-package.Rd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.1.0): do not edit by hand
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
22
% Please edit documentation in R/plotly-package.r
33
\docType{package}
44
\name{plotly-package}
@@ -15,7 +15,7 @@ An example of an interactive graph made from the R API: https://plot.ly/~chris/4
1515
\itemize{
1616
\item Package: plotly
1717
\item Type: Package
18-
\item Version: 0.5.20
18+
\item Version: 0.5.30
1919
\item Date: 2014-03-07
2020
\item License: MIT
2121
}

man/plotly.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.1.0): do not edit by hand
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
22
% Please edit documentation in R/plotly.R
33
\name{plotly}
44
\alias{plotly}

man/set_config_file.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.1.0): do not edit by hand
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
22
% Please edit documentation in R/tools.R
33
\name{set_config_file}
44
\alias{set_config_file}

man/set_credentials_file.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.1.0): do not edit by hand
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
22
% Please edit documentation in R/tools.R
33
\name{set_credentials_file}
44
\alias{set_credentials_file}

man/show_config_file.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.1.0): do not edit by hand
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
22
% Please edit documentation in R/tools.R
33
\name{show_config_file}
44
\alias{show_config_file}

man/show_credentials_file.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.1.0): do not edit by hand
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
22
% Please edit documentation in R/tools.R
33
\name{show_credentials_file}
44
\alias{show_credentials_file}

man/signup.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.1.0): do not edit by hand
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
22
% Please edit documentation in R/signup.R
33
\name{signup}
44
\alias{signup}

man/toFill.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.1.0): do not edit by hand
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
22
% Please edit documentation in R/colour_conversion.R
33
\name{toFill}
44
\alias{toFill}

man/toRGB.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.1.0): do not edit by hand
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
22
% Please edit documentation in R/colour_conversion.R
33
\name{toRGB}
44
\alias{toRGB}

tests/testthat/test-cookbook-axes.R

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ expect_traces <- function(gg, n.traces, name){
88
stopifnot(is.numeric(n.traces))
99
save_outputs(gg, paste0("cookbook-axes-", name))
1010
L <- gg2list(gg)
11-
is.trace <- names(L) == ""
12-
all.traces <- L[is.trace]
11+
all.traces <- L$data
1312
no.data <- sapply(all.traces, function(tr) {
1413
is.null(tr[["x"]]) && is.null(tr[["y"]])
1514
})
1615
has.data <- all.traces[!no.data]
1716
expect_equal(length(has.data), n.traces)
18-
list(traces=has.data, kwargs=L$kwargs)
17+
list(traces=has.data, layout=L$layout)
1918
}
2019

2120
# Reverse the order of a discrete-valued axis
@@ -44,13 +43,13 @@ test_that("ylim hides points", {
4443
bp.scale.hide <- bp + scale_y_continuous(limits=c(5, 7.5))
4544
test_that("scale_y(limits) hides points", {
4645
info <- expect_traces(bp.scale.hide, 3, "scale.hide")
47-
expect_equal(info$kwargs$layout$yaxis$range, c(5, 7.5))
46+
expect_equal(info$layout$yaxis$range, c(5, 7.5))
4847
})
4948

5049
bp.coord <- bp + coord_cartesian(ylim=c(5, 7.5))
5150
test_that("Using coord_cartesian zooms into the area", {
5251
info <- expect_traces(bp.coord, 3, "coord-ylim")
53-
expect_equal(info$kwargs$layout$yaxis$range, c(5, 7.5))
52+
expect_equal(info$layout$yaxis$range, c(5, 7.5))
5453
})
5554

5655
# Create some noisy exponentially-distributed data
@@ -148,7 +147,7 @@ bp.fonts <- bp +
148147

149148
test_that("element_text face, colour, size, angle, vjust, size", {
150149
info <- expect_traces(bp.fonts, 3, "fonts")
151-
x <- info$kwargs$layout$xaxis
150+
x <- info$layout$xaxis
152151
xtitle <- x[["titlefont"]]
153152
xtick <- x[["tickfont"]]
154153
expect_identical(xtitle$color, toRGB("#990000"))

tests/testthat/test-ggplot-abline.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ test_that("Second trace be the a-b line", {
1212

1313
L <- gg2list(gg)
1414

15-
expect_equal(length(L), 3)
16-
expect_true(L[[2]]$x[1] <= 0)
17-
expect_true(L[[2]]$x[2] >= 3.5)
18-
expect_identical(L[[2]]$mode, "lines")
19-
expect_identical(L[[2]]$line$shape, "linear")
20-
expect_equal(L[[2]]$line$width, 8)
15+
expect_equal(length(L$data), 2)
16+
expect_true(L$data[[2]]$x[1] <= 0)
17+
expect_true(L$data[[2]]$x[2] >= 3.5)
18+
expect_identical(L$data[[2]]$mode, "lines")
19+
expect_identical(L$data[[2]]$line$shape, "linear")
20+
expect_equal(L$data[[2]]$line$width, 8)
2121

22-
expect_identical(L[[1]]$showlegend, FALSE)
23-
expect_identical(L[[2]]$showlegend, FALSE)
22+
expect_identical(L$data[[1]]$showlegend, FALSE)
23+
expect_identical(L$data[[2]]$showlegend, FALSE)
2424

2525
save_outputs(gg, "abline")
2626
})

tests/testthat/test-ggplot-area.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ ar <- ggplot(huron) + geom_area(aes(x=year, y=level))
77
L <- gg2list(ar)
88

99
test_that("sanity check for geom_area", {
10-
expect_equal(length(L), 2)
11-
expect_identical(L[[1]]$type, "scatter")
12-
expect_equal(L[[1]]$x, c(huron$year[1], huron$year, tail(huron$year, n=1)))
13-
expect_equal(L[[1]]$y, c(0, huron$level, 0))
14-
expect_identical(L[[1]]$line$color, "transparent")
10+
expect_equal(length(L$data), 1)
11+
expect_identical(L$data[[1]]$type, "scatter")
12+
expect_equal(L$data[[1]]$x, c(huron$year[1], huron$year, tail(huron$year, n=1)))
13+
expect_equal(L$data[[1]]$y, c(0, huron$level, 0))
14+
expect_identical(L$data[[1]]$line$color, "transparent")
1515
})
1616

1717
save_outputs(ar, "area")
@@ -21,8 +21,8 @@ gg <- ggplot(huron) + geom_area(aes(x=year, y=level), alpha=0.4)
2121
L <- gg2list(gg)
2222

2323
test_that("transparency alpha in geom_area is converted", {
24-
expect_identical(L[[1]]$line$color, "transparent")
25-
expect_identical(L[[1]]$fillcolor, "rgba(51,51,51,0.4)")
24+
expect_identical(L$data[[1]]$line$color, "transparent")
25+
expect_identical(L$data[[1]]$fillcolor, "rgba(51,51,51,0.4)")
2626
})
2727

2828
save_outputs(gg, "area-fillcolor")

0 commit comments

Comments
 (0)