rggplot2plotrecurrent

Increasing size of lines in ggplot mean cumulative function plot


I am using the reReg package to create mean cumulative function plots. but I am unable to change the size of lines inside the plot.

is there anyway to increase the line width? enter image description here

library(reReg)
data(readmission, package = "frailtypack")
readmission <- subset(readmission, !(id %in% c(60, 109, 280)))
mcf0 <- mcf(Recur(t.start %2% t.stop, id, event, death) ~ sex, data = readmission)
p<- plot(mcf0, conf.int = TRUE)

p + theme_bw(base_size = 20)

Thanks for reading


Solution

  • You could use ggplot_build to change the linewidth in each layer with lapply like this (I used big linewidth to show result):

    library(reReg)
    library(ggplot2)
    library(frailtypack)
    data(readmission, package = "frailtypack")
    readmission <- subset(readmission, !(id %in% c(60, 109, 280)))
    mcf0 <- mcf(Recur(t.start %2% t.stop, id, event, death) ~ sex, data = readmission)
    p <- plot(mcf0, conf.int = TRUE) + theme_bw(base_size = 20) 
    
    q <- ggplot_build(p)
    
    q$data = lapply(q$data, \(x) {
      x$linewidth = 3
      x
    })
    
    q <- ggplot_gtable(q)
    plot(q)
    

    Created on 2023-04-06 with reprex v2.0.2

    Different linewidth:

    library(reReg)
    library(ggplot2)
    library(frailtypack)
    
    p <- plot(mcf0, conf.int = TRUE) + theme_bw(base_size = 20) 
    
    q <- ggplot_build(p)
    
    q$data = lapply(q$data, \(x) {
      x$linewidth = 1
      x
    })
    
    q <- ggplot_gtable(q)
    plot(q)
    

    Created on 2023-04-06 with reprex v2.0.2