使用ggparty仅在终端节点中绘制有效预测线

使用ggparty仅在终端节点中绘制有效预测线,r,R,我使用的是从基于线性模型的树中可视化结果。总的来说,我认为这与包的作者提供的示例代码配合得很好: library(ggparty) data("iris") #load iris dataset data=iris formula = as.formula(paste("Sepal.Length~Sepal.Width", paste(colnames(data)[-which(colnames(data) %in% c("Sepal.Len

我使用的是从基于线性模型的树中可视化结果。总的来说,我认为这与包的作者提供的示例代码配合得很好:

library(ggparty)

data("iris") #load iris dataset
data=iris

formula = as.formula(paste("Sepal.Length~Sepal.Width", paste(colnames(data)[-which(colnames(data) %in% c("Sepal.Length","Sepal.Width"))], collapse=" + "), sep=" | ")) # creating a formula

lmtree <- lmtree(formula, data = data) #tree based on linear model

#plot example code provided in the package description (https://cran.r-project.org/web/packages/ggparty/ggparty.pdf)
ggparty(lmtree,
        terminal_space = 0.4,
        add_vars = list(p.value = "$node$info$p.value")) +
  geom_edge(size = 1) +
  geom_edge_label(colour = "grey", size = 5) +
  geom_node_plot(gglist = list(geom_point(aes(x = Sepal.Width,
                                              y = Sepal.Length),
  alpha = 0.5),
  theme_bw(base_size = 12)),
  scales = "fixed",
  ids = "terminal",
  shared_axis_labels = T,
  shared_legend = T,
  legend_separator = T,
  predict = "Sepal.Width",
  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 = 10, col = "black", fontface = "bold"),
                                   list(size = 12),
                                   list(size = 10)),
                  ids = "inner") +
  geom_node_label(aes(label = paste0("Node ", id, ", N = ", nodesize)),
                  fontface = "bold",
                  ids = "terminal",
                  size = 4, 
                  nudge_y = 0.01) +
  theme(legend.position = "none")
库(ggparty)
数据(“iris”)#加载iris数据集
数据=虹膜
公式=as.formula(粘贴(“萼片长度~萼片宽度”)、粘贴(colnames(数据)[-which(colnames(数据)%in%c(“萼片长度”、“萼片宽度”)))、collapse=“+”、sep=“|”)创建公式
树