-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from hlydecker/main
Make notly a package
- Loading branch information
Showing
10 changed files
with
158 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
^notly\.Rproj$ | ||
^\.Rproj\.user$ | ||
^LICENSE\.md$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.RData | ||
.Ruserdata | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
YEAR: 2022 | ||
COPYRIGHT HOLDER: notly authors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(ggplotly) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |