Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linetype is not vectorized #45

Closed
MarcinKosinski opened this issue May 30, 2016 · 6 comments
Closed

linetype is not vectorized #45

MarcinKosinski opened this issue May 30, 2016 · 6 comments

Comments

@MarcinKosinski
Copy link
Contributor

Dear Marcin

I have a question about the survminer package. I am new to R, and not sure where to ask questions, I hope you can help or redirect me.

Expected behavior

I have a survival object based on 6 groups. The following code creates 6 survival curves with ggsurvplot.

ggsurvplot (my_surv_groups, palette = c(1,1,2,1,2,2), linetype = 1)

I can change the color of each line individual – but not the linetype? I thought I could write:

ggsurvplot (my_surv_groups, palette = c(1,1,2,1,2,2),linetype = c(1,1,2,1,2,2))

Actual behavior

However, this creates an error:

Error: Aesthetics must be either length 1 or the same as the data (53): size, linetype 

In addition: Warning message:

In if (value %in% columns) { :

  the condition has length > 1 and only the first element will be used

Can you explain me why “linetype” do not work in the same way as “palette”

Steps to reproduce the problem

library(survminer)

library(survival)

lung$fake_groups <- sample(1:6, size = nrow(lung), replace = TRUE)
fit<- survfit(Surv(time, status) ~ fake_groups, data = lung)


ggsurvplot(fit, palette = c(1,1,2,1,2,2),linetype = c(1,1,2,1,2,2))

session_info()

# please paste here the result of
devtools::session_info()
> devtools::session_info()
Session info -------------------------------------------------------
 setting  value                       
 version  R version 3.3.0 (2016-05-03)
 system   x86_64, linux-gnu           
 ui       RStudio (0.99.879)          
 language English                     
 collate  pl_PL.UTF-8                 
 tz       <NA>                        
 date     2016-05-30                  

Packages -----------------------------------------------------------
 package    * version   date       source        
 colorspace   1.2-6     2015-03-11 CRAN (R 3.3.0)
 devtools     1.11.1    2016-04-21 CRAN (R 3.3.0)
 digest       0.6.9     2016-01-08 CRAN (R 3.3.0)
 ggplot2    * 2.1.0     2016-03-01 CRAN (R 3.3.0)
 gtable       0.2.0     2016-02-26 CRAN (R 3.3.0)
 labeling     0.3       2014-08-23 CRAN (R 3.3.0)
 lattice      0.20-33   2015-07-14 CRAN (R 3.2.1)
 magrittr     1.5       2014-11-22 CRAN (R 3.3.0)
 Matrix       1.2-6     2016-05-02 CRAN (R 3.3.0)
 memoise      1.0.0     2016-01-29 CRAN (R 3.3.0)
 munsell      0.4.3     2016-02-13 CRAN (R 3.3.0)
 plyr         1.8.3     2015-06-12 CRAN (R 3.3.0)
 Rcpp         0.12.5    2016-05-14 CRAN (R 3.3.0)
 scales       0.4.0     2016-02-26 CRAN (R 3.3.0)
 survival   * 2.39-4    2016-05-11 CRAN (R 3.3.0)
 survminer  * 0.2.1.900 2016-05-29 local         
 withr        1.0.1     2016-02-04 CRAN (R 3.3.0)

Cheers

Nikolaj

@MarcinKosinski
Copy link
Contributor Author

@kassambara I've received such user experience

@kassambara
Copy link
Owner

Hi,

Linetypes can be changed by strata as follow:

# Fit sur vival curves
library(survival)
lung$fake_groups <- sample(1:6, size = nrow(lung), replace = TRUE)
fit<- survfit(Surv(time, status) ~ fake_groups, data = lung)

# Visualize and change linetypes by strata
library(survminer)
ggsurvplot(fit, linetype = "strata")

rplot

# Change linetypes manually
ggsurv <- ggsurvplot(fit, linetype = "strata")
ggsurv$plot <- ggsurv$plot + scale_linetype_manual(values = c(1,1,2,1,2,2))
print(ggsurv)

rplot13

Should we add a new argument "linetype.manual = c(1,1,2,1,2,2)" in ggsurvplot()?

Best,
A.

@MarcinKosinski
Copy link
Contributor Author

It's always easier than modyfing ggsurvplot$plot :)

2016-05-30 16:49 GMT+02:00 Alboukadel KASSAMBARA notifications@github.com:

Hi,

Linetypes can be changed by strata as follow:

Fit sur vival curves

library(survival)lung$fake_groups <- sample(1:6, size = nrow(lung), replace = TRUE)fit<- survfit(Surv(time, status) ~ fake_groups, data = lung)

Visualize and change linetypes by strata

library(survminer)
ggsurvplot(fit, linetype = "strata")

[image: rplot]
https://cloud.githubusercontent.com/assets/3313355/15652320/b720e3ce-2685-11e6-93fc-b4586b76ebaa.png

Change linetypes manuallyggsurv <- ggsurvplot(fit, linetype = "strata")ggsurv$plot <- ggsurv$plot + scale_linetype_manual(values = c(1,1,2,1,2,2))

print(ggsurv)

[image: rplot13]
https://cloud.githubusercontent.com/assets/3313355/15652401/3a8c7ef8-2686-11e6-8c4c-d59768088510.png

Should we add a new argument "linetype.manual = c(1,1,2,1,2,2)" in
ggsurvplot()?

Best,
A.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#45 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AGdaztldnibQ2KitZGgFqk4VXZvxEddyks5qGvkJgaJpZM4Ip1yF
.

@kassambara
Copy link
Owner

The function 'ggsurvplot()' has now a new argument linetype.

Allowed values includes i) "strata" for changing linetypes by strata (i.e. groups); ii) a numeric vector (e.g., c(1, 2)) or a character vector c("solid", "dashed").

@MarcinKosinski
Copy link
Contributor Author

MarcinKosinski commented May 30, 2016 via email

@MarcinKosinski
Copy link
Contributor Author

b50ca68

1609980

After you'll update NEWS.md you can close this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants