diff --git a/.push_test_table.sh b/.push_test_table.sh index 2b332dfc13..138afcfdd2 100644 --- a/.push_test_table.sh +++ b/.push_test_table.sh @@ -38,6 +38,7 @@ git checkout gh-pages mv ../code_commits.csv . cat code_commits.csv +touch table.R make # add, commit, push to gh-pages branch of plotly-test-table diff --git a/DESCRIPTION b/DESCRIPTION index 77aef2f5cf..04e93d0c83 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: plotly Type: Package Title: Interactive, publication-quality graphs online. -Version: 0.5.23 +Version: 0.5.24 Authors@R: c(person("Chris", "Parmer", role = c("aut", "cre"), email = "chris@plot.ly"), person("Scott", "Chamberlain", role = "aut", @@ -13,7 +13,9 @@ Authors@R: c(person("Chris", "Parmer", role = c("aut", "cre"), person("Marianne", "Corvellec", role="aut", email="marianne@plot.ly"), person("Pedro", "Despouy", role="aut", - email="pedro@plot.ly")) + email="pedro@plot.ly"), + person("Carson", "Sievert", role="aut", + email="cpsievert1@gmail.com")) Author: Chris Parmer Maintainer: Marianne Corvellec License: MIT + file LICENSE diff --git a/NAMESPACE b/NAMESPACE index dc6b9f52c4..50bca0d434 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,4 +1,4 @@ -# Generated by roxygen2 (4.0.2): do not edit by hand +# Generated by roxygen2 (4.1.0): do not edit by hand export(gg2list) export(ggplot_build2) diff --git a/NEWS b/NEWS index 7ee806cf25..2c9b1b110c 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +0.5.24 -- 10 March 2015 + +Implemented #167 + 0.5.23 -- 10 March 2015. geom_ribbon now respects alpha transparency diff --git a/R/ggplotly.R b/R/ggplotly.R index 67622ba3ad..bab347df2d 100644 --- a/R/ggplotly.R +++ b/R/ggplotly.R @@ -26,20 +26,25 @@ ribbon.line.defaults$colour <- NA polygon.line.defaults <- line.defaults polygon.line.defaults$colour <- NA -aesConverters <- list(linetype=function(lty) { - lty2dash[as.character(lty)] - }, - colour=function(col) { - toRGB(col) - }, - size=identity, - sizeref=identity, - sizemode=identity, - alpha=identity, - shape=function(pch) { - pch2symbol[as.character(pch)] - }, - direction=identity) +# Convert R lty line type codes to plotly "dash" codes. +lty2dash <- c(numeric.lty, named.lty, coded.lty) + +aesConverters <- list( + linetype=function(lty) { + lty2dash[as.character(lty)] + }, + colour=function(col) { + toRGB(col) + }, + size=identity, + sizeref=identity, + sizemode=identity, + alpha=identity, + shape=function(pch) { + pch2symbol[as.character(pch)] + }, + direction=identity +) markLegends <- # NOTE: Do we also want to split on size? @@ -173,6 +178,9 @@ gg2list <- function(p){ gglayout <- built$panel$layout # invert rows so that plotly and ggplot2 show panels in the same order gglayout$plotly.row <- max(gglayout$ROW) - gglayout$ROW + 1 + # ugh, ggplot counts panel right-to-left & top-to-bottom + # plotly count them right-to-left & *bottom-to-top* + gglayout$plotly.panel <- with(gglayout, order(plotly.row, COL)) # Add ROW and COL to df: needed to link axes to traces; keep df's # original ordering while merging. @@ -180,7 +188,7 @@ gg2list <- function(p){ df <- merge(df, gglayout[, c("PANEL", "plotly.row", "COL")]) df <- df[order(df$order),] df$order <- NULL - + prestats <- built$prestats.data[[i]] # scale_reverse multiples x/y data by -1, so here we undo that so # that the actual data can be uploaded to plotly. @@ -204,7 +212,7 @@ gg2list <- function(p){ misc$prestats.data$globsizemin <- ggsizemin misc$prestats.data$globsizemax <- ggsizemax } - + # This extracts essential info for this geom/layer. traces <- layer2traces(L, df, misc) @@ -217,7 +225,7 @@ gg2list <- function(p){ # built$panel$ranges[[1]]) trace.list <- c(trace.list, traces) } - + # for barcharts, verify that all traces have the same barmode; we don't # support different barmodes on the same plot yet. barmodes <- do.call(c, lapply(trace.list, function (x) x$barmode)) @@ -278,12 +286,12 @@ gg2list <- function(p){ grid <- theme.pars$panel.grid grid.major <- theme.pars$panel.grid.major if ((!is.null(grid$linetype) || !is.null(grid.major$linetype)) && - c(grid$linetype, grid.major$linetype) %in% c(2, 3, "dashed", "dotted")) { + c(grid$linetype, grid.major$linetype) %in% c(2, 3, "dashed", "dotted")) { ax.list$gridcolor <- ifelse(is.null(grid.major$colour), - toRGB(grid$colour, 0.1), - toRGB(grid.major$colour, 0.1)) + toRGB(grid$colour, 0.1), + toRGB(grid.major$colour, 0.1)) } else { - ax.list$gridcolor <- toRGB(grid.major$colour) + ax.list$gridcolor <- toRGB(grid.major$colour) } ax.list$showgrid <- !is.blank(s("panel.grid.major.%s")) @@ -388,117 +396,138 @@ gg2list <- function(p){ outer.margin <- 0.05 # to put titles outside of the plots orig.xaxis <- layout$xaxis orig.yaxis <- layout$yaxis - if (nrow(gglayout) > 1) - { - row.size <- 1. / max(gglayout$ROW) - col.size <- 1. / max(gglayout$COL) - for (i in seq_len(nrow(gglayout))) - { - row <- gglayout[i, "plotly.row"] - col <- gglayout[i, "COL"] - x <- col * col.size - xmin <- x - col.size - xmax <- x - inner.margin - y <- row * row.size - ymin <- y - row.size - ymax <- y - inner.margin - if ("wrap" %in% class(p$facet)) - ymax <- ymax - 0.04 - yaxis.name <- if (row == 1) "yaxis" else paste0("yaxis", row) - xaxis.name <- if (col == 1) "xaxis" else paste0("xaxis", col) - layout[[xaxis.name]] <- orig.xaxis - layout[[xaxis.name]]$domain <- c(xmin, xmax) - layout[[xaxis.name]]$anchor <- "y" - layout[[xaxis.name]]$title <- NULL - if (orig.xaxis$type == "linear" && # range only makes sense for numeric data - (is.null(p$facet$scales) || p$facet$scales == "fixed" || p$facet$scales == "free_y")) - { - layout[[xaxis.name]]$range <- built$panel$ranges[[i]]$x.range - layout[[xaxis.name]]$autorange <- FALSE - } - - layout[[yaxis.name]] <- orig.yaxis - layout[[yaxis.name]]$domain <- c(ymin, ymax) - layout[[yaxis.name]]$anchor <- "x" - layout[[yaxis.name]]$title <- NULL - if (orig.yaxis$type == "linear" && # range only makes sense for numeric data - (is.null(p$facet$scales) || p$facet$scales == "fixed" || p$facet$scales == "free_x")) - { - layout[[yaxis.name]]$range <- built$panel$ranges[[i]]$y.range - layout[[yaxis.name]]$autorange <- FALSE - } - + if (nrow(gglayout) > 1) { + row.size <- 1. / max(gglayout$ROW) + col.size <- 1. / max(gglayout$COL) + npanels <- nrow(gglayout) + for (i in seq_len(npanels)) { + row <- gglayout[i, "plotly.row"] + col <- gglayout[i, "COL"] + panel <- gglayout[i, "plotly.panel"] + x <- col * col.size + xmin <- x - col.size + xmax <- x - inner.margin + y <- row * row.size + ymin <- y - row.size + ymax <- y - inner.margin + # assume grid layout by default where axes are restrict to the exterior + xaxis.name <- if (col == 1) "xaxis" else paste0("xaxis", col) + yaxis.name <- if (row == 1) "yaxis" else paste0("yaxis", row) + # anchor needs to be incremented if the corresponding axis is "free" + xanchor <- "y" + yanchor <- "x" + if ("wrap" %in% class(p$facet)) { + # in wrap layout, axes can be drawn on interior (if scales are free) + # make room for facet strip label + ymax <- ymax - 0.04 + # make room for yaxis labels (this should be a function of label size) + if (col == 1) { + xmax <- xmax - 0.02 + } else { + xmin <- xmin + 0.02 } - # add panel titles as annotations - annotations <- list() + # make room for xaxis labels + if (row == 1) { + ymax <- ymax - 0.02 + } else { + ymin <- ymin + 0.02 + } + if (p$facet$free$y && panel > 1) { + # draw a y-axis on each panel + yaxis.name <- paste0("yaxis", panel) + trace.list[[i]]$yaxis <- paste0("y", panel) + yanchor <- if (p$facet$free$x) paste0("x", panel) else paste0("x",col) + } + if (p$facet$free$x && panel > 1) { + # draw an x-axis on each panel + xaxis.name <- paste0("xaxis", panel) + trace.list[[i]]$xaxis <- paste0("x", panel) + xanchor <- if (p$facet$free$y) paste0("y", panel) else paste0("y",row) + } + } + layout[[xaxis.name]] <- orig.xaxis + layout[[xaxis.name]]$domain <- c(xmin, xmax) + layout[[xaxis.name]]$anchor <- xanchor + layout[[xaxis.name]]$title <- NULL + layout[[yaxis.name]] <- orig.yaxis + layout[[yaxis.name]]$domain <- c(ymin, ymax) + layout[[yaxis.name]]$anchor <- yanchor + layout[[yaxis.name]]$title <- NULL + if (is.null(layout[[xaxis.name]]$anchor)) + layout[[xaxis.name]]$anchor <- "y" + if (is.null(layout[[yaxis.name]]$anchor)) + layout[[yaxis.name]]$anchor <- "x" + # range only makes sense for numeric data + if (orig.xaxis$type == "linear") { + layout[[xaxis.name]]$range <- built$panel$ranges[[i]]$x.range + layout[[xaxis.name]]$autorange <- FALSE + } + if (orig.yaxis$type == "linear") { + layout[[yaxis.name]]$range <- built$panel$ranges[[i]]$y.range + layout[[yaxis.name]]$autorange <- FALSE + } + } + # add panel titles as annotations + annotations <- list() + nann <- 1 + make.label <- function(text, x, y, xanchor="auto", yanchor="auto", textangle=0) + list(text=text, showarrow=FALSE, x=x, y=y, ax=0, ay=0, + xref="paper", yref="paper", xanchor=xanchor, yanchor=yanchor, + textangle=textangle) + if ("grid" %in% class(p$facet)) { + frows <- names(p$facet$rows) nann <- 1 - make.label <- function(text, x, y, xanchor="auto", yanchor="auto", textangle=0) - list(text=text, showarrow=FALSE, x=x, y=y, ax=0, ay=0, - xref="paper", yref="paper", xanchor=xanchor, yanchor=yanchor, - textangle=textangle) - if ("grid" %in% class(p$facet)) - { - frows <- names(p$facet$rows) - nann <- 1 - - for (i in seq_len(max(gglayout$ROW))) - { - text <- paste(lapply(gglayout[gglayout$ROW == i, frows, drop=FALSE][1,], - as.character), - collapse=", ") - if (text != "") { # to not create extra annotations - increase_margin_r <- TRUE - annotations[[nann]] <- make.label(text, - 1 + outer.margin - 0.04, - row.size * (max(gglayout$ROW)-i+0.5), - xanchor="center", - textangle=90) - nann <- nann + 1 - } - } - - fcols <- names(p$facet$cols) - for (i in seq_len(max(gglayout$COL))) - { - text <- paste(lapply(gglayout[gglayout$COL == i, fcols, drop=FALSE][1,], - as.character), - collapse=", ") - if (text!="") { - annotations[[nann]] <- make.label(text, - col.size * (i-0.5) - inner.margin/2, - 1 + outer.margin, - xanchor="center") - nann <- nann + 1 - } - } - - # add empty traces everywhere so that the background shows even if there - # is no data for a facet - for (r in seq_len(max(gglayout$ROW))) - for (c in seq_len(max(gglayout$COL))) - trace.list <- c(trace.list, list(list(xaxis=paste0("x", c), yaxis=paste0("y", r), showlegend=FALSE))) + for (i in seq_len(max(gglayout$ROW))) { + text <- paste(lapply(gglayout[gglayout$ROW == i, frows, drop=FALSE][1,], + as.character), + collapse=", ") + if (text != "") { # to not create extra annotations + increase_margin_r <- TRUE + annotations[[nann]] <- make.label(text, + 1 + outer.margin - 0.04, + row.size * (max(gglayout$ROW)-i+0.5), + xanchor="center", + textangle=90) + nann <- nann + 1 } - else if ("wrap" %in% class(p$facet)) - { - facets <- names(p$facet$facets) - for (i in seq_len(max(as.numeric(gglayout$PANEL)))) - { - ix <- gglayout$PANEL == i - row <- gglayout$ROW[ix] - col <- gglayout$COL[ix] - text <- paste(lapply(gglayout[ix, facets, drop=FALSE][1,], - as.character), - collapse=", ") - annotations[[nann]] <- make.label(text, - col.size * (col-0.5) - inner.margin/2, - row.size * (max(gglayout$ROW) - row + 0.985), - xanchor="center", - yanchor="top") - nann <- nann + 1 - } - } - + } + fcols <- names(p$facet$cols) + for (i in seq_len(max(gglayout$COL))) { + text <- paste(lapply(gglayout[gglayout$COL == i, fcols, drop=FALSE][1,], + as.character), + collapse=", ") + if (text!="") { + annotations[[nann]] <- make.label(text, + col.size * (i-0.5) - inner.margin/2, + 1 + outer.margin, + xanchor="center") + nann <- nann + 1 + } + } + + # add empty traces everywhere so that the background shows even if there + # is no data for a facet + for (r in seq_len(max(gglayout$ROW))) + for (c in seq_len(max(gglayout$COL))) + trace.list <- c(trace.list, list(list(xaxis=paste0("x", c), yaxis=paste0("y", r), showlegend=FALSE))) + } else if ("wrap" %in% class(p$facet)) { + facets <- names(p$facet$facets) + for (i in seq_len(max(as.numeric(gglayout$PANEL)))) { + ix <- gglayout$PANEL == i + row <- gglayout$ROW[ix] + col <- gglayout$COL[ix] + text <- paste(lapply(gglayout[ix, facets, drop=FALSE][1,], + as.character), + collapse=", ") + annotations[[nann]] <- make.label(text, + col.size * (col-0.5) - inner.margin/2, + row.size * (max(gglayout$ROW) - row + 0.985), + xanchor="center", + yanchor="top") + nann <- nann + 1 + } + } # axes titles annotations[[nann]] <- make.label(xaxis.title, 0.5, @@ -509,9 +538,8 @@ gg2list <- function(p){ -outer.margin, 0.5, textangle=-90) - - layout$annotations <- annotations - } + layout$annotations <- annotations + } # Remove legend if theme has no legend position layout$showlegend <- !(theme.pars$legend.position=="none") @@ -531,7 +559,6 @@ gg2list <- function(p){ layout$legend <- list(bordercolor="transparent", x=1.05, y=1/2, xanchor="center", yanchor="top") - # Workaround for removing unnecessary legends. # [markUnique != "x"] is for boxplot's particular case. if (any(names(layer.aes) %in% markUnique[markUnique != "x"]) == FALSE) @@ -566,7 +593,7 @@ gg2list <- function(p){ legend.title <- colnames(p$data)[i] } legend.title <- paste0("", legend.title, "") - + # Create legend title element as an annotation if (exists("annotations")) { nann <- nann + 1 @@ -583,7 +610,7 @@ gg2list <- function(p){ textangle=0) layout$annotations <- annotations } - + # Family font for text if (!is.null(theme.pars$text$family)) { layout$titlefont$family <- theme.pars$text$family @@ -652,7 +679,7 @@ gg2list <- function(p){ } } } - + # If background elements are NULL, and background rect (rectangle) is defined: rect_fill <- theme.pars$rect$fill if (!is.null(rect_fill)) { @@ -667,7 +694,7 @@ gg2list <- function(p){ if (length(trace.list) == 0) { stop("No exportable traces") } - + mode.mat <- matrix(NA, 3, 3) rownames(mode.mat) <- colnames(mode.mat) <- c("markers", "lines", "none") mode.mat["markers", "lines"] <- @@ -714,7 +741,7 @@ gg2list <- function(p){ } merged.traces[[length(merged.traces)+1]] <- tr } - + # Put the traces in correct order, according to any manually # specified scales. This seems to be repetitive with the trace$rank # attribute in layer2traces (which is useful for sorting traces that @@ -733,7 +760,7 @@ gg2list <- function(p){ }else{ merged.traces } - + # Translate scale(labels) to trace name. named.traces <- ordered.traces for(trace.i in seq_along(named.traces)){ @@ -765,7 +792,7 @@ gg2list <- function(p){ flipped.layout[["xaxis"]] <- y flipped.layout[["yaxis"]] <- x } - + flipped.traces$kwargs <- list(layout=flipped.layout) flipped.traces diff --git a/man/ensure_file_exist.Rd b/man/ensure_file_exist.Rd new file mode 100644 index 0000000000..ab1c577a2f --- /dev/null +++ b/man/ensure_file_exist.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/tools.R +\name{ensure_file_exist} +\alias{ensure_file_exist} +\title{Create file if nonexistent} +\usage{ +ensure_file_exist(abspath) +} +\arguments{ +\item{abspath}{Character vector of file path} +} +\description{ +Create file if nonexistent +} + diff --git a/man/get_config_file.Rd b/man/get_config_file.Rd new file mode 100644 index 0000000000..55de20aa9e --- /dev/null +++ b/man/get_config_file.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/tools.R +\name{get_config_file} +\alias{get_config_file} +\title{Read Plotly config file (which is a JSON) and create one if nonexistent} +\usage{ +get_config_file(args = c()) +} +\arguments{ +\item{args}{Character vector of keys you are looking up} +} +\value{ +List of keyword-value pairs (config) +} +\description{ +Read Plotly config file (which is a JSON) and create one if nonexistent +} +\examples{ +\dontrun{ +get_config_file(c("plotly_domain", "plotly_streaming_domain")) +} +} + diff --git a/man/get_credentials_file.Rd b/man/get_credentials_file.Rd new file mode 100644 index 0000000000..4c3178d002 --- /dev/null +++ b/man/get_credentials_file.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/tools.R +\name{get_credentials_file} +\alias{get_credentials_file} +\title{Read Plotly credentials file (which is a JSON)} +\usage{ +get_credentials_file(args = c()) +} +\arguments{ +\item{args}{Character vector of keys you are looking up} +} +\value{ +List of keyword-value pairs (credentials) +} +\description{ +Read Plotly credentials file (which is a JSON) +} +\examples{ +\dontrun{ +get_credentials_file(c("username", "api_key")) +} +} + diff --git a/man/gg2list.Rd b/man/gg2list.Rd index c3080229a6..67016d2a0d 100644 --- a/man/gg2list.Rd +++ b/man/gg2list.Rd @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/ggplotly.R \name{gg2list} \alias{gg2list} \title{Convert a ggplot to a list.} diff --git a/man/ggplot_build2.Rd b/man/ggplot_build2.Rd index 5125cfff1d..a37efa75c4 100644 --- a/man/ggplot_build2.Rd +++ b/man/ggplot_build2.Rd @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/build_function.R \name{ggplot_build2} \alias{ggplot_build2} \title{ggplot build function with enhanced return} diff --git a/man/group2NA.Rd b/man/group2NA.Rd index faeb97f3f8..c1114f4c35 100644 --- a/man/group2NA.Rd +++ b/man/group2NA.Rd @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/trace_generation.R \name{group2NA} \alias{group2NA} \title{Drawing ggplot2 geoms with a group aesthetic is most efficient in diff --git a/man/layer2traces.Rd b/man/layer2traces.Rd index b0e80b9bf0..d57083fe5b 100644 --- a/man/layer2traces.Rd +++ b/man/layer2traces.Rd @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/trace_generation.R \name{layer2traces} \alias{layer2traces} \title{Convert a layer to a list of traces. Called from gg2list()} diff --git a/man/paramORdefault.Rd b/man/paramORdefault.Rd index 491d3cbcd9..c0cb1cb457 100644 --- a/man/paramORdefault.Rd +++ b/man/paramORdefault.Rd @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/marker_conversion.R \name{paramORdefault} \alias{paramORdefault} \title{Convert ggplot params to plotly.} diff --git a/man/plotly-package.Rd b/man/plotly-package.Rd index 91ca574ac1..2643bf2dd2 100644 --- a/man/plotly-package.Rd +++ b/man/plotly-package.Rd @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/plotly-package.r \docType{package} \name{plotly-package} \alias{plotly-package} @@ -14,7 +15,7 @@ An example of an interactive graph made from the R API: https://plot.ly/~chris/4 \itemize{ \item Package: plotly \item Type: Package - \item Version: 0.3.4 + \item Version: 0.5.20 \item Date: 2014-03-07 \item License: MIT } diff --git a/man/plotly.Rd b/man/plotly.Rd index 6119c5a751..0c4db5bd35 100644 --- a/man/plotly.Rd +++ b/man/plotly.Rd @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/plotly.R \name{plotly} \alias{plotly} \title{Main interface to plotly} diff --git a/man/set_config_file.Rd b/man/set_config_file.Rd index 59fde04bbf..d37aaf672b 100644 --- a/man/set_config_file.Rd +++ b/man/set_config_file.Rd @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/tools.R \name{set_config_file} \alias{set_config_file} \title{Set keyword-value pairs in Plotly config file} diff --git a/man/set_credentials_file.Rd b/man/set_credentials_file.Rd index 3f398d1e18..b5145446c8 100644 --- a/man/set_credentials_file.Rd +++ b/man/set_credentials_file.Rd @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/tools.R \name{set_credentials_file} \alias{set_credentials_file} \title{Set the keyword-value pairs in Plotly credentials file} diff --git a/man/show_config_file.Rd b/man/show_config_file.Rd index 178dbab4a9..1f781075f7 100644 --- a/man/show_config_file.Rd +++ b/man/show_config_file.Rd @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/tools.R \name{show_config_file} \alias{show_config_file} \title{Read and print Plotly config file, wrapping get_credentials_file()} diff --git a/man/show_credentials_file.Rd b/man/show_credentials_file.Rd index e4c2072311..70a9bda657 100644 --- a/man/show_credentials_file.Rd +++ b/man/show_credentials_file.Rd @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/tools.R \name{show_credentials_file} \alias{show_credentials_file} \title{Read and print Plotly credentials file, wrapping get_credentials_file()} diff --git a/man/signup.Rd b/man/signup.Rd index 226094019d..577d1d1c5d 100644 --- a/man/signup.Rd +++ b/man/signup.Rd @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/signup.R \name{signup} \alias{signup} \title{Sign up to plotly.} diff --git a/man/toFill.Rd b/man/toFill.Rd index abc71b77ec..05e3f49dff 100644 --- a/man/toFill.Rd +++ b/man/toFill.Rd @@ -1,12 +1,15 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/colour_conversion.R \name{toFill} \alias{toFill} \title{Use default ggplot colour for fill (gray20) if not declared} \usage{ -toFill(x) +toFill(x, alpha = 1) } \arguments{ \item{x}{character for colour} + +\item{alpha}{transparency alpha} } \value{ hexadecimal colour value diff --git a/man/toRGB.Rd b/man/toRGB.Rd index c0cac1536c..5e75af9c0b 100644 --- a/man/toRGB.Rd +++ b/man/toRGB.Rd @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/colour_conversion.R \name{toRGB} \alias{toRGB} \title{Convert R colours to RGBA hexadecimal colour values} @@ -8,7 +9,7 @@ toRGB(x, alpha = 1) \arguments{ \item{x}{character for colour, for example: "white"} -\item{alpha}{alpha} +\item{alpha}{transparency alpha} } \value{ hexadecimal colour value (if is.na(x), return "transparent" for compatibility with Plotly) diff --git a/tests/testthat/test-facets.R b/tests/testthat/test-facets.R deleted file mode 100644 index 5ea8414484..0000000000 --- a/tests/testthat/test-facets.R +++ /dev/null @@ -1,49 +0,0 @@ -context("Facets") - -# test_that("6 facets becomes 6 panels", { -# require(lattice) -# gg <- qplot(yield, variety, data=barley, color=year, facets=site~., pch=I(1))+ -# theme_bw()+ -# theme(panel.margin=grid::unit(0, "cm")) -# info <- gg2list(gg) -# traces <- info[names(info)==""] -# trace.axes <- list() -# for(N in c("xaxis", "yaxis")){ -# trace.axes[[N]] <- axes.vec <- -# sapply(traces, function(t){ -# if(N %in% names(t)){ -# t[[N]] -# }else{ -# NA -# } -# }) -# expect_true(all(!is.na(axes.vec))) -# } -# trace.axes.df <- as.data.frame(trace.axes) -# u <- unique(trace.axes.df) -# expect_identical(nrow(u), 6L) -# }) - -test_that("3 facets becomes 3 panels", { - df <- data.frame(x=runif(99), y=runif(99), z=rep(c('a','b','c'), 33)) - gg <- qplot(x, y, data=df, facets=z~., pch=I(1))+ - theme_bw()+ - theme(panel.margin=grid::unit(0, "cm")) - info <- gg2list(gg) - traces <- info[names(info)==""] - trace.axes <- list() - for(N in c("xaxis", "yaxis")){ - trace.axes[[N]] <- axes.vec <- - sapply(traces, function(t){ - if(N %in% names(t)){ - t[[N]] - }else{ - NA - } - }) - expect_true(all(!is.na(axes.vec))) - } - trace.axes.df <- as.data.frame(trace.axes) - u <- unique(trace.axes.df) - expect_identical(nrow(u), 3L) -}) diff --git a/tests/testthat/test-ggplot-facets.R b/tests/testthat/test-ggplot-facets.R new file mode 100644 index 0000000000..e39575f853 --- /dev/null +++ b/tests/testthat/test-ggplot-facets.R @@ -0,0 +1,100 @@ +context("Facets") + +# test_that("6 facets becomes 6 panels", { +# require(lattice) +# gg <- qplot(yield, variety, data=barley, color=year, facets=site~., pch=I(1))+ +# theme_bw()+ +# theme(panel.margin=grid::unit(0, "cm")) +# info <- gg2list(gg) +# traces <- info[names(info)==""] +# trace.axes <- list() +# for(N in c("xaxis", "yaxis")){ +# trace.axes[[N]] <- axes.vec <- +# sapply(traces, function(t){ +# if(N %in% names(t)){ +# t[[N]] +# }else{ +# NA +# } +# }) +# expect_true(all(!is.na(axes.vec))) +# } +# trace.axes.df <- as.data.frame(trace.axes) +# u <- unique(trace.axes.df) +# expect_identical(nrow(u), 6L) +# }) + +test_that("3 facets becomes 3 panels", { + df <- data.frame(x=runif(99), y=runif(99), z=rep(c('a','b','c'), 33)) + gg <- qplot(x, y, data=df, facets=z~., pch=I(1))+ + theme_bw()+ + theme(panel.margin=grid::unit(0, "cm")) + info <- gg2list(gg) + traces <- info[names(info)==""] + trace.axes <- list() + for(N in c("xaxis", "yaxis")){ + trace.axes[[N]] <- axes.vec <- + sapply(traces, function(t){ + if(N %in% names(t)){ + t[[N]] + }else{ + NA + } + }) + expect_true(all(!is.na(axes.vec))) + } + trace.axes.df <- as.data.frame(trace.axes) + u <- unique(trace.axes.df) + expect_identical(nrow(u), 3L) +}) + +# expect a certain number of _unique_ [x/y] axes +expect_axes <- function(info, n, axis = "x") { + pattern <- paste0("^", axis, "axis([0-9]+)?$") + axes <- with(info$kwargs, layout[grepl(pattern, names(layout))]) + n.axes <- length(axes) + ranges <- do.call("rbind", lapply(axes, function(x) x$range)) + expect_identical(nrow(unique(ranges)), as.integer(n)) +} + +no_panels <- ggplot(mtcars, aes(mpg, wt)) + geom_point() + +test_that("facet_wrap(..., scales = 'free') creates interior scales", { + free_both <- no_panels + facet_wrap(~am+vs, scales = "free") + save_outputs(free_both, "facet_wrap_free") + info <- gg2list(free_both) + expect_axes(info, 4L) + expect_axes(info, 4L, "y") + + free_y <- no_panels + facet_wrap(~am+vs, scales = "free_y") + save_outputs(free_y, "facet_wrap_free_y") + info <- gg2list(free_y) + expect_axes(info, 1L) + expect_axes(info, 4L, "y") + + free_x <- no_panels + facet_wrap(~am+vs, scales = "free_x") + save_outputs(free_x, "facet_wrap_free_x") + info <- gg2list(free_x) + expect_axes(info, 4L) + expect_axes(info, 1L, "y") +}) + +test_that("facet_grid(..., scales = 'free') doesnt create interior scales.", { + free_both <- no_panels + facet_grid(vs~am, scales = "free") + save_outputs(free_both, "facet_grid_free") + info <- gg2list(free_both) + expect_axes(info, 2L) + expect_axes(info, 2L, "y") + + free_y <- no_panels + facet_grid(vs~am, scales = "free_y") + save_outputs(free_y, "facet_grid_free_y") + info <- gg2list(free_y) + expect_axes(info, 1L) + expect_axes(info, 2L, "y") + + free_x <- no_panels + facet_grid(vs~am, scales = "free_x") + save_outputs(free_x, "facet_grid_free_x") + info <- gg2list(free_x) + expect_axes(info, 2L) + expect_axes(info, 1L, "y") +})