Description Usage Arguments See Also Examples
View source: R/geom_node_plot.R
Additional component for a ggparty()
that allows to create in each node a
ggplot with its data. #'
1 2 3 4 5 |
plot_call |
Any function that generates a |
gglist |
List of additional |
width |
Expansion factor for viewport's width. |
height |
Expansion factor for viewport's height. |
size |
Expansion factor for viewport's size. |
ids |
Id's to plot. Numeric, "terminal", "inner" or "all". Defaults to "terminal". |
scales |
See |
nudge_x, nudge_y |
Nudges node plot. |
shared_axis_labels |
If TRUE only one pair of axes labels is plotted in
the terminal space. Only recommended if |
shared_legend |
If |
predict |
Character string specifying variable for which predictions should be plotted. |
predict_gpar |
Named list containing arguments to be passed to the
|
legend_separator |
If |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | library(ggparty)
airq <- subset(airquality, !is.na(Ozone))
airct <- ctree(Ozone ~ ., data = airq)
ggparty(airct, horizontal = TRUE, terminal_space = 0.6) +
geom_edge() +
geom_edge_label() +
geom_node_splitvar() +
geom_node_plot(gglist = list(
geom_density(aes(x = Ozone))),
shared_axis_labels = TRUE)
#############################################################
## Plot with ggparty
## Demand for economics journals data
data("Journals", package = "AER")
Journals <- transform(Journals,
age = 2000 - foundingyear,
chars = charpp * pages)
## linear regression tree (OLS)
j_tree <- lmtree(log(subs) ~ log(price/citations) | price + citations +
age + chars + society, data = Journals, minsize = 10, verbose = TRUE)
pred_df <- get_predictions(j_tree, ids = "terminal", newdata = function(x) {
data.frame(
citations = 1,
price = exp(seq(from = min(x$`log(price/citations)`),
to = max(x$`log(price/citations)`),
length.out = 100)))
})
ggparty(j_tree, terminal_space = 0.8) +
geom_edge() +
geom_edge_label() +
geom_node_splitvar() +
geom_node_plot(gglist =
list(aes(x = `log(price/citations)`, y = `log(subs)`),
geom_point(),
geom_line(data = pred_df,
aes(x = log(price/citations),
y = prediction),
col = "red")))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.