0

I would like to change the decimal separator of all the numbers (risk table, x and y axis, as well as p-value) in a Kaplan Meier curve from "." to "," (e.g. from 3.1415 to 3,1415). For the graph I use ggsurvplot from the survival package in R.

I found a post on here (Add comma separator to large numbers in risk table) describing how to add a ","-Separator for large numbers by changing the ggsurv object, but I don't know enough about this topic to modify it for my purpose.

Another post (R decimal comma instead of decimal point in ggplot scales::percent) I found was suggesting the usage of "geom_text", but this is not compatible with ggurvplot, only with ggplot as far as I know.

Is there any way how this can be done?

1 Answer 1

1

The answer you referenced already shows how this can be done. But instead of scales::comma you have to switch to the more general scales::number which allows to set the symbols used as decimal.mark and as big.mark. Also note that a ggsurvplot is simply a list where the ggplot is stored as an element named plot, i.e. to apply the second answer you reference you have to do something like ggsurv$plot + geom_text(....).

Adapting the example and the answer by @AllanCameron to the more general case you could do:


ggsurv$table$layers[[1]]$data$llabels <-
  scales::number(ggsurv$table$layers[[1]]$data$llabels, decimal.mark = ",", big.mark = ".", accuracy = .01)

ggsurv

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer, that has helped me understand ggsurvplot a bit better now. Apart from the risk table I also wanted to make these changes for the survival probabilty at the y axis, as well as the p value (not shown in the example plot). Do you know how I can access these in the ggsurvplot?
+scale_y_continuous(label = function(x) format(x, big.mark = ".", decimal.mark = ","))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.