t <- c(1,1,2,2,3,4,4,5,5,6,6,6,6,7,8,8,8,8,9,10,10,11,11,11,12,12,13,15,16,17,17,19,
20,22,22,23,23,25,32,32,34,35)
status <-c(1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,0,1,0,1,1,1,1,1,1,0,1,0,0,1,1,1,1,0,0,0,0,0)
grupo <- c(1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,0,0,0,1,0,1,1,1,0,1,0,0,1,0,0,0,1,1,0,0,0,0,0,0)
sex <- c(1,1,1,1,1,1,1,1,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,1,1,1,1,1,1,1)
data<- data.frame(t,status,grupo, sex)
# Fit a Cox model
library(survival)
fit <- coxph(Surv(t,status) ~ grupo+sex, data=data, method='breslow')
# Predict Survival
datosnuevos <- data.frame(grupo=c(0,0,1,1), sex=c(0,1,0,1))
curva <- survfit(fit, newdata = datosnuevos, conf.type = "log-log")
df<- data.frame(time=curva$time, TtoFemale=curva$surv[,1], TtoMale=curva$surv[,2],
PboFemale=curva$surv[,3], PboMale=curva$surv[,4])
# log minus log (survival)
library(ggplot2)
ggplot()+
geom_step(aes(time, log(-log(TtoFemale)), col='TTo0_Female0'), lty=2, data=df)+
geom_step(aes(time, log(-log(TtoMale)), col='TTo0_Male1'),lty=2, data=df)+
geom_step(aes(time, log(-log(PboFemale)), col='Pbo1_Female0'), data=df)+
geom_step(aes(time, log(-log(PboMale)), col='Pbo1_Male1'), data=df)+
labs(color= 'TRT-Sex', x = "time", y = "log(-log Survival)", title = "")+
scale_color_manual(name = "TRT-Sex", values = c("TTo0_Female0" = "pink", "TTo0_Male1" = "blue",
"Pbo1_Female0" = "pink", "Pbo1_Male1" = "blue"))+
theme_classic()+
theme(legend.position = "right", legend.direction = "vertical") +
theme(legend.title = element_text(family = "Courier", color = "black", size = 12, face = 1))+
theme(legend.text = element_text (size = 10)) +
scale_linetype_manual(name = "TRT-Sex", values=c(2,2,1,1))
How can I modify the two first lines in the legend (must be 'dotted line') I have tried it with -- scale_linetype_manual(name = "TRT-Sex", values=c(2,2,1,1)) --- but It doesn't work... Thanks