Reputation: 11
I am having some trouble reordering the appearance of the risk table in a plot made with the ggcuminc function of the ggSurvit package. I would like to have ‘Resection’ displayed above and ‘MWA’ below.
Here you can see the plot: CIF of LC
Below the code to create the plot:
# Plot the CIF curves for each group
cuminc(Surv(LC_from_local_treatment_per_tumor, Loss_of_local_control) ~ Treatment_type_tumor_near_gallbladder, efficacy_df_CIF) %>%
ggcuminc(outcome = c("Event", "Competing Event")) +
# add_confidence_interval() +
scale_color_manual(values = c("#A81D24", "#FFD700")) +
add_risktable() +
coord_cartesian(ylim = c(0, 1)) +
add_censor_mark(size = 2, alpha = 0.2) +
scale_ggsurvfit() +
labs(title = "CIF for Local Control (LC) per tumor") +
theme(plot.title = element_text(hjust = 0.5)) + # Center the title
add_pvalue(caption = "Gray's Test (Event) p={round(glance(cif_LC)$p.value_1, digits=3)}")
For some reason, even though ‘Resection’ is set as the reference level in the dataframe, ‘MWA’ appears above ‘Resection’ in the risk table below the graph. I also tried changing the order of levels in the dataset, but it didn’t resolve the issue. Interestingly, when I plot a Kaplan-Meier curve using the same dataset, the risk table is displayed correctly.
Below the code to plot the K-M curves:
# Plot the survival curve
sf <- survfit2(Surv(LC_from_local_treatment_per_tumor, Loss_of_local_control == "Event") ~ Treatment_type_tumor_near_gallbladder, data = efficacy_df_CIF)
sf %>%
ggsurvfit() +
add_risktable() +
# add_confidence_interval() +
scale_color_manual(values = c("#A81D24", "#FFD700")) +
add_censor_mark(size = 2, alpha = 0.2) +
scale_ggsurvfit() +
labs(title = "K-M curves for Loss of Local Control (LLC) per tumor") +
labs(caption = glue::glue("Log-rank {survfit2_p(sf)}")) +
theme(plot.title = element_text(hjust = 0.5)) # Center the title
# annotate("text", x = 2, y = 0.05, label = glue::glue("{survfit2_p(sf)}")) # Add p-value to the plot
Here you can see the plot: K-M of LC
Is there a way to change the order of labels in the first plot?
Upvotes: 1
Views: 43