ggparty {ggparty} | R Documentation |
Create a new ggparty plot
Description
ggplot2
extension for objects of class party
. Creates a data.frame
from
an object of class party
and calls ggplot()
Usage
ggparty(party, horizontal = FALSE, terminal_space, layout = NULL,
add_vars = NULL)
Arguments
party |
Object of class |
horizontal |
If |
terminal_space |
Proportion of the plot that should be reserved for
the terminal nodeplots. Defaults to |
layout |
Optional layout adjustment. Overwrites the coordinates of the
specified nodes. Must be |
add_vars |
Named list containing either string(s) specifying the locations
of elements to be extracted from
each node of |
Details
ggparty
can be called directly with an object of class party
, which will
convert it to a suitable data.frame
and pass it to a call to ggplot
with as
the data
argument. As usual, additional components can then be added with
+
.
The nodes will be spaced equally in the unit square. Specifying
terminal_size
allows to increase or decrease the area for plots of the
terminal nodes.
If one of the list entries supplied to add_vars
is a function, it has to take
exactly two arguments,
namely data
(the corresponding row of the plot_data data frame) and node
(the corresponding node, i.e. party_object[i]
)
See Also
geom_edge()
, geom_edge_label()
, geom_node_label()
,
autoplot.party()
, geom_node_plot()
Examples
library(ggparty)
data("WeatherPlay", package = "partykit")
sp_o <- partysplit(1L, index = 1:3)
sp_h <- partysplit(3L, breaks = 75)
sp_w <- partysplit(4L, index = 1:2)
pn <- partynode(1L, split = sp_o, kids = list(
partynode(2L, split = sp_h, kids = list(
partynode(3L, info = "yes"),
partynode(4L, info = "no"))),
partynode(5L, info = "yes"),
partynode(6L, split = sp_w, kids = list(
partynode(7L, info = "yes"),
partynode(8L, info = "no")))))
py <- party(pn, WeatherPlay)
ggparty(py) +
geom_edge() +
geom_edge_label() +
geom_node_label(aes(label = splitvar),
ids = "inner") +
geom_node_label(aes(label = info),
ids = "terminal")