0

The data frame:

n <- 500
lbd_a <- 0.1
lbd_b <- 0.15
df <- data.frame()
for (x in c(1:80)){
  St_a <- n*exp(-lbd_a*x)
  St_b <- n*exp(-lbd_b*x)
  ft_a <- lbd_a*x*exp(-lbd_a*x)*n
  ft_b <- lbd_b*x*exp(-lbd_b*x)*n
  ht_a <- ft_a / St_a
  ht_b <- ft_b / St_b
  ht_ab <- (ft_a + ft_b)/ (n*(exp(-lbd_a*x)+exp(-lbd_b*x)))
  a <- c(ht_a, ht_b, ht_ab)
  df <- rbind(df, as.data.frame(t(a)))
}
colnames(df) <- c("ht_a", "ht_b", "ht_ab")

The codes for graph

color <- "Cohort A"
color2 <- "Cohort B"
color3 <- "Combined"
  df %>%
    rowid_to_column("time") %>%
    ggplot(aes(x = time))+
    geom_line(aes(y = ht_a, color = color, linetype = color ))+
    geom_line(aes(y = ht_b, color = color2, linetype = color2)) +
    geom_line(aes(y = ht_ab,color =color3, linetype = color3)) +
    ylab("Hazard Rate")+
    xlab("time")+labs(fill = "Condition")+
    scale_fill_discrete(name = "Condition")

The graph is: enter image description here

Now the legend title is "color". How can I change it?

Chx Fang
  • 1
  • 1

0 Answers0