this is a follow up to a previously asked, related question: data and code are here error message when ploting subjects at risk with survplot
When trying to plot the subjects at risk below the survplot, the table either overlaps with the labels of the x - axis or does not appear on the plot (in the example below one line is missing; totalps=4). How to solve this issue?
From the documentation to the survplot command, I understand that I may have to reset the margins of the plot with the par command (e.g. par(mar=c(5,4,4,2)+.1).) I don't understand how to include this par command into survplot.
Furthermore, there is considerable space between the lines of the table on the subjects at risk. Is there any direct way to reduce this space?
Here the code for the plot:
library(rms)
pdf(plot1.pdf)
survplot(KM.Duration.totalps[-1],
xlab="duration in months", ylab="survival prob",
conf="none",
label.curves=list(method="arrow", cex=0.8),
time.inc=12,
col=c(1:4),
levels.only = FALSE,
n.risk=TRUE,
y.n.risk = -0.3, cex.n.risk = 0.6
)
dev.off()
Simply reading the help page:
sep.n.risk
multiple of upper y limit - lower y limit for separating lines of text containing number of subjects at risk. Default is .056*(ylim[2]-ylim[1]).
And some par functions are best used with par just prior to the plot call (but after the pdf() call), so:
pdf(...)
par( mar=c(7,4,4,2)+.1) ) # adds two lines to default space along bottom margin
survplot(...