有没有办法手动更改使用 rms-package 绘制的诺模图中的标签颜色?
Is there a way to manually change label colors in nomogram drawn with the rms-package?
请在下面找到我的数据样本 pp
。
问题:有没有办法改变下图列线图中被包围的标签文本的颜色?如您所见,我圈出了三个不同的部分,我想手动更改它们。
中没有找到解决方案
我的列线图:
这是用这段代码制作的
library(rms)
pp$uicc <- factor(pp$uicc,levels=c("1","2","3","4"),labels=c("1","2","3","4"))
pp$rt.kemo <- factor(pp$rt.kemo,levels=c("0","1"),labels=c("0","1"))
d <- datadist(pp)
options(datadist="d")
var.labels <- c(alder = "Age",
n.fjernet = "LNY",
uicc = "UICC Stage",
rt.kemo = "Radiochemotherapy",
mors = "mors",
os.neck = "OS")
label(pp) = lapply(names(var.labels),
function(x) label(pp[,x]) <- var.labels[x])
a <- cph(Surv(os.neck,mors)~alder+n.fjernet+uicc+rt.kemo,data=pp,surv=TRUE,x=TRUE,y=TRUE)
surv <- Survival(a)
nom <- nomogram(a, fun=list(function(x) surv(12, x),
function(x) surv(36, x),
function(x) surv(60, x)),
funlabel=c("Probability of 1 year survival",
"Probability of 3 years survival",
"Probability of 5 years survival"), lp=F)
plot(nom, xfrac=.2,
total.points.label="Sum of all points",
cex.axis = 1.05,
force.label = TRUE,
tcl = 0.8,
lmgp = 0.1,
vnames="labels",
col.grid=gray(c(0.85,0.95)))
我的数据
pp <- structure(list(alder = structure(c(58.53, 51.43, 78.5, 48.44,
68.61, 58.28, 55.06, 67.33, 86.51, 61.57, 76.98, 63.73, 63.72,
55.29, 55.34, 60.85, 60.54, 56.13, 76.09, 71.54, 80.24, 81.67,
59.49, 61.07, 58.28, 60.2, 58.57, 60, 71.95, 40.48), label = c(alder = "Age"), class = c("labelled",
"numeric")), n.fjernet = structure(c(4L, 27L, 18L, 11L, 14L,
15L, 9L, 6L, 3L, 16L, 4L, 6L, 10L, 13L, 33L, 16L, 6L, 9L, 15L,
23L, 5L, 9L, 10L, 8L, 17L, 14L, 13L, 13L, 5L, 9L), label = c(n.fjernet = "LNY"), class = c("labelled",
"integer")), uicc = structure(c(2L, 2L, 4L, 3L, 3L, 2L, 2L, 2L,
2L, 4L, 1L, 1L, 2L, 1L, 4L, 2L, 1L, 2L, 3L, 3L, 1L, 1L, 2L, 2L,
1L, 2L, 2L, 3L, 2L, 1L), .Label = c("1", "2", "3", "4"), class = c("labelled",
"factor"), label = c(uicc = "UICC Stage")), rt.kemo = structure(c(2L,
2L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 1L,
1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L), .Label = c("0",
"1"), class = c("labelled", "factor"), label = c(rt.kemo = "Radiochemotherapy")),
mors = structure(c(0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L,
0L, 0L, 1L, 1L, 0L), label = c(mors = "mors"), class = c("labelled",
"integer")), os.neck = structure(c(77.01, 75.96, 11.5, 74.38,
17.02, 7.89, 96.03, 40.48, 17.74, 14.65, 62.46, 12.55, 9.92,
26.05, 45.47, 17.38, 39.72, 51.45, 119, 8.61, 117.39, 76.98,
115.78, 67.09, 113.74, 113.22, 111.64, 94.79, 72.15, 110.23
), label = c(os.neck = "OS"), class = c("labelled", "numeric"
))), row.names = c(NA, 30L), class = "data.frame")
我不认为可以直接通过 nomogram
或 plot
完成,但总有修改一个 grob:
library(gridGraphics)
library(grid)
plot(nom, xfrac=.2,
total.points.label="Sum of all points",
cex.axis = 1.05,
force.label = TRUE,
tcl = 0.8,
lmgp = 0.1,
vnames="labels",
col.grid=gray(c(0.85,0.95)))
grid.echo()
a <- grid.grab()
要更改颜色,只需指定您想要的标签,按从上到下的顺序编号:
a$children$`graphics-plot-1-text-1`$gp$col <- "red"
a$children$`graphics-plot-1-text-2`$gp$col <- "green"
a$children$`graphics-plot-1-text-7`$gp$col <- "blue"
grid.draw(a)
最好的办法是加载 https://raw.githubusercontent.com/harrelfe/rms/master/R/plot.nomogram.s 并编辑成本地函数,例如 plotnom
,然后调用 plotnom
。
甚至更好:从 github
分叉并向 man
目录中的 R 文件及其帮助文件添加新选项,然后让我将其合并回主干。
请在下面找到我的数据样本 pp
。
问题:有没有办法改变下图列线图中被包围的标签文本的颜色?如您所见,我圈出了三个不同的部分,我想手动更改它们。
中没有找到解决方案我的列线图:
这是用这段代码制作的
library(rms)
pp$uicc <- factor(pp$uicc,levels=c("1","2","3","4"),labels=c("1","2","3","4"))
pp$rt.kemo <- factor(pp$rt.kemo,levels=c("0","1"),labels=c("0","1"))
d <- datadist(pp)
options(datadist="d")
var.labels <- c(alder = "Age",
n.fjernet = "LNY",
uicc = "UICC Stage",
rt.kemo = "Radiochemotherapy",
mors = "mors",
os.neck = "OS")
label(pp) = lapply(names(var.labels),
function(x) label(pp[,x]) <- var.labels[x])
a <- cph(Surv(os.neck,mors)~alder+n.fjernet+uicc+rt.kemo,data=pp,surv=TRUE,x=TRUE,y=TRUE)
surv <- Survival(a)
nom <- nomogram(a, fun=list(function(x) surv(12, x),
function(x) surv(36, x),
function(x) surv(60, x)),
funlabel=c("Probability of 1 year survival",
"Probability of 3 years survival",
"Probability of 5 years survival"), lp=F)
plot(nom, xfrac=.2,
total.points.label="Sum of all points",
cex.axis = 1.05,
force.label = TRUE,
tcl = 0.8,
lmgp = 0.1,
vnames="labels",
col.grid=gray(c(0.85,0.95)))
我的数据
pp <- structure(list(alder = structure(c(58.53, 51.43, 78.5, 48.44,
68.61, 58.28, 55.06, 67.33, 86.51, 61.57, 76.98, 63.73, 63.72,
55.29, 55.34, 60.85, 60.54, 56.13, 76.09, 71.54, 80.24, 81.67,
59.49, 61.07, 58.28, 60.2, 58.57, 60, 71.95, 40.48), label = c(alder = "Age"), class = c("labelled",
"numeric")), n.fjernet = structure(c(4L, 27L, 18L, 11L, 14L,
15L, 9L, 6L, 3L, 16L, 4L, 6L, 10L, 13L, 33L, 16L, 6L, 9L, 15L,
23L, 5L, 9L, 10L, 8L, 17L, 14L, 13L, 13L, 5L, 9L), label = c(n.fjernet = "LNY"), class = c("labelled",
"integer")), uicc = structure(c(2L, 2L, 4L, 3L, 3L, 2L, 2L, 2L,
2L, 4L, 1L, 1L, 2L, 1L, 4L, 2L, 1L, 2L, 3L, 3L, 1L, 1L, 2L, 2L,
1L, 2L, 2L, 3L, 2L, 1L), .Label = c("1", "2", "3", "4"), class = c("labelled",
"factor"), label = c(uicc = "UICC Stage")), rt.kemo = structure(c(2L,
2L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 1L,
1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L), .Label = c("0",
"1"), class = c("labelled", "factor"), label = c(rt.kemo = "Radiochemotherapy")),
mors = structure(c(0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L,
0L, 0L, 1L, 1L, 0L), label = c(mors = "mors"), class = c("labelled",
"integer")), os.neck = structure(c(77.01, 75.96, 11.5, 74.38,
17.02, 7.89, 96.03, 40.48, 17.74, 14.65, 62.46, 12.55, 9.92,
26.05, 45.47, 17.38, 39.72, 51.45, 119, 8.61, 117.39, 76.98,
115.78, 67.09, 113.74, 113.22, 111.64, 94.79, 72.15, 110.23
), label = c(os.neck = "OS"), class = c("labelled", "numeric"
))), row.names = c(NA, 30L), class = "data.frame")
我不认为可以直接通过 nomogram
或 plot
完成,但总有修改一个 grob:
library(gridGraphics)
library(grid)
plot(nom, xfrac=.2,
total.points.label="Sum of all points",
cex.axis = 1.05,
force.label = TRUE,
tcl = 0.8,
lmgp = 0.1,
vnames="labels",
col.grid=gray(c(0.85,0.95)))
grid.echo()
a <- grid.grab()
要更改颜色,只需指定您想要的标签,按从上到下的顺序编号:
a$children$`graphics-plot-1-text-1`$gp$col <- "red"
a$children$`graphics-plot-1-text-2`$gp$col <- "green"
a$children$`graphics-plot-1-text-7`$gp$col <- "blue"
grid.draw(a)
最好的办法是加载 https://raw.githubusercontent.com/harrelfe/rms/master/R/plot.nomogram.s 并编辑成本地函数,例如 plotnom
,然后调用 plotnom
。
甚至更好:从 github
分叉并向 man
目录中的 R 文件及其帮助文件添加新选项,然后让我将其合并回主干。