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?

kobue1
  • 43
  • 4

1 Answers1

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

stefan
  • 90,330
  • 6
  • 25
  • 51
  • 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? – kobue1 Apr 18 '23 at 07:46
  • `+scale_y_continuous(label = function(x) format(x, big.mark = ".", decimal.mark = ","))` – IRTFM Apr 19 '23 at 17:48