The g2
function generally accepts a data.frame
or tibble
but can also accept other types of objects, as shown in the graph vignettes where it works on objects of class igraph
.
These functions use the to_g2r
method internally to obtain an object that the package can process and serialise to JSON, this is generally a tibble
at the exception of the edge case. This function is exported so one can observe which variables will be made available to use in asp()
for the various figures.
For instance, running to_g2r
on an object of class loess
returns the following tibble
.
data(mpg, package = "ggplot2")
smooth <- loess(hwy ~ displ, data = mpg, span = .3)
to_g2r(smooth) %>%
head() %>%
knitr::kable()
hwy | displ | .fitted | .resid | .se | .lower | .upper |
---|---|---|---|---|---|---|
29 | 1.8 | 31.71733 | -2.7173342 | 0.5788917 | 31.13844 | 32.29623 |
29 | 1.8 | 31.71733 | -2.7173342 | 0.5788917 | 31.13844 | 32.29623 |
31 | 2.0 | 29.48387 | 1.5161318 | 0.5951880 | 28.88868 | 30.07906 |
30 | 2.0 | 29.48387 | 0.5161318 | 0.5951880 | 28.88868 | 30.07906 |
26 | 2.8 | 23.52388 | 2.4761238 | 0.7294572 | 22.79442 | 24.25333 |
26 | 2.8 | 23.52388 | 2.4761238 | 0.7294572 | 22.79442 | 24.25333 |
library(quantmod)
aapl <- getSymbols("AAPL", env=NULL)
g2(aapl, asp(x, open = AAPL.Open, close = AAPL.Close)) %>%
fig_candle(asp(high = AAPL.High, low = AAPL.Low))
library(quantmod)
rate <- getFX("EUR/CHF", auto.assign = FALSE)
g2(rate, asp(x, EUR.CHF)) %>%
fig_line()
library(survival)
data(veteran)
km_fit <- survfit(Surv(time, status) ~ trt, data = veteran)
g2(km_fit, asp(time, color = "strata", shape = "vh")) %>%
fig_line(asp(y = estimate)) %>%
fig_ribbon(asp(ymin = conf.low, ymax = conf.high)) %>%
fig_point(asp(y = n.censor.y, shape = "circle"), stroke = "black")
cc <- acf(lh, plot = FALSE)
g2(cc) %>%
fig_interval(asp(lag, acf, size = 2))
correl_mat <- cor(mtcars)
g2(correl_mat) %>%
fig_polygon(asp(Var1, Var2, color = Freq)) %>%
gauge_color(c("#fae0e4", "#ff85a1", "#ff0a54"))
g2(volcano) %>%
fig_polygon(asp(Var1, Var2, color = Freq)) %>%
gauge_color(c("#ffba08", "#dc2f02", "#03071e"))