Description Usage Arguments Details See Also Examples
View source: R/geom_node_label.R
geom_node_splitvar()
and geom_node_info()
are simplified versions of
geom_node_label()
with the respective defaults to either label the split variables
for all inner nodes or the info for all terminal nodes.
1 2 3 4 5 6 7 8 9 10 11 12 | geom_node_label(mapping = NULL, data = NULL, line_list = NULL,
line_gpar = NULL, ids = NULL, position = "identity", ...,
parse = FALSE, nudge_x = 0, nudge_y = 0,
label.padding = unit(0.25, "lines"), label.r = unit(0.15, "lines"),
label.size = 0.25, label.col = NULL, label.fill = NULL,
na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
geom_node_info(mapping = NULL, nudge_x = 0, nudge_y = 0,
ids = NULL, label.padding = unit(0.5, "lines"), ...)
geom_node_splitvar(mapping = NULL, nudge_x = 0, nudge_y = 0,
label.padding = unit(0.5, "lines"), ids = NULL, ...)
|
mapping |
|
data |
The data to be displayed in this layer. There are three options: If A A |
line_list |
Use this only if you want a multi-line label with the
possibility to override the aesthetics mapping for each line specifically
with fixed graphical parameters. In this case, don't map anything to
|
line_gpar |
List of lists containing line-specific graphical parameters.
Only use in
conjunction with |
ids |
Select for which nodes to draw a label. Can be |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
... |
Additional arguments to layer. |
parse |
If |
nudge_x, nudge_y |
Adjust position of label. |
label.padding |
Amount of padding around label. Defaults to 0.25 lines. |
label.r |
Radius of rounded corners. Defaults to 0.15 lines. |
label.size |
Size of label border, in mm. |
label.col |
Border colour. |
label.fill |
Background colour. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
geom_node_label()
is a modified version of ggplot2::geom_label()
. This
modification allows for labels with multiple lines and line specific graphical
parameters.
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | 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")
######################################
data("TeachingRatings", package = "AER")
tr <- subset(TeachingRatings, credits == "more")
tr_tree <- lmtree(eval ~ beauty | minority + age + gender + division + native +
tenure, data = tr, weights = students, caseweights = FALSE)
data("TeachingRatings", package = "AER")
tr <- subset(TeachingRatings, credits == "more")
tr_tree <- lmtree(eval ~ beauty | minority + age + gender + division + native +
tenure, data = tr, weights = students, caseweights = FALSE)
ggparty(tr_tree,
terminal_space = 0.5,
add_vars = list(p.value = "$node$info$p.value")) +
geom_edge(size = 1.5) +
geom_edge_label(colour = "grey", size = 6) +
geom_node_plot(gglist = list(geom_point(aes(x = beauty,
y = eval,
col = tenure,
shape = minority),
alpha = 0.8),
theme_bw(base_size = 15)),
scales = "fixed",
id = "terminal",
shared_axis_labels = TRUE,
shared_legend = TRUE,
legend_separator = TRUE,
predict = "beauty",
predict_gpar = list(col = "blue",
size = 1.2)
) +
geom_node_label(aes(col = splitvar),
line_list = list(aes(label = paste("Node", id)),
aes(label = splitvar),
aes(label = paste("p =", formatC(p.value,
format = "e", digits = 2)))),
line_gpar = list(list(size = 12, col = "black", fontface = "bold"),
list(size = 20),
list(size = 12)),
ids = "inner") +
geom_node_label(aes(label = paste0("Node ", id, ", N = ", nodesize)),
fontface = "bold",
ids = "terminal",
size = 5,
nudge_y = 0.01) +
theme(legend.position = "none")
|
sh: 1: cannot create /dev/null: Permission denied
Loading required package: ggplot2
sh: 1: cannot create /dev/null: Permission denied
Loading required package: partykit
Loading required package: grid
Loading required package: libcoin
Loading required package: mvtnorm
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.