# 安装包
if (!requireNamespace("data.table", quietly = TRUE)) {
install.packages("data.table")
}
if (!requireNamespace("jsonlite", quietly = TRUE)) {
install.packages("jsonlite")
}
if (!requireNamespace("rms", quietly = TRUE)) {
install.packages("rms")
}
if (!requireNamespace("ggplotify", quietly = TRUE)) {
install.packages("ggplotify")
}
# 加载包
library(data.table)
library(jsonlite)
library(rms)
library(ggplotify)诺莫图 (逻辑回归)
注记
Hiplot 网站
本页面为 Hiplot Nomogram (Logistic) 插件的源码版本教程,您也可以使用 Hiplot 网站实现无代码绘图,更多信息请查看以下链接:
环境配置
系统: Cross-platform (Linux/MacOS/Windows)
编程语言: R
依赖包:
data.table;jsonlite;rms;ggplotify
sessioninfo::session_info("attached")─ Session info ───────────────────────────────────────────────────────────────
setting value
version R version 4.5.2 (2025-10-31)
os Ubuntu 24.04.3 LTS
system x86_64, linux-gnu
ui X11
language (EN)
collate C.UTF-8
ctype C.UTF-8
tz UTC
date 2026-01-28
pandoc 3.1.3 @ /usr/bin/ (via rmarkdown)
quarto 1.8.27 @ /usr/local/bin/quarto
─ Packages ───────────────────────────────────────────────────────────────────
package * version date (UTC) lib source
data.table * 1.18.0 2025-12-24 [1] RSPM
ggplotify * 0.1.3 2025-09-20 [1] RSPM
Hmisc * 5.2-5 2026-01-09 [1] RSPM
jsonlite * 2.0.0 2025-03-27 [1] RSPM
rms * 8.1-0 2025-10-14 [1] RSPM
[1] /home/runner/work/_temp/Library
[2] /opt/R/4.5.2/lib/R/site-library
[3] /opt/R/4.5.2/lib/R/library
* ── Packages attached to the search path.
──────────────────────────────────────────────────────────────────────────────
数据准备
# 加载数据
data <- data.table::fread(jsonlite::read_json("https://hiplot.cn/ui/basic/nomogram-logistic/data.json")$exampleData$textarea[[1]])
data <- as.data.frame(data)
# 整理数据格式
dd <- datadist(data)
options(datadist = "dd")
## 建立 Logistic 模型并运行列线图
logistic_res <- lrm(data=data, as.formula(paste(
colnames(data)[1], " ~ ",
paste(colnames(data)[2:length(colnames(data))],
collapse = "+"
)
))
)
logistic_nomo <- nomogram(logistic_res, maxscale = 100,
fun= function(x)1/(1+exp(-x)), lp=F, funlabel="Dead Risk",
fun.at=c(.001,.01,.05,seq(.1,.9,by=.1),.95,.99,.999)
)
# 查看数据
head(data) status age sex ph.ecog ph.karno pat.karno meal.cal wt.loss
1 2 74 1 1 90 100 1175 NA
2 2 68 1 0 90 90 1225 15
3 1 56 1 0 90 90 NA 15
4 2 57 1 1 90 60 1150 11
5 2 60 1 0 100 90 NA 0
6 1 74 1 1 50 80 513 0
可视化
# 诺莫图 (逻辑回归)
p <- as.ggplot(function() {
plot(logistic_nomo,
scale = 1
)
title(main = "Nomogram (Logistic)")
})
p
