我知道功能ggplotly()的的plotly包转换ggplot2对象成plotly一个,而是有没有做相反的功能?将一个plotly对象转换为一个对象ggplot2?
男孩,我有办法给你吗!
我们编写了一个包来执行此操作。它被称为notly.
安装:
# install.packages("devtools")
devtools::install_github("gdmcdonald/notly")
Run Code Online (Sandbox Code Playgroud)
用法示例:
library(ggplot2)
library(plotly)
library(notly)
data(iris)
# Create a ggplot
ggplot_object <-
iris %>%
ggplot(aes(x = Sepal.Length,
y = Sepal.Width,
color = Species))+
geom_point()
# Create a plotly object - but with the ggplot hiding inside of it as well
notly_obj <-
ggplot_object %>%
ggplotly
notly_obj
# Extract the ggplot again
ggplot_obj_again <-
notly_obj %>%
notly
ggplot_obj_again
Run Code Online (Sandbox Code Playgroud)