| 1 |
### Demonstrate tree |
| 2 |
|
| 3 |
if (require(tree)) { |
| 4 |
require(ggplot2) |
| 5 |
require(MASS) |
| 6 |
data(cpus, package = "MASS") |
| 7 |
cpus.ltr <- tree(log10(perf) ~ syct + mmin + mmax + cach + chmin + chmax, |
| 8 |
data = cpus) |
| 9 |
tree_data <- dendro_data(cpus.ltr) |
| 10 |
ggplot(segment(tree_data)) + |
| 11 |
geom_segment(aes(x = x, y = y, xend = xend, yend = yend, linewidth = n), |
| 12 |
colour = "lightblue" |
| 13 |
) + |
| 14 |
scale_size("n") + |
| 15 |
geom_text( |
| 16 |
data = label(tree_data), |
| 17 |
aes(x = x, y = y, label = label), vjust = -0.5, size = 4 |
| 18 |
) + |
| 19 |
geom_text( |
| 20 |
data = leaf_label(tree_data), |
| 21 |
aes(x = x, y = y, label = label), vjust = 0.5, size = 3 |
| 22 |
) + |
| 23 |
theme_dendro() |
| 24 |
} |