Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gglogger is an R package that logs the calls used to create ggplot2 objects.

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
NotificationsYou must be signed in to change notification settings

pwwang/gglogger

Repository files navigation

gglogger is an R package that logs the calls used to createggplot2 objects.

This can be useful for debugging, reproducibility, and understanding the sequence of operations used to build a plot.

Have you ever created a plot inggplot2 and then forgotten how you made it? Or wanted to reproduce a plot but couldn't remember the exact sequence of operations you used?gglogger can help!

Installation

You can install thegglogger package from source usingdevtools:

devtools::install_github("pwwang/gglogger")# orremotes::install_github("pwwang/gglogger")

Usage

To use thegglogger package, simply load it along withggplot2 and create your plots as usual. The package will automatically log the calls used to create the plots.

PreviousNow
library(ggplot2)p<- ggplot(mpg, aes(x=displ,y=hwy))+    geom_point()
library(ggplot2)# Just add gglogger after ggplot2library(gglogger)p<- ggplot(mpg, aes(x=displ,y=hwy))+    geom_point()# Print the logsprint(p$logs)## ggplot2::ggplot(mpg, aes(x = displ, y = hwy)) +##   geom_point()

Evaluate the code in logs to reproduce the plot:

p$logs$evaluate()

You can also attach the variables in an environment for evaluation:

env<- new.env()env$mpg<-mpgenv$mpg$hwy<-mpg$hwy/2p$logs$evaluate(env)

Registering a function from a ggplot2 extension

library(dplyr)library(gglogger)mtcars_radar<-mtcars %>%  as_tibble(rownames="group") %>%  mutate_at(vars(-group),scales::rescale) %>%  tail(4) %>%  select(1:10)ggradar<- register(ggradar::ggradar)p<- ggradar(mtcars_radar,legend.position="right")print(p$logs)# ggradar::ggradar(mtcars_radar, legend.position = "right")

Generating code to reproduce a plot

# p is a ggradar plot created in the previous examplecode<-p$logs$gen_code(setup='library(dplyr)library(ggradar)mtcars_radar <- mtcars %>%  as_tibble(rownames = "group") %>%  mutate_at(vars(-group), scales::rescale) %>%  tail(4) %>%  select(1:10)')cat(code)## library(dplyr)## library(ggradar)#### mtcars_radar <- mtcars %>%##   as_tibble(rownames = "group") %>%##   mutate_at(vars(-group), scales::rescale) %>%##   tail(4) %>%##   select(1:10)###### ggradar::ggradar(mtcars_radar, legend.position = "right")# eval(parse(text = code)) # to reproduce the plot

Limitations

gglogger cannot log the global settings used to create a plot, such astheme_set(). It can only log the calls used directly to create the plot itself. You may need to manually set these global settings when reproducing a plot, or prepare them using thesetup argument ingen_code().

If your data is piped toggplot function, you need to use|> instead of%>%, otherwise the data will be logged as..

About

gglogger is an R package that logs the calls used to create ggplot2 objects.

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp