I am trying to save a KM plot using ggsave but my following code isn't saving the file on my Mac:
# Fit survival curves
require("survival")
fit<- survfit(Surv(time, status) ~ sex, data = lung)
# Visualize
library("survminer")
p <- ggsurvplot(fit, data = lung,
surv.median.line = "hv", # Add medians survival
pval = TRUE, # Add p-value and tervals
conf.int = TRUE, # Add the 95% confidence band
risk.table = TRUE, # Add risk table
tables.height = 0.2,
tables.theme = theme_cleantable(),
palette = "jco",
ggtheme = theme_bw()
)
print(p)
ggsave(filename = "Test.png",
plot = print(p),
path = "~/Desktop/",
width = 8,
height = 7,
dpi = 300)
The code runs properly without any errors but and I can see the sample KM curve appear in R. However, no saved image file appears on my desktop. I would really appreciate any help with this request.