ggparty: Create a new ggparty plot

Description Usage Arguments Details See Also Examples

View source: R/ggparty.R

Description

ggplot2 extension for objects of class party. Creates a data.frame from an object of class party and calls ggplot()

Usage

1
2
ggparty(party, horizontal = FALSE, terminal_space, layout = NULL,
  add_vars = NULL)

Arguments

party

Object of class party.

horizontal

If TRUE plot will be horizontal.

terminal_space

Proportion of the plot that should be reserved for the terminal nodeplots. Defaults to 2 / (depth(party) + 2).

layout

Optional layout adjustment. Overwrites the coordinates of the specified nodes. Must be data.frame containing the columns id, x and y. With x and y values between 0 and 1.

add_vars

Named list containing either string(s) specifying the locations of elements to be extracted from each node of party or function(s) of corresponding row of plot data and node. In either case returned object has to be of length 1. If the data is supposed to be accessible by geom_node_plot() the respective list entry has to be named with the prefix "nodedata_" and be a function returning a list of same length as nodesize.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
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")

Example output

Loading required package: ggplot2
Loading required package: partykit
Loading required package: grid
Loading required package: libcoin
Loading required package: mvtnorm

ggparty documentation built on July 18, 2019, 5:04 p.m.