ggghost: Capture the Spirit of Your 'ggplot2' Calls

> library(ggghost)

バージョン: 0.2.0


関数名 概略
%g<% Begin constructing a ggghost cache
+.gg Add a New ggplot Component to a ggghost Object
-.gg Remove a Call from a ggghost Object
ggghost ggghost: Capture the spirit of your ggplot calls
is.ggghost Reports Whether x is a ggghost Object
print.ggghost Collect ggghost Calls and Produce the ggplot Output
reanimate Bring a ggplot to Life (re-animate)
recover_data Recover Data Stored in a ggghost Object
subset.ggghost Extract a Subset of a ggghost Object
summary.ggghost List the Calls Contained in a ggghost Object

%g<%

> tmpdata <- data.frame(x = 1:100, y = rnorm(100))
> z %g<% ggplot(tmpdata, aes(x, y))
> summary(z)
[[1]]
ggplot(tmpdata, aes(x, y))
> z <- z + geom_point(col = "steelblue")
> z <- z + theme_bw()
> z <- z + labs(title = "My cool ggplot")
> z <- z + labs(x = "x axis", y = "y axis")
> z <- z + geom_smooth()
> summary(z)
[[1]]
ggplot(tmpdata, aes(x, y))

[[2]]
geom_point(col = "steelblue")

[[3]]
theme_bw()

[[4]]
labs(title = "My cool ggplot")

[[5]]
labs(x = "x axis", y = "y axis")

[[6]]
geom_smooth()
> summary(z, combine = TRUE)
[1] "ggplot(tmpdata, aes(x, y)) + geom_point(col = \"steelblue\") + theme_bw() + labs(title = \"My cool ggplot\") + labs(x = \"x axis\", y = \"y axis\") + geom_smooth()"
> subset(z, c(1,2,6))
Warning: ggghostbuster: no supplementary data found

plot of chunk unnamed-chunk-3

> z2 <- z + geom_line(col = "coral")
> z2 - geom_point()
Warning: ggghostbuster: no supplementary data found

plot of chunk unnamed-chunk-3

reanimate

レイヤーが追加されていく様子をgifアニメーションで生成

> reanimate(z, "mycoolplot.gif")

recover_data

> rm(tmpdata)
> ls()
[1] "mytext"   "sql_expr" "z"        "z2"
> recover_data(z)
Warning: ggghostbuster: no supplementary data found
> ls()
[1] "mytext"   "sql_expr" "tmpdata"  "z"        "z2"
> head(tmpdata)
  x          y
1 1  0.6963711
2 2 -1.0535444
3 3  0.1460046
4 4 -0.9324614
5 5 -1.5770553
6 6 -0.2497717