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

ggsurvplot, displaying time in years instead of days #166

Closed
kassambara opened this issue Mar 7, 2017 · 6 comments
Closed

ggsurvplot, displaying time in years instead of days #166

kassambara opened this issue Mar 7, 2017 · 6 comments

Comments

@kassambara
Copy link
Owner

(e-mail from a user)

Hi

I continue to use your ggsurvplot and it’s really good, such a good package and nice to see you’re adding features such as the cumulative events table, no. censored subjects – great features!

Anyway, I wonder if there is a way of displaying time in years when it has been calculated in days. For example, I have some overall survival data calculated in days (it’s trivial to recalculate the OS in years), similar to the ‘xscale’ function in base plot.survfit

From the documentation;

https://stat.ethz.ch/R-manual/R-devel/library/survival/html/plot.survfit.html


xscale
a numeric value used like yscale for labels on the x axis. A value of 365.25 will give labels in years instead of the original days.

I think this would be a useful addition.

@kassambara
Copy link
Owner Author

New argument suggestion for x scale transformation

xscale = c("d_m", "d_y", "m_d", "m_y", "y_d", "y_m")

d_m: days to months
d_y: from days to years
m_d: months to days
....

@kassambara
Copy link
Owner Author

To be added in ggsurvplot

xscale = "d_m"
xtrans <- switch(xscale,
      d_m = 12/365.25,
      d_y = 1/365.25,
      m_d = 365.25/12,
      m_y = 1/12,
      y_d = 365.25,
      y_m = 12,
      1
      )

breaks <- c(0, 250, 500, 750, 1000)
p + scale_x_continuous(
  breaks = breaks,
  labels = round(breaks*xtrans,2))

kassambara added a commit that referenced this issue Mar 26, 2017
kassambara added a commit that referenced this issue Mar 26, 2017
@kassambara
Copy link
Owner Author

  • New argument xscale in ggsurvplot(): numeric or character value specifying x-axis scale.
    • If numeric, the value is used to divide the labels on the x axis. For example, a value of 365.25 will give labels in years instead of the original days.
    • If character, allowed options include one of c("d_m", "d_y", "m_d", "m_y", "y_d", "y_m"), where d = days, m = months and y = years. For example, xscale = "d_m" will transform labels from days to months; xscale = "m_y", will transform labels from months to years

@JuRaGa
Copy link

JuRaGa commented Apr 10, 2019

Hi, I am using the flag "d_m" to convert my time scale in days to months. This works, but the months have decimals. I was wondering if there was a way to round them so they display as integers?

Thank you,

@ayc17
Copy link

ayc17 commented Aug 10, 2020

Also having the same issue as my months appear in decimals. For instance, I wanted to see 3, 6, 9, 12 months intervals, but instead it shows up as 3.29, 6.57, 9.86. Is there a way to round them? Thanks!

@nandobonf
Copy link

A workaround is to add the argument "break.time.by=365.25*3"

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

4 participants