Please, find my data sample pp
below.
Question: is there a way to change the color of the encircled label text in the nomogram shown below? As you can see, I encircled three different parts which I would like to change manually.
I have not found a solution by looking in the r-documentation
My nomogram:
Which has been made with this code
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)))
My data
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")
I don't think it can be done directly via nomogram
or plot
, but there's always modifying a 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()
To change colors simply specify the label you want, numbered in order from top to bottom:
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)