From 77d6176599a576ba25823436a36de934b129b0a8 Mon Sep 17 00:00:00 2001 From: Henry Lydecker Date: Thu, 4 Aug 2022 11:03:48 +1000 Subject: [PATCH 1/3] Make notly a package --- .Rbuildignore | 3 +++ .gitignore | 5 +++++ DESCRIPTION | 18 ++++++++++++++++++ LICENSE | 2 ++ LICENSE.md | 21 +++++++++++++++++++++ NAMESPACE | 3 +++ notly.R => R/notly.R | 11 +++++++++-- man/ggplotly.Rd | 29 +++++++++++++++++++++++++++++ notly.Rproj | 22 ++++++++++++++++++++++ 9 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 .Rbuildignore create mode 100644 .gitignore create mode 100644 DESCRIPTION create mode 100644 LICENSE create mode 100644 LICENSE.md create mode 100644 NAMESPACE rename notly.R => R/notly.R (64%) create mode 100644 man/ggplotly.Rd create mode 100644 notly.Rproj diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..cc58978 --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1,3 @@ +^notly\.Rproj$ +^\.Rproj\.user$ +^LICENSE\.md$ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7b732e7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.Rproj.user +.Rhistory +.RData +.Ruserdata +.DS_Store diff --git a/DESCRIPTION b/DESCRIPTION new file mode 100644 index 0000000..312ba5b --- /dev/null +++ b/DESCRIPTION @@ -0,0 +1,18 @@ +Package: notly +Title: What the Package Does (One Line, Title Case) +Version: 0.0.0.9000 +Authors@R: c( + person("Gordon", "McDonald", ,"gordon.mcdonald@sydney.edu.au", role = c("aut", "cre")), + person("Henry", "Lydecker", ,"henry.lydecker@gmail.com", role = c("aut")) + ) +Description: Adds the ability to turn a ggplotly object plot back into a ggplot in Plotly R. Notly has the following functions: + notly::ggplotly() which should override plotly::ggplotly() by adding the ggplot object to the output plotly object. + notly::notly() which is basically the inverse function to plotly::ggplotly(), i.e. it extracts the ggplot object back out of the plotly object. + This way if you've saved an interactive plotly object you can recover the ggplot from it for static output e.g. pdf! +License: MIT + file LICENSE +Encoding: UTF-8 +Roxygen: list(markdown = TRUE) +RoxygenNote: 7.1.2 +Imports: + plotly, + ggplot2 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e9b0b26 --- /dev/null +++ b/LICENSE @@ -0,0 +1,2 @@ +YEAR: 2022 +COPYRIGHT HOLDER: notly authors diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..0ad2361 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# MIT License + +Copyright (c) 2022 notly authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/NAMESPACE b/NAMESPACE new file mode 100644 index 0000000..d340942 --- /dev/null +++ b/NAMESPACE @@ -0,0 +1,3 @@ +# Generated by roxygen2: do not edit by hand + +export(ggplotly) diff --git a/notly.R b/R/notly.R similarity index 64% rename from notly.R rename to R/notly.R index c80f599..6280d7f 100644 --- a/notly.R +++ b/R/notly.R @@ -1,5 +1,12 @@ -library(ggplot2) -library(plotly) +#' Turn a ggplot into a plotly object +#' +#' This function takes a ggplot object and turns it into a plotly object. +#' The original ggplot object is retained inside of the new plotly object. +#' This makes this conversion reversible, allowing you to freely go back and forth betweeen ggplot and plotly. +#' +#' @param p ggplot object +#' @return Plotly object with a ggplot nested inside +#' @export ggplotly <- function( p = ggplot2::last_plot(), diff --git a/man/ggplotly.Rd b/man/ggplotly.Rd new file mode 100644 index 0000000..e24f0eb --- /dev/null +++ b/man/ggplotly.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/notly.R +\name{ggplotly} +\alias{ggplotly} +\title{Turn a ggplot into a plotly object} +\usage{ +ggplotly( + p = ggplot2::last_plot(), + width = NULL, + height = NULL, + tooltip = "all", + dynamicTicks = FALSE, + layerData = 1, + originalData = TRUE, + source = "A", + ... +) +} +\arguments{ +\item{p}{ggplot object} +} +\value{ +Plotly object with a ggplot nested inside +} +\description{ +This function takes a ggplot object and turns it into a plotly object. +The original ggplot object is retained inside of the new plotly object. +This makes this conversion reversible, allowing you to freely go back and forth betweeen ggplot and plotly. +} diff --git a/notly.Rproj b/notly.Rproj new file mode 100644 index 0000000..69fafd4 --- /dev/null +++ b/notly.Rproj @@ -0,0 +1,22 @@ +Version: 1.0 + +RestoreWorkspace: No +SaveWorkspace: No +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +AutoAppendNewline: Yes +StripTrailingWhitespace: Yes +LineEndingConversion: Posix + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source +PackageRoxygenize: rd,collate,namespace From 2243cb5ede91ace3c1672de6dbf862d1acc1717d Mon Sep 17 00:00:00 2001 From: Henry Lydecker Date: Thu, 4 Aug 2022 12:09:01 +1000 Subject: [PATCH 2/3] Add more detail to description --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 312ba5b..8a4e4f4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: notly -Title: What the Package Does (One Line, Title Case) +Title: Reversible ggplot to plotly conversion Version: 0.0.0.9000 Authors@R: c( person("Gordon", "McDonald", ,"gordon.mcdonald@sydney.edu.au", role = c("aut", "cre")), From 6ddf680ec88d5baebe19cabc6dbbf7ac554e463e Mon Sep 17 00:00:00 2001 From: Gordon McDonald Date: Thu, 4 Aug 2022 12:24:04 +1000 Subject: [PATCH 3/3] Update notly.R Add doc and export the critical notly() function --- R/notly.R | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/R/notly.R b/R/notly.R index 6280d7f..67f309f 100644 --- a/R/notly.R +++ b/R/notly.R @@ -42,6 +42,14 @@ ggplotly <- function( return(plotly_object) } +#' Turn a notly back into a ggplot object +#' +#' This function takes a notly object (plotly with embedded ggplot) and turns it into a ggplot object. +#' It is the inverse function to `ggplotly()`, allowing you to freely go back and forth betweeen ggplot and plotly. +#' +#' @param notly_object notly object +#' @return ggplot object +#' @export notly <- function(notly_object){ notly_object$ggplot }