legend

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

legend

R Kozarski
Hi,
there is a function to plot survival curves:

library(survival)
plot.KM <- function(survival, x, x_cut.off, main='', label='')
{
plot(survfit(survival ~ I(x >= x_cut.off)), main=main)
legend('bottomleft', c(expression(label >= x_cut.off),expression(label < x_cut.off)))
}

Now, I need to determine as the argument what appears in the legend. I want
plot.KM(survival, x, x_cut.off=0.5, main='', label='ABC')
but what I get is ('label < x_cut.off') in legend instead of 'ABC<0.5'. Symbol '>=' should be in mathematical form. will appreciate any help.

robert

Reply | Threaded
Open this post in threaded view
|

Re: legend

David Winsemius

On Sep 22, 2010, at 1:39 PM, threshold wrote:

>
> Hi,
> there is a function to plot survival curves:
>
> library(survival)
> plot.KM <- function(survival, x, x_cut.off, main='', label='')
> {
> plot(survfit(survival ~ I(x >= x_cut.off)), main=main)
> legend('bottomleft', c(expression(label >=  
> x_cut.off),expression(label <
> x_cut.off)))
> }

This is untested because "survival" is not an object for the rest of  
us to survfit:

plot.KM <- function(survival, x, x_cut.off, main='', label='')
{
#really kind of worried about whether this part will work, but perhaps  
you already have this running?
plot(survfit(survival ~ I(x >= x_cut.off)), main=main)
#####
## perhaps something like this ... untested d/t no data example
legend('bottomleft',
        labels= bquote( .(label)>=.(x_cut.off),
                        .(label)<.(x_cut.off) ) )
}

(And if you have made such a Surv object, perhaps naming it something  
other than the package name would be less confusing to us ordinary  
mortals.)

-- David.



>
> Now, I need to determine as the argument what appears in the legend.  
> I want
> plot.KM(survival, x, x_cut.off=0.5, main='', label='ABC')
> but what I get is ('label < x_cut.off') in legend instead of  
> 'ABC<0.5'.
> Symbol '>=' should be in mathematical form. will appreciate any help.
>
> robert
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/legend-tp2550747p2550747.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: legend

David Winsemius

On Sep 22, 2010, at 2:58 PM, David Winsemius wrote:

>
> On Sep 22, 2010, at 1:39 PM, threshold wrote:
>
>>
>> Hi,
>> there is a function to plot survival curves:
>>
>> library(survival)
>> plot.KM <- function(survival, x, x_cut.off, main='', label='')
>> {
>> plot(survfit(survival ~ I(x >= x_cut.off)), main=main)
>> legend('bottomleft', c(expression(label >=  
>> x_cut.off),expression(label <
>> x_cut.off)))
>> }
>
> This is untested because "survival" is not an object for the rest of  
> us to survfit:
>
> plot.KM <- function(survival, x, x_cut.off, main='', label='')
> {
> #really kind of worried about whether this part will work, but  
> perhaps you already have this running?
> plot(survfit(survival ~ I(x >= x_cut.off)), main=main)
> #####
> ## perhaps something like this ... untested d/t no data example
> legend('bottomleft',
>       labels= bquote( .(label)>=.(x_cut.off),
>       ^^no^^          .(label)<.(x_cut.off) ) )
(labels is a argument to text() but not to legend().


That should be :
  legend('bottomleft',
       legend= bquote( .(label)>=.(x_cut.off),
                       .(label)<.(x_cut.off) ) )


> }
>
> (And if you have made such a Surv object, perhaps naming it  
> something other than the package name would be less confusing to us  
> ordinary mortals.)
>
> -- David.
>
>
>
>>
>> Now, I need to determine as the argument what appears in the  
>> legend. I want
>> plot.KM(survival, x, x_cut.off=0.5, main='', label='ABC')
>> but what I get is ('label < x_cut.off') in legend instead of  
>> 'ABC<0.5'.
>> Symbol '>=' should be in mathematical form. will appreciate any help.
>>
>> robert
>>
>


David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: legend

David Winsemius

On Sep 22, 2010, at 3:03 PM, David Winsemius wrote:

>
> On Sep 22, 2010, at 2:58 PM, David Winsemius wrote:
>
>>
>> On Sep 22, 2010, at 1:39 PM, threshold wrote:
>>
>>>
>>> Hi,
>>> there is a function to plot survival curves:
>>>
>>> library(survival)
>>> plot.KM <- function(survival, x, x_cut.off, main='', label='')
>>> {
>>> plot(survfit(survival ~ I(x >= x_cut.off)), main=main)
>>> legend('bottomleft', c(expression(label >=  
>>> x_cut.off),expression(label <
>>> x_cut.off)))
>>> }
>>
>> This is untested because "survival" is not an object for the rest  
>> of us to survfit:
>>
>> plot.KM <- function(survival, x, x_cut.off, main='', label='')
>> {
>> #really kind of worried about whether this part will work, but  
>> perhaps you already have this running?
>> plot(survfit(survival ~ I(x >= x_cut.off)), main=main)
>> #####
>> ## perhaps something like this ... untested d/t no data example
>> legend('bottomleft',
>>      labels= bquote( .(label)>=.(x_cut.off),
>>      ^^no^^          .(label)<.(x_cut.off) ) )
> (labels is a argument to text() but not to legend().
>
>
> That should be :
> legend('bottomleft',
>      legend= bquote( .(label)>=.(x_cut.off),
>                      .(label)<.(x_cut.off) ) )

Or not:

I stripped out the suspect fitting and plotting with unreproducible  
code and worked on a more simple function and the above does not work:

plot.KM <- function(survival, x, x_cut.off, main='', label='')
{ plot(1~1, main=main);\
  L= list(bquote(.(label) >= .(x_cut.off)), bquote(.(label) < .
(x_cut.off) ) )
legend('bottomleft', legend=sapply(L, as.expression))
}

The sapply strategy on a list of bquote()-ed expressions was suggested  
by Gabor Grothendieck to Thomas Lumley on rhelp in 2005 for just such  
an application.

http://finzi.psych.upenn.edu/R/Rhelp02/archive/58403.html
--
David.

>
>
>> }
>>
>> (And if you have made such a Surv object, perhaps naming it  
>> something other than the package name would be less confusing to us  
>> ordinary mortals.)
>>
>> -- David.
>>
>>
>>
>>>
>>> Now, I need to determine as the argument what appears in the  
>>> legend. I want
>>> plot.KM(survival, x, x_cut.off=0.5, main='', label='ABC')
>>> but what I get is ('label < x_cut.off') in legend instead of  
>>> 'ABC<0.5'.
>>> Symbol '>=' should be in mathematical form. will appreciate any  
>>> help.
>>>
>>> robert
>>>
>>
>
>
> David Winsemius, MD
> West Hartford, CT
>

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: legend

R Kozarski
Thanks David, works fine!
robert