From 63e0ddbb5698b11a6e28c21f427abdd70ca168c4 Mon Sep 17 00:00:00 2001 From: Carson Sievert Date: Wed, 13 Jul 2016 15:54:58 -0500 Subject: [PATCH] curse you cbind --- R/layers2traces.R | 2 +- R/plotly_data.R | 1 + man/plotly_data.Rd | 46 ---------------------------------------------- 3 files changed, 2 insertions(+), 47 deletions(-) diff --git a/R/layers2traces.R b/R/layers2traces.R index 3686fc2153..a7a00f2967 100644 --- a/R/layers2traces.R +++ b/R/layers2traces.R @@ -645,7 +645,7 @@ ribbon_dat <- function(dat) { tmp <- dat[o, ] others <- tmp[not_used] dat1 <- cbind(x = tmp$x, y = tmp$ymin, others) - dat1[n+1, ] <- cbind(x = tmp$x[n], y = tmp$ymin[n], others[n, ]) + dat1[n+1, ] <- data.frame(x = tmp$x[n], y = tmp$ymin[n], others[n, ]) # bottom-half of ribbon tmp2 <- dat[o2, ] others2 <- tmp2[not_used] diff --git a/R/plotly_data.R b/R/plotly_data.R index a5abfd757e..929ff0a2ed 100644 --- a/R/plotly_data.R +++ b/R/plotly_data.R @@ -8,6 +8,7 @@ #' @param id a character string or number referencing an "attribute layer". #' @return returns a data frame #' @examples +#' @export #' #' # use group_by() to define groups of visual markings #' p <- txhousing %>% diff --git a/man/plotly_data.Rd b/man/plotly_data.Rd index 064ed70362..ebb1e55f83 100644 --- a/man/plotly_data.Rd +++ b/man/plotly_data.Rd @@ -19,50 +19,4 @@ returns a data frame a plotly visualization (if there are multiple data frames, by default, it returns the most recent one). } -\examples{ - -# use group_by() to define groups of visual markings -p <- txhousing \%>\% - group_by(city) \%>\% - plot_ly(x = ~date, y = ~sales) -p - -# plotly objects preserve data groupings -groups(p) -plotly_data(p) - -# dplyr verbs operate on plotly objects as if they were data frames -p <- economics \%>\% - plot_ly(x = ~date, y = ~unemploy / pop) \%>\% - add_lines() \%>\% - mutate(rate = unemploy / pop) \%>\% - filter(rate == max(rate)) -plotly_data(p) -add_markers(p) -layout(p, annotations = list(x = ~date, y = ~rate, text = "peak")) - -# use group_by() + do() + subplot() for trellis displays -d <- group_by(mpg, drv) -plots <- do(d, p = plot_ly(., x = ~cty, name = ~drv)) -subplot(plots[["p"]], nrows = 3, shareX = TRUE) - -# arrange displays by their mean -means <- summarise(d, mn = mean(cty, na.rm = TRUE)) -means \%>\% - left_join(plots) \%>\% - arrange(mn) \%>\% - .[["p"]] \%>\% - subplot(nrows = NROW(.), shareX = TRUE) - -# more dplyr verbs applied to plotly objects -p <- mtcars \%>\% - plot_ly(x = ~wt, y = ~mpg, name = "scatter trace") \%>\% - add_markers() -p \%>\% slice(1) \%>\% plotly_data() -p \%>\% slice(1) \%>\% add_markers(name = "first observation") -p \%>\% filter(cyl == 4) \%>\% plotly_data() -p \%>\% filter(cyl == 4) \%>\% add_markers(name = "four cylinders") - - -}