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

Adding Line Colour Changes Line Position #120

Open
DarioS opened this issue Jul 8, 2016 · 8 comments
Open

Adding Line Colour Changes Line Position #120

DarioS opened this issue Jul 8, 2016 · 8 comments

Comments

@DarioS
Copy link
Contributor

DarioS commented Jul 8, 2016

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.

@averissimo
Copy link

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

@sinhrks
Copy link
Owner

sinhrks commented Jul 29, 2016

@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.

@DarioS
Copy link
Contributor Author

DarioS commented Nov 7, 2016

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.

@sinhrks
Copy link
Owner

sinhrks commented Nov 7, 2016

OK, will consider the fix.

@lselzer
Copy link
Contributor

lselzer commented Jul 3, 2017

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

@DarioS
Copy link
Contributor Author

DarioS commented Jul 4, 2017

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

@lselzer
Copy link
Contributor

lselzer commented Jul 4, 2017

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.

@terrytangyuan
Copy link
Collaborator

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

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

No branches or pull requests

5 participants