r - 使用 ggparty 仅在终端节点中绘制重要的预测线
问题描述
我正在使用ggparty 包来可视化基于线性模型的树的结果。一般来说,我认为这与包作者提供的示例代码很好地配合:
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")
但是,现在我只想在找到的关系显着(p<0.05)时才在终端节点中绘制预测线。此外,最好在各个终端节点图中绘制线性关系的R2和p 值。
如果我需要提供有关此问题的更多信息,请告诉我。预先感谢您的帮助!
解决方案
推荐阅读
- jquery - 单击父级,然后单击子级事件
- node.js - Safari 仅保存一个“Set-Cookie”标头
- excel - 错误 - 运行时错误 9“下标超出范围”
- python - Python/HTML:如何将 csv 文件写入 sheet.html?
- hybris - Hybris commerce - 站点用户组的产品限制和类别限制
- chart.js - ChartJS 画布未在边缘浏览器中显示颜色
- api - 谷歌应用程序脚本静默无法发布,卷曲工作
- python - 熊猫用第一个可用值的拆分填充 nan 值
- npm - NPM 包如何保证长期正确性?
- python - 访问 Pandas DataFrame 元素中的列表并对列表求和