ggfortify icon indicating copy to clipboard operation
ggfortify copied to clipboard

Adding Line Colour Changes Line Position

Open DarioS opened this issue 9 years ago • 8 comments

I firstly used the command

survivalPlot <- autoplot(survivalFit, conf.int = FALSE)

and got a sensible looking plot.

normalsurv

Then, I added a line colour and the placement of lines changed

autoplot(survivalFit, conf.int = FALSE, surv.colour = "red")

badsurv

The legend also disappeared.

DarioS avatar Jul 08 '16 05:07 DarioS

You want to control the colors on each curve? try this:

p1 <- autoplot(survival_obj)
p1 <- p1 + scale_colour_manual(values = c('indianred2','seagreen'))

I was having the same problem and when debugging found that it uses geom_step function and this is how to control the colors :)

Despite all this, I think the implementation on ggfortify should be more clear on that option or corrected.

Cheers

averissimo avatar Jul 28 '16 18:07 averissimo

@averissimo thx for the reply. It is correct that we should specify multi colors like ggplot2 does. Maybe better to update the doc.

@DarioS Sorry to late reply, I missed the notification.

sinhrks avatar Jul 29 '16 01:07 sinhrks

I think that it would be better to provide abstraction of this to the end-user, as the function currently tries to do unsuccessfully. The underlying ggplot2 framework should be hidden away where possible.

DarioS avatar Nov 07 '16 04:11 DarioS

OK, will consider the fix.

sinhrks avatar Nov 07 '16 05:11 sinhrks

@DarioS I'm guessing that you want to make all lines red regardless of which group they are. Am I correct?

lselzer avatar Jul 03 '17 21:07 lselzer

Actually, it would be desirable to specify one colour per factor level. I only used "red" because the surv.colour option doesn't allow a vector of values.

> library(survival)
> autoplot(survfit(Surv(time, status) ~ sex, data = lung), surv.colour = c("red", "blue"))
Error: Aesthetics must be either length 1 or the same as the data (208): colour

Note that the number of samples in the error message is wrong.

> dim(lung)
[1] 228  10

DarioS avatar Jul 04 '17 01:07 DarioS

I will take a look tomorrow. I think the issue is with the way that geom_factory() works. Am I right @sinhrks ? I likely fix would for geom_factory() to check if the column exists in the data if not, check if it is a valid colour.

lselzer avatar Jul 04 '17 15:07 lselzer

A pull request for fixing this would be appreciated! @lselzer @DarioS @averissimo

terrytangyuan avatar Feb 18 '18 16:02 terrytangyuan