Skip to content

Commit

Permalink
Merge pull request #1 from hlydecker/main
Browse files Browse the repository at this point in the history
Make notly a package
  • Loading branch information
gdmcdonald authored Aug 4, 2022
2 parents 138516c + 6ddf680 commit 67ce24b
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 40 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
^notly\.Rproj$
^\.Rproj\.user$
^LICENSE\.md$
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
.DS_Store
18 changes: 18 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Package: notly
Title: Reversible ggplot to plotly conversion
Version: 0.0.0.9000
Authors@R: c(
person("Gordon", "McDonald", ,"[email protected]", role = c("aut", "cre")),
person("Henry", "Lydecker", ,"[email protected]", 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
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YEAR: 2022
COPYRIGHT HOLDER: notly authors
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Generated by roxygen2: do not edit by hand

export(ggplotly)
55 changes: 55 additions & 0 deletions R/notly.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#' 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(),
width = NULL,
height = NULL,
tooltip = "all",
dynamicTicks = FALSE,
layerData = 1,
originalData = TRUE,
source = "A",
...
){
#make plotly object
plotly_object <- plotly::ggplotly(
p = p,
width = width,
height = height,
tooltip = tooltip,
dynamicTicks = dynamicTicks,
layerData = layerData,
originalData = originalData,
source = source,
...
)

#append ggplot
plotly_object$ggplot <- p

#append notly class
class(plotly_object) <- append(class(plotly_object), "notly")

#return object
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
}
29 changes: 29 additions & 0 deletions man/ggplotly.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 0 additions & 40 deletions notly.R

This file was deleted.

22 changes: 22 additions & 0 deletions notly.Rproj
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 67ce24b

Please sign in to comment.