That's right. You cannot delete items from a plot made with base graphics. If you are succeeding with lines
then that's excellent evidence that plot.cuminc
is using base graphics. Base graphics is not like ggplot2 graphics. There is no "awareness" or "object-orientation" that makes it easy to bolt in a new component when an extra line was added. You probably need to suppress the first legend with curvlab=NA
and then build a legend from scratch with the added annotation. Post a working code example, perhaps using one of the datasets or examples in cmprsk
.
How can I add a legend after I used lines()
-
30-07-2022 - |
Question
first I make a CIF plot :
cmprsk:::plot.cuminc(forplot,ylim=c(0, 0.04),curvlab="CIF",main="Curves for Failure Hematologic P=(0:1) ")
then I add a 1-km curve
fitcs1=survfit(Surv(hem_free, hem_censor2)~1)
lines(fitcs1,fun='event',lty=2:3,lwd=0.5,mark.time=FALSE,legend="e") #"event" plots cumulative events (f(y) = 1-y)
I am wondering why there is no legend for the 1-KM curve
I tried to use legend("topleft",c("1-KM curve"),lty=2:3,lwd=0.5)
but I can't delete the label I had from my first plot.
I will be very appropriated if you can help me out!
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow